diff options
Diffstat (limited to 'Lib/test/test_pyexpat.py')
-rw-r--r-- | Lib/test/test_pyexpat.py | 196 |
1 files changed, 98 insertions, 98 deletions
diff --git a/Lib/test/test_pyexpat.py b/Lib/test/test_pyexpat.py index 68a1451..840a7a8 100644 --- a/Lib/test/test_pyexpat.py +++ b/Lib/test/test_pyexpat.py @@ -22,17 +22,17 @@ class SetAttributeTest(unittest.TestCase): def test_returns_unicode(self): for x, y in self.set_get_pairs: self.parser.returns_unicode = x - self.assertEquals(self.parser.returns_unicode, y) + self.assertEqual(self.parser.returns_unicode, y) def test_ordered_attributes(self): for x, y in self.set_get_pairs: self.parser.ordered_attributes = x - self.assertEquals(self.parser.ordered_attributes, y) + self.assertEqual(self.parser.ordered_attributes, y) def test_specified_attributes(self): for x, y in self.set_get_pairs: self.parser.specified_attributes = x - self.assertEquals(self.parser.specified_attributes, y) + self.assertEqual(self.parser.specified_attributes, y) data = '''\ @@ -140,23 +140,23 @@ class ParseTest(unittest.TestCase): # Verify output op = out.out - self.assertEquals(op[0], 'PI: \'xml-stylesheet\' \'href="stylesheet.css"\'') - self.assertEquals(op[1], "Comment: ' comment data '") - self.assertEquals(op[2], "Notation declared: ('notation', None, 'notation.jpeg', None)") - self.assertEquals(op[3], "Unparsed entity decl: ('unparsed_entity', None, 'entity.file', None, 'notation')") - self.assertEquals(op[4], "Start element: 'root' {'attr1': 'value1', 'attr2': 'value2\\xe1\\xbd\\x80'}") - self.assertEquals(op[5], "NS decl: 'myns' 'http://www.python.org/namespace'") - self.assertEquals(op[6], "Start element: 'http://www.python.org/namespace!subelement' {}") - self.assertEquals(op[7], "Character data: 'Contents of subelements'") - self.assertEquals(op[8], "End element: 'http://www.python.org/namespace!subelement'") - self.assertEquals(op[9], "End of NS decl: 'myns'") - self.assertEquals(op[10], "Start element: 'sub2' {}") - self.assertEquals(op[11], 'Start of CDATA section') - self.assertEquals(op[12], "Character data: 'contents of CDATA section'") - self.assertEquals(op[13], 'End of CDATA section') - self.assertEquals(op[14], "End element: 'sub2'") - self.assertEquals(op[15], "External entity ref: (None, 'entity.file', None)") - self.assertEquals(op[16], "End element: 'root'") + self.assertEqual(op[0], 'PI: \'xml-stylesheet\' \'href="stylesheet.css"\'') + self.assertEqual(op[1], "Comment: ' comment data '") + self.assertEqual(op[2], "Notation declared: ('notation', None, 'notation.jpeg', None)") + self.assertEqual(op[3], "Unparsed entity decl: ('unparsed_entity', None, 'entity.file', None, 'notation')") + self.assertEqual(op[4], "Start element: 'root' {'attr1': 'value1', 'attr2': 'value2\\xe1\\xbd\\x80'}") + self.assertEqual(op[5], "NS decl: 'myns' 'http://www.python.org/namespace'") + self.assertEqual(op[6], "Start element: 'http://www.python.org/namespace!subelement' {}") + self.assertEqual(op[7], "Character data: 'Contents of subelements'") + self.assertEqual(op[8], "End element: 'http://www.python.org/namespace!subelement'") + self.assertEqual(op[9], "End of NS decl: 'myns'") + self.assertEqual(op[10], "Start element: 'sub2' {}") + self.assertEqual(op[11], 'Start of CDATA section') + self.assertEqual(op[12], "Character data: 'contents of CDATA section'") + self.assertEqual(op[13], 'End of CDATA section') + self.assertEqual(op[14], "End element: 'sub2'") + self.assertEqual(op[15], "External entity ref: (None, 'entity.file', None)") + self.assertEqual(op[16], "End element: 'root'") def test_unicode(self): # Try the parse again, this time producing Unicode output @@ -169,23 +169,23 @@ class ParseTest(unittest.TestCase): parser.Parse(data, 1) op = out.out - self.assertEquals(op[0], 'PI: u\'xml-stylesheet\' u\'href="stylesheet.css"\'') - self.assertEquals(op[1], "Comment: u' comment data '") - self.assertEquals(op[2], "Notation declared: (u'notation', None, u'notation.jpeg', None)") - self.assertEquals(op[3], "Unparsed entity decl: (u'unparsed_entity', None, u'entity.file', None, u'notation')") - self.assertEquals(op[4], "Start element: u'root' {u'attr1': u'value1', u'attr2': u'value2\\u1f40'}") - self.assertEquals(op[5], "NS decl: u'myns' u'http://www.python.org/namespace'") - self.assertEquals(op[6], "Start element: u'http://www.python.org/namespace!subelement' {}") - self.assertEquals(op[7], "Character data: u'Contents of subelements'") - self.assertEquals(op[8], "End element: u'http://www.python.org/namespace!subelement'") - self.assertEquals(op[9], "End of NS decl: u'myns'") - self.assertEquals(op[10], "Start element: u'sub2' {}") - self.assertEquals(op[11], 'Start of CDATA section') - self.assertEquals(op[12], "Character data: u'contents of CDATA section'") - self.assertEquals(op[13], 'End of CDATA section') - self.assertEquals(op[14], "End element: u'sub2'") - self.assertEquals(op[15], "External entity ref: (None, u'entity.file', None)") - self.assertEquals(op[16], "End element: u'root'") + self.assertEqual(op[0], 'PI: u\'xml-stylesheet\' u\'href="stylesheet.css"\'') + self.assertEqual(op[1], "Comment: u' comment data '") + self.assertEqual(op[2], "Notation declared: (u'notation', None, u'notation.jpeg', None)") + self.assertEqual(op[3], "Unparsed entity decl: (u'unparsed_entity', None, u'entity.file', None, u'notation')") + self.assertEqual(op[4], "Start element: u'root' {u'attr1': u'value1', u'attr2': u'value2\\u1f40'}") + self.assertEqual(op[5], "NS decl: u'myns' u'http://www.python.org/namespace'") + self.assertEqual(op[6], "Start element: u'http://www.python.org/namespace!subelement' {}") + self.assertEqual(op[7], "Character data: u'Contents of subelements'") + self.assertEqual(op[8], "End element: u'http://www.python.org/namespace!subelement'") + self.assertEqual(op[9], "End of NS decl: u'myns'") + self.assertEqual(op[10], "Start element: u'sub2' {}") + self.assertEqual(op[11], 'Start of CDATA section') + self.assertEqual(op[12], "Character data: u'contents of CDATA section'") + self.assertEqual(op[13], 'End of CDATA section') + self.assertEqual(op[14], "End element: u'sub2'") + self.assertEqual(op[15], "External entity ref: (None, u'entity.file', None)") + self.assertEqual(op[16], "End element: u'root'") def test_parse_file(self): # Try parsing a file @@ -199,23 +199,23 @@ class ParseTest(unittest.TestCase): parser.ParseFile(file) op = out.out - self.assertEquals(op[0], 'PI: u\'xml-stylesheet\' u\'href="stylesheet.css"\'') - self.assertEquals(op[1], "Comment: u' comment data '") - self.assertEquals(op[2], "Notation declared: (u'notation', None, u'notation.jpeg', None)") - self.assertEquals(op[3], "Unparsed entity decl: (u'unparsed_entity', None, u'entity.file', None, u'notation')") - self.assertEquals(op[4], "Start element: u'root' {u'attr1': u'value1', u'attr2': u'value2\\u1f40'}") - self.assertEquals(op[5], "NS decl: u'myns' u'http://www.python.org/namespace'") - self.assertEquals(op[6], "Start element: u'http://www.python.org/namespace!subelement' {}") - self.assertEquals(op[7], "Character data: u'Contents of subelements'") - self.assertEquals(op[8], "End element: u'http://www.python.org/namespace!subelement'") - self.assertEquals(op[9], "End of NS decl: u'myns'") - self.assertEquals(op[10], "Start element: u'sub2' {}") - self.assertEquals(op[11], 'Start of CDATA section') - self.assertEquals(op[12], "Character data: u'contents of CDATA section'") - self.assertEquals(op[13], 'End of CDATA section') - self.assertEquals(op[14], "End element: u'sub2'") - self.assertEquals(op[15], "External entity ref: (None, u'entity.file', None)") - self.assertEquals(op[16], "End element: u'root'") + self.assertEqual(op[0], 'PI: u\'xml-stylesheet\' u\'href="stylesheet.css"\'') + self.assertEqual(op[1], "Comment: u' comment data '") + self.assertEqual(op[2], "Notation declared: (u'notation', None, u'notation.jpeg', None)") + self.assertEqual(op[3], "Unparsed entity decl: (u'unparsed_entity', None, u'entity.file', None, u'notation')") + self.assertEqual(op[4], "Start element: u'root' {u'attr1': u'value1', u'attr2': u'value2\\u1f40'}") + self.assertEqual(op[5], "NS decl: u'myns' u'http://www.python.org/namespace'") + self.assertEqual(op[6], "Start element: u'http://www.python.org/namespace!subelement' {}") + self.assertEqual(op[7], "Character data: u'Contents of subelements'") + self.assertEqual(op[8], "End element: u'http://www.python.org/namespace!subelement'") + self.assertEqual(op[9], "End of NS decl: u'myns'") + self.assertEqual(op[10], "Start element: u'sub2' {}") + self.assertEqual(op[11], 'Start of CDATA section') + self.assertEqual(op[12], "Character data: u'contents of CDATA section'") + self.assertEqual(op[13], 'End of CDATA section') + self.assertEqual(op[14], "End element: u'sub2'") + self.assertEqual(op[15], "External entity ref: (None, u'entity.file', None)") + self.assertEqual(op[16], "End element: u'root'") class NamespaceSeparatorTest(unittest.TestCase): @@ -231,14 +231,14 @@ class NamespaceSeparatorTest(unittest.TestCase): expat.ParserCreate(namespace_separator=42) self.fail() except TypeError, e: - self.assertEquals(str(e), + self.assertEqual(str(e), 'ParserCreate() argument 2 must be string or None, not int') try: expat.ParserCreate(namespace_separator='too long') self.fail() except ValueError, e: - self.assertEquals(str(e), + self.assertEqual(str(e), 'namespace_separator must be at most one character, omitted, or None') def test_zero_length(self): @@ -264,7 +264,7 @@ class InterningTest(unittest.TestCase): p.EndElementHandler = collector p.Parse("<e> <e/> <e></e> </e>", 1) tag = L[0] - self.assertEquals(len(L), 6) + self.assertEqual(len(L), 6) for entry in L: # L should have the same string repeated over and over. self.assertTrue(tag is entry) @@ -278,7 +278,7 @@ class BufferTextTest(unittest.TestCase): self.parser.CharacterDataHandler = self.CharacterDataHandler def check(self, expected, label): - self.assertEquals(self.stuff, expected, + self.assertEqual(self.stuff, expected, "%s\nstuff = %r\nexpected = %r" % (label, self.stuff, map(unicode, expected))) @@ -311,47 +311,47 @@ class BufferTextTest(unittest.TestCase): # Make sure buffering is turned on self.assertTrue(self.parser.buffer_text) self.parser.Parse("<a>1<b/>2<c/>3</a>", 1) - self.assertEquals(self.stuff, ['123'], - "buffered text not properly collapsed") + self.assertEqual(self.stuff, ['123'], + "buffered text not properly collapsed") def test1(self): # XXX This test exposes more detail of Expat's text chunking than we # XXX like, but it tests what we need to concisely. self.setHandlers(["StartElementHandler"]) self.parser.Parse("<a>1<b buffer-text='no'/>2\n3<c buffer-text='yes'/>4\n5</a>", 1) - self.assertEquals(self.stuff, - ["<a>", "1", "<b>", "2", "\n", "3", "<c>", "4\n5"], - "buffering control not reacting as expected") + self.assertEqual(self.stuff, + ["<a>", "1", "<b>", "2", "\n", "3", "<c>", "4\n5"], + "buffering control not reacting as expected") def test2(self): self.parser.Parse("<a>1<b/><2><c/> \n 3</a>", 1) - self.assertEquals(self.stuff, ["1<2> \n 3"], - "buffered text not properly collapsed") + self.assertEqual(self.stuff, ["1<2> \n 3"], + "buffered text not properly collapsed") def test3(self): self.setHandlers(["StartElementHandler"]) self.parser.Parse("<a>1<b/>2<c/>3</a>", 1) - self.assertEquals(self.stuff, ["<a>", "1", "<b>", "2", "<c>", "3"], + self.assertEqual(self.stuff, ["<a>", "1", "<b>", "2", "<c>", "3"], "buffered text not properly split") def test4(self): self.setHandlers(["StartElementHandler", "EndElementHandler"]) self.parser.CharacterDataHandler = None self.parser.Parse("<a>1<b/>2<c/>3</a>", 1) - self.assertEquals(self.stuff, - ["<a>", "<b>", "</b>", "<c>", "</c>", "</a>"]) + self.assertEqual(self.stuff, + ["<a>", "<b>", "</b>", "<c>", "</c>", "</a>"]) def test5(self): self.setHandlers(["StartElementHandler", "EndElementHandler"]) self.parser.Parse("<a>1<b></b>2<c/>3</a>", 1) - self.assertEquals(self.stuff, + self.assertEqual(self.stuff, ["<a>", "1", "<b>", "</b>", "2", "<c>", "</c>", "3", "</a>"]) def test6(self): self.setHandlers(["CommentHandler", "EndElementHandler", "StartElementHandler"]) self.parser.Parse("<a>1<b/>2<c></c>345</a> ", 1) - self.assertEquals(self.stuff, + self.assertEqual(self.stuff, ["<a>", "1", "<b>", "</b>", "2", "<c>", "</c>", "345", "</a>"], "buffered text not properly split") @@ -359,10 +359,10 @@ class BufferTextTest(unittest.TestCase): self.setHandlers(["CommentHandler", "EndElementHandler", "StartElementHandler"]) self.parser.Parse("<a>1<b/>2<c></c>3<!--abc-->4<!--def-->5</a> ", 1) - self.assertEquals(self.stuff, - ["<a>", "1", "<b>", "</b>", "2", "<c>", "</c>", "3", - "<!--abc-->", "4", "<!--def-->", "5", "</a>"], - "buffered text not properly split") + self.assertEqual(self.stuff, + ["<a>", "1", "<b>", "</b>", "2", "<c>", "</c>", "3", + "<!--abc-->", "4", "<!--def-->", "5", "</a>"], + "buffered text not properly split") # Test handling of exception from callback: @@ -377,9 +377,9 @@ class HandlerExceptionTest(unittest.TestCase): parser.Parse("<a><b><c/></b></a>", 1) self.fail() except RuntimeError, e: - self.assertEquals(e.args[0], 'a', - "Expected RuntimeError for element 'a', but" + \ - " found %r" % e.args[0]) + self.assertEqual(e.args[0], 'a', + "Expected RuntimeError for element 'a', but" + \ + " found %r" % e.args[0]) # Test Current* members: @@ -398,7 +398,7 @@ class PositionTest(unittest.TestCase): self.assertTrue(self.upto < len(self.expected_list), 'too many parser events') expected = self.expected_list[self.upto] - self.assertEquals(pos, expected, + self.assertEqual(pos, expected, 'Expected position %s, got position %s' %(pos, expected)) self.upto += 1 @@ -439,10 +439,10 @@ class ChardataBufferTest(unittest.TestCase): """ def test_1025_bytes(self): - self.assertEquals(self.small_buffer_test(1025), 2) + self.assertEqual(self.small_buffer_test(1025), 2) def test_1000_bytes(self): - self.assertEquals(self.small_buffer_test(1000), 1) + self.assertEqual(self.small_buffer_test(1000), 1) def test_wrong_size(self): parser = expat.ParserCreate() @@ -466,15 +466,15 @@ class ChardataBufferTest(unittest.TestCase): # once. self.n = 0 parser.Parse(xml1) - self.assertEquals(self.n, 1) + self.assertEqual(self.n, 1) # Reassign to buffer_size, but assign the same size. parser.buffer_size = parser.buffer_size - self.assertEquals(self.n, 1) + self.assertEqual(self.n, 1) # Try parsing rest of the document parser.Parse(xml2) - self.assertEquals(self.n, 2) + self.assertEqual(self.n, 2) def test_disabling_buffer(self): @@ -485,27 +485,27 @@ class ChardataBufferTest(unittest.TestCase): parser.CharacterDataHandler = self.counting_handler parser.buffer_text = 1 parser.buffer_size = 1024 - self.assertEquals(parser.buffer_size, 1024) + self.assertEqual(parser.buffer_size, 1024) # Parse one chunk of XML self.n = 0 parser.Parse(xml1, 0) - self.assertEquals(parser.buffer_size, 1024) - self.assertEquals(self.n, 1) + self.assertEqual(parser.buffer_size, 1024) + self.assertEqual(self.n, 1) # Turn off buffering and parse the next chunk. parser.buffer_text = 0 self.assertFalse(parser.buffer_text) - self.assertEquals(parser.buffer_size, 1024) + self.assertEqual(parser.buffer_size, 1024) for i in range(10): parser.Parse(xml2, 0) - self.assertEquals(self.n, 11) + self.assertEqual(self.n, 11) parser.buffer_text = 1 self.assertTrue(parser.buffer_text) - self.assertEquals(parser.buffer_size, 1024) + self.assertEqual(parser.buffer_size, 1024) parser.Parse(xml3, 1) - self.assertEquals(self.n, 12) + self.assertEqual(self.n, 12) @@ -533,14 +533,14 @@ class ChardataBufferTest(unittest.TestCase): parser.CharacterDataHandler = self.counting_handler parser.buffer_text = 1 parser.buffer_size = 1024 - self.assertEquals(parser.buffer_size, 1024) + self.assertEqual(parser.buffer_size, 1024) self.n = 0 parser.Parse(xml1, 0) parser.buffer_size *= 2 - self.assertEquals(parser.buffer_size, 2048) + self.assertEqual(parser.buffer_size, 2048) parser.Parse(xml2, 1) - self.assertEquals(self.n, 2) + self.assertEqual(self.n, 2) def test_change_size_2(self): xml1 = "<?xml version='1.0' encoding='iso8859'?><a>a<s>%s" % ('a' * 1023) @@ -549,14 +549,14 @@ class ChardataBufferTest(unittest.TestCase): parser.CharacterDataHandler = self.counting_handler parser.buffer_text = 1 parser.buffer_size = 2048 - self.assertEquals(parser.buffer_size, 2048) + self.assertEqual(parser.buffer_size, 2048) self.n=0 parser.Parse(xml1, 0) parser.buffer_size //= 2 - self.assertEquals(parser.buffer_size, 1024) + self.assertEqual(parser.buffer_size, 1024) parser.Parse(xml2, 1) - self.assertEquals(self.n, 4) + self.assertEqual(self.n, 4) class MalformedInputText(unittest.TestCase): def test1(self): @@ -566,7 +566,7 @@ class MalformedInputText(unittest.TestCase): parser.Parse(xml, True) self.fail() except expat.ExpatError as e: - self.assertEquals(str(e), 'unclosed token: line 2, column 0') + self.assertEqual(str(e), 'unclosed token: line 2, column 0') def test2(self): xml = "<?xml version\xc2\x85='1.0'?>\r\n" @@ -575,7 +575,7 @@ class MalformedInputText(unittest.TestCase): parser.Parse(xml, True) self.fail() except expat.ExpatError as e: - self.assertEquals(str(e), 'XML declaration not well-formed: line 1, column 14') + self.assertEqual(str(e), 'XML declaration not well-formed: line 1, column 14') def test_main(): run_unittest(SetAttributeTest, |