Skip to content

Commit 2d4e590

Browse files
committed
Restore test from gh-134050
1 parent d0dc245 commit 2d4e590

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

Lib/test/test_pyexpat.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@
99
from io import BytesIO
1010
from test import support
1111
from test.support import os_helper
12-
12+
from test.support import sortdict
13+
from unittest import mock
1314
from xml.parsers import expat
1415
from xml.parsers.expat import errors
1516

16-
from test.support import sortdict
17-
1817

1918
class SetAttributeTest(unittest.TestCase):
2019
def setUp(self):
@@ -436,6 +435,19 @@ def test7(self):
436435
"<!--abc-->", "4", "<!--def-->", "5", "</a>"],
437436
"buffered text not properly split")
438437

438+
def test_change_character_data_handler_in_callback(self):
439+
# Test that xmlparse_handler_setter() properly handles
440+
# the special case "parser.CharacterDataHandler = None".
441+
def handler(*args):
442+
parser.CharacterDataHandler = None
443+
444+
handler_wrapper = mock.Mock(wraps=handler)
445+
parser = expat.ParserCreate()
446+
parser.CharacterDataHandler = handler_wrapper
447+
parser.Parse(b"<a>1<b/>2<c></c>3<!--abc-->4<!--def-->5</a> ", True)
448+
handler_wrapper.assert_called_once()
449+
self.assertIsNone(parser.CharacterDataHandler)
450+
439451

440452
# Test handling of exception from callback:
441453
class HandlerExceptionTest(unittest.TestCase):
@@ -595,7 +607,7 @@ def test_unchanged_size(self):
595607
def test_disabling_buffer(self):
596608
xml1 = b"<?xml version='1.0' encoding='iso8859'?><a>" + b'a' * 512
597609
xml2 = b'b' * 1024
598-
xml3 = b'c' * 1024 + b'</a>';
610+
xml3 = b'c' * 1024 + b'</a>'
599611
parser = expat.ParserCreate()
600612
parser.CharacterDataHandler = self.counting_handler
601613
parser.buffer_text = 1

0 commit comments

Comments
 (0)