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

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

Issue 16510: Using appropriate checks in tests
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:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_uuid.py ('k') | Lib/test/test_winreg.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 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 for C in set, frozenset, dict.fromkeys, list, tuple: 98 for C in set, frozenset, dict.fromkeys, list, tuple:
99 x = WeakSet([]) 99 x = WeakSet([])
100 self.assertEqual(i.intersection(C(self.items)), x) 100 self.assertEqual(i.intersection(C(self.items)), x)
101 self.assertEqual(len(i), len(self.items2)) 101 self.assertEqual(len(i), len(self.items2))
102 self.items2.pop() 102 self.items2.pop()
103 gc.collect() 103 gc.collect()
104 self.assertEqual(len(i), len(self.items2)) 104 self.assertEqual(len(i), len(self.items2))
105 105
106 def test_isdisjoint(self): 106 def test_isdisjoint(self):
107 self.assertTrue(self.s.isdisjoint(WeakSet(self.items2))) 107 self.assertTrue(self.s.isdisjoint(WeakSet(self.items2)))
108 self.assertTrue(not self.s.isdisjoint(WeakSet(self.letters))) 108 self.assertFalse(self.s.isdisjoint(WeakSet(self.letters)))
109 109
110 def test_and(self): 110 def test_and(self):
111 i = self.s.intersection(self.items2) 111 i = self.s.intersection(self.items2)
112 self.assertEqual(self.s & set(self.items2), i) 112 self.assertEqual(self.s & set(self.items2), i)
113 self.assertEqual(self.s & frozenset(self.items2), i) 113 self.assertEqual(self.s & frozenset(self.items2), i)
114 114
115 def test_difference(self): 115 def test_difference(self):
116 i = self.s.difference(self.items2) 116 i = self.s.difference(self.items2)
117 for c in self.letters: 117 for c in self.letters:
118 self.assertEqual(c in i, c in self.d and c not in self.items2) 118 self.assertEqual(c in i, c in self.d and c not in self.items2)
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 215
216 def test_add(self): 216 def test_add(self):
217 x = ustr('Q') 217 x = ustr('Q')
218 self.s.add(x) 218 self.s.add(x)
219 self.assertIn(x, self.s) 219 self.assertIn(x, self.s)
220 dup = self.s.copy() 220 dup = self.s.copy()
221 self.s.add(x) 221 self.s.add(x)
222 self.assertEqual(self.s, dup) 222 self.assertEqual(self.s, dup)
223 self.assertRaises(TypeError, self.s.add, []) 223 self.assertRaises(TypeError, self.s.add, [])
224 self.fs.add(Foo()) 224 self.fs.add(Foo())
225 self.assertTrue(len(self.fs) == 1) 225 self.assertEqual(len(self.fs), 1)
226 self.fs.add(self.obj) 226 self.fs.add(self.obj)
227 self.assertTrue(len(self.fs) == 1) 227 self.assertEqual(len(self.fs), 1)
228 228
229 def test_remove(self): 229 def test_remove(self):
230 x = ustr('a') 230 x = ustr('a')
231 self.s.remove(x) 231 self.s.remove(x)
232 self.assertNotIn(x, self.s) 232 self.assertNotIn(x, self.s)
233 self.assertRaises(KeyError, self.s.remove, x) 233 self.assertRaises(KeyError, self.s.remove, x)
234 self.assertRaises(TypeError, self.s.remove, []) 234 self.assertRaises(TypeError, self.s.remove, [])
235 235
236 def test_discard(self): 236 def test_discard(self):
237 a, q = ustr('a'), ustr('Q') 237 a, q = ustr('a'), ustr('Q')
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 self.assertLessEqual(n1, N) 441 self.assertLessEqual(n1, N)
442 self.assertGreaterEqual(n2, 0) 442 self.assertGreaterEqual(n2, 0)
443 self.assertLessEqual(n2, n1) 443 self.assertLessEqual(n2, n1)
444 444
445 445
446 def test_main(verbose=None): 446 def test_main(verbose=None):
447 support.run_unittest(TestWeakSet) 447 support.run_unittest(TestWeakSet)
448 448
449 if __name__ == "__main__": 449 if __name__ == "__main__":
450 test_main(verbose=True) 450 test_main(verbose=True)
OLDNEW
« no previous file with comments | « Lib/test/test_uuid.py ('k') | Lib/test/test_winreg.py » ('j') | no next file with comments »

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