Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(69)

Side by Side Diff: Lib/test/test_pyexpat.py

Issue 16510: Using appropriate checks in tests
Patch Set: Created 6 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_pulldom.py ('k') | Lib/test/test_queue.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # XXX TypeErrors on calling handlers, or on bad return values from a 1 # XXX TypeErrors on calling handlers, or on bad return values from a
2 # handler, are obscure and unhelpful. 2 # handler, are obscure and unhelpful.
3 3
4 from io import BytesIO 4 from io import BytesIO
5 import unittest 5 import unittest
6 6
7 from xml.parsers import expat 7 from xml.parsers import expat
8 from xml.parsers.expat import errors 8 from xml.parsers.expat import errors
9 9
10 from test.support import sortdict, run_unittest 10 from test.support import sortdict, run_unittest
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 L = [] 267 L = []
268 def collector(name, *args): 268 def collector(name, *args):
269 L.append(name) 269 L.append(name)
270 p.StartElementHandler = collector 270 p.StartElementHandler = collector
271 p.EndElementHandler = collector 271 p.EndElementHandler = collector
272 p.Parse("<e> <e/> <e></e> </e>", 1) 272 p.Parse("<e> <e/> <e></e> </e>", 1)
273 tag = L[0] 273 tag = L[0]
274 self.assertEqual(len(L), 6) 274 self.assertEqual(len(L), 6)
275 for entry in L: 275 for entry in L:
276 # L should have the same string repeated over and over. 276 # L should have the same string repeated over and over.
277 self.assertTrue(tag is entry) 277 self.assertIs(tag, entry)
278 278
279 def test_issue9402(self): 279 def test_issue9402(self):
280 # create an ExternalEntityParserCreate with buffer text 280 # create an ExternalEntityParserCreate with buffer text
281 class ExternalOutputter: 281 class ExternalOutputter:
282 def __init__(self, parser): 282 def __init__(self, parser):
283 self.parser = parser 283 self.parser = parser
284 self.parser_result = None 284 self.parser_result = None
285 285
286 def ExternalEntityRefHandler(self, context, base, sysId, pubId): 286 def ExternalEntityRefHandler(self, context, base, sysId, pubId):
287 external_parser = self.parser.ExternalEntityParserCreate("") 287 external_parser = self.parser.ExternalEntityParserCreate("")
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 self.check_pos('s') 414 self.check_pos('s')
415 415
416 def EndElementHandler(self, name): 416 def EndElementHandler(self, name):
417 self.check_pos('e') 417 self.check_pos('e')
418 418
419 def check_pos(self, event): 419 def check_pos(self, event):
420 pos = (event, 420 pos = (event,
421 self.parser.CurrentByteIndex, 421 self.parser.CurrentByteIndex,
422 self.parser.CurrentLineNumber, 422 self.parser.CurrentLineNumber,
423 self.parser.CurrentColumnNumber) 423 self.parser.CurrentColumnNumber)
424 self.assertTrue(self.upto < len(self.expected_list), 424 self.assertLess(self.upto, len(self.expected_list),
425 'too many parser events') 425 'too many parser events')
426 expected = self.expected_list[self.upto] 426 expected = self.expected_list[self.upto]
427 self.assertEqual(pos, expected, 427 self.assertEqual(pos, expected,
428 'Expected position %s, got position %s' %(pos, expected)) 428 'Expected position %s, got position %s' %(pos, expected))
429 self.upto += 1 429 self.upto += 1
430 430
431 def test(self): 431 def test(self):
432 self.parser = expat.ParserCreate() 432 self.parser = expat.ParserCreate()
433 self.parser.StartElementHandler = self.StartElementHandler 433 self.parser.StartElementHandler = self.StartElementHandler
434 self.parser.EndElementHandler = self.EndElementHandler 434 self.parser.EndElementHandler = self.EndElementHandler
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 HandlerExceptionTest, 680 HandlerExceptionTest,
681 PositionTest, 681 PositionTest,
682 sf1296433Test, 682 sf1296433Test,
683 ChardataBufferTest, 683 ChardataBufferTest,
684 MalformedInputTest, 684 MalformedInputTest,
685 ErrorMessageTest, 685 ErrorMessageTest,
686 ForeignDTDTests) 686 ForeignDTDTests)
687 687
688 if __name__ == "__main__": 688 if __name__ == "__main__":
689 test_main() 689 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_pulldom.py ('k') | Lib/test/test_queue.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+