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

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

Issue 16510: Using appropriate checks in tests
Patch Set: Created 5 years, 7 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_re.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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 L = [] 278 L = []
279 def collector(name, *args): 279 def collector(name, *args):
280 L.append(name) 280 L.append(name)
281 p.StartElementHandler = collector 281 p.StartElementHandler = collector
282 p.EndElementHandler = collector 282 p.EndElementHandler = collector
283 p.Parse(b"<e> <e/> <e></e> </e>", 1) 283 p.Parse(b"<e> <e/> <e></e> </e>", 1)
284 tag = L[0] 284 tag = L[0]
285 self.assertEqual(len(L), 6) 285 self.assertEqual(len(L), 6)
286 for entry in L: 286 for entry in L:
287 # L should have the same string repeated over and over. 287 # L should have the same string repeated over and over.
288 self.assertTrue(tag is entry) 288 self.assertIs(tag, entry)
289 289
290 def test_issue9402(self): 290 def test_issue9402(self):
291 # create an ExternalEntityParserCreate with buffer text 291 # create an ExternalEntityParserCreate with buffer text
292 class ExternalOutputter: 292 class ExternalOutputter:
293 def __init__(self, parser): 293 def __init__(self, parser):
294 self.parser = parser 294 self.parser = parser
295 self.parser_result = None 295 self.parser_result = None
296 296
297 def ExternalEntityRefHandler(self, context, base, sysId, pubId): 297 def ExternalEntityRefHandler(self, context, base, sysId, pubId):
298 external_parser = self.parser.ExternalEntityParserCreate("") 298 external_parser = self.parser.ExternalEntityParserCreate("")
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 self.check_pos('s') 425 self.check_pos('s')
426 426
427 def EndElementHandler(self, name): 427 def EndElementHandler(self, name):
428 self.check_pos('e') 428 self.check_pos('e')
429 429
430 def check_pos(self, event): 430 def check_pos(self, event):
431 pos = (event, 431 pos = (event,
432 self.parser.CurrentByteIndex, 432 self.parser.CurrentByteIndex,
433 self.parser.CurrentLineNumber, 433 self.parser.CurrentLineNumber,
434 self.parser.CurrentColumnNumber) 434 self.parser.CurrentColumnNumber)
435 self.assertTrue(self.upto < len(self.expected_list), 435 self.assertLess(self.upto, len(self.expected_list),
436 'too many parser events') 436 'too many parser events')
437 expected = self.expected_list[self.upto] 437 expected = self.expected_list[self.upto]
438 self.assertEqual(pos, expected, 438 self.assertEqual(pos, expected,
439 'Expected position %s, got position %s' %(pos, expected)) 439 'Expected position %s, got position %s' %(pos, expected))
440 self.upto += 1 440 self.upto += 1
441 441
442 def test(self): 442 def test(self):
443 self.parser = expat.ParserCreate() 443 self.parser = expat.ParserCreate()
444 self.parser.StartElementHandler = self.StartElementHandler 444 self.parser.StartElementHandler = self.StartElementHandler
445 self.parser.EndElementHandler = self.EndElementHandler 445 self.parser.EndElementHandler = self.EndElementHandler
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 HandlerExceptionTest, 687 HandlerExceptionTest,
688 PositionTest, 688 PositionTest,
689 sf1296433Test, 689 sf1296433Test,
690 ChardataBufferTest, 690 ChardataBufferTest,
691 MalformedInputTest, 691 MalformedInputTest,
692 ErrorMessageTest, 692 ErrorMessageTest,
693 ForeignDTDTests) 693 ForeignDTDTests)
694 694
695 if __name__ == "__main__": 695 if __name__ == "__main__":
696 test_main() 696 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_pulldom.py ('k') | Lib/test/test_re.py » ('j') | no next file with comments »

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