Skip to content

Commit 52da4ae

Browse files
committed
refine test
1 parent 840c4a2 commit 52da4ae

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

Lib/test/test_pyexpat.py

Lines changed: 7 additions & 5 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):
@@ -440,9 +439,12 @@ def test_change_character_data_handler_in_callback(self):
440439
def handler(*args):
441440
parser.CharacterDataHandler = None
442441

442+
handler_wrapper = unittest.mock.Mock(wraps=handler)
443443
parser = expat.ParserCreate()
444-
parser.CharacterDataHandler = handler
444+
parser.CharacterDataHandler = handler_wrapper
445445
parser.Parse(b"<a>1<b/>2<c></c>3<!--abc-->4<!--def-->5</a> ", True)
446+
handler_wrapper.assert_called_once()
447+
self.assertIsNone(parser.CharacterDataHandler)
446448

447449

448450
# Test handling of exception from callback:
@@ -603,7 +605,7 @@ def test_unchanged_size(self):
603605
def test_disabling_buffer(self):
604606
xml1 = b"<?xml version='1.0' encoding='iso8859'?><a>" + b'a' * 512
605607
xml2 = b'b' * 1024
606-
xml3 = b'c' * 1024 + b'</a>';
608+
xml3 = b'c' * 1024 + b'</a>'
607609
parser = expat.ParserCreate()
608610
parser.CharacterDataHandler = self.counting_handler
609611
parser.buffer_text = 1

0 commit comments

Comments
 (0)