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

Delta Between Two Patch Sets: Lib/test/test_weakset.py

Issue 16510: Using appropriate checks in tests
Left Patch Set: Created 5 years, 9 months ago
Right Patch Set: Created 5 years, 6 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/test/test_uuid.py ('k') | Lib/test/test_winreg.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 import unittest 1 import unittest
2 from test import support 2 from test import support
3 from weakref import proxy, ref, WeakSet 3 from weakref import proxy, ref, WeakSet
4 import operator 4 import operator
5 import copy 5 import copy
6 import string 6 import string
7 import os 7 import os
8 from random import randrange, shuffle 8 from random import randrange, shuffle
9 import sys 9 import sys
10 import warnings 10 import warnings
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 self.assertEqual(len(s), len(items)) 363 self.assertEqual(len(s), len(items))
364 364
365 def test_weak_destroy_and_mutate_while_iterating(self): 365 def test_weak_destroy_and_mutate_while_iterating(self):
366 # Issue #7105: iterators shouldn't crash when a key is implicitly remove d 366 # Issue #7105: iterators shouldn't crash when a key is implicitly remove d
367 items = [ustr(c) for c in string.ascii_letters] 367 items = [ustr(c) for c in string.ascii_letters]
368 s = WeakSet(items) 368 s = WeakSet(items)
369 @contextlib.contextmanager 369 @contextlib.contextmanager
370 def testcontext(): 370 def testcontext():
371 try: 371 try:
372 it = iter(s) 372 it = iter(s)
373 next(it) 373 # Start iterator
374 del it 374 yielded = ustr(str(next(it)))
375 # Schedule an item for removal and recreate it 375 # Schedule an item for removal and recreate it
376 u = ustr(str(items.pop())) 376 u = ustr(str(items.pop()))
377 if yielded == u:
378 # The iterator still has a reference to the removed item,
379 # advance it (issue #20006).
380 next(it)
377 gc.collect() # just in case 381 gc.collect() # just in case
378 yield u 382 yield u
379 finally: 383 finally:
380 it = None # should commit all removals 384 it = None # should commit all removals
381 385
382 with testcontext() as u: 386 with testcontext() as u:
383 self.assertNotIn(u, s) 387 self.assertNotIn(u, s)
384 with testcontext() as u: 388 with testcontext() as u:
385 self.assertRaises(KeyError, s.remove, u) 389 self.assertRaises(KeyError, s.remove, u)
386 self.assertNotIn(u, s) 390 self.assertNotIn(u, s)
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 self.assertLessEqual(n1, N) 441 self.assertLessEqual(n1, N)
438 self.assertGreaterEqual(n2, 0) 442 self.assertGreaterEqual(n2, 0)
439 self.assertLessEqual(n2, n1) 443 self.assertLessEqual(n2, n1)
440 444
441 445
442 def test_main(verbose=None): 446 def test_main(verbose=None):
443 support.run_unittest(TestWeakSet) 447 support.run_unittest(TestWeakSet)
444 448
445 if __name__ == "__main__": 449 if __name__ == "__main__":
446 test_main(verbose=True) 450 test_main(verbose=True)
LEFTRIGHT

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