|
9 | 9 | from io import BytesIO |
10 | 10 | from test import support |
11 | 11 | from test.support import os_helper |
12 | | - |
| 12 | +from test.support import sortdict |
| 13 | +from unittest import mock |
13 | 14 | from xml.parsers import expat |
14 | 15 | from xml.parsers.expat import errors |
15 | 16 |
|
16 | | -from test.support import sortdict |
17 | | - |
18 | 17 |
|
19 | 18 | class SetAttributeTest(unittest.TestCase): |
20 | 19 | def setUp(self): |
@@ -440,9 +439,12 @@ def test_change_character_data_handler_in_callback(self): |
440 | 439 | def handler(*args): |
441 | 440 | parser.CharacterDataHandler = None |
442 | 441 |
|
| 442 | + handler_wrapper = unittest.mock.Mock(wraps=handler) |
443 | 443 | parser = expat.ParserCreate() |
444 | | - parser.CharacterDataHandler = handler |
| 444 | + parser.CharacterDataHandler = handler_wrapper |
445 | 445 | 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) |
446 | 448 |
|
447 | 449 |
|
448 | 450 | # Test handling of exception from callback: |
@@ -603,7 +605,7 @@ def test_unchanged_size(self): |
603 | 605 | def test_disabling_buffer(self): |
604 | 606 | xml1 = b"<?xml version='1.0' encoding='iso8859'?><a>" + b'a' * 512 |
605 | 607 | xml2 = b'b' * 1024 |
606 | | - xml3 = b'c' * 1024 + b'</a>'; |
| 608 | + xml3 = b'c' * 1024 + b'</a>' |
607 | 609 | parser = expat.ParserCreate() |
608 | 610 | parser.CharacterDataHandler = self.counting_handler |
609 | 611 | parser.buffer_text = 1 |
|
0 commit comments