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

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

Issue 16510: Using appropriate checks in tests
Patch Set: Created 5 years, 10 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_iter.py ('k') | Lib/test/test_json/test_decode.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 itertools import * 3 from itertools import *
4 from weakref import proxy 4 from weakref import proxy
5 from decimal import Decimal 5 from decimal import Decimal
6 from fractions import Fraction 6 from fractions import Fraction
7 import sys 7 import sys
8 import operator 8 import operator
9 import random 9 import random
10 import copy 10 import copy
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 result = list(cwr(values, r)) 319 result = list(cwr(values, r))
320 320
321 self.assertEqual(len(result), numcombs(n, r)) # right number of combs 321 self.assertEqual(len(result), numcombs(n, r)) # right number of combs
322 self.assertEqual(len(result), len(set(result))) # no rep eats 322 self.assertEqual(len(result), len(set(result))) # no rep eats
323 self.assertEqual(result, sorted(result)) # lexico graphic order 323 self.assertEqual(result, sorted(result)) # lexico graphic order
324 324
325 regular_combs = list(combinations(values, r)) # compar e to combs without replacement 325 regular_combs = list(combinations(values, r)) # compar e to combs without replacement
326 if n == 0 or r <= 1: 326 if n == 0 or r <= 1:
327 self.assertEqual(result, regular_combs) # cases t hat should be identical 327 self.assertEqual(result, regular_combs) # cases t hat should be identical
328 else: 328 else:
329 self.assertTrue(set(result) >= set(regular_combs)) # res t should be supersets of regular combs 329 self.assertGreaterEqual(set(result), set(regular_combs)) # rest should be supersets of regular combs
330 330
331 for c in result: 331 for c in result:
332 self.assertEqual(len(c), r) # r-leng th combinations 332 self.assertEqual(len(c), r) # r-leng th combinations
333 noruns = [k for k,v in groupby(c)] # combo without consecutive repeats 333 noruns = [k for k,v in groupby(c)] # combo without consecutive repeats
334 self.assertEqual(len(noruns), len(set(noruns))) # no rep eats other than consecutive 334 self.assertEqual(len(noruns), len(set(noruns))) # no rep eats other than consecutive
335 self.assertEqual(list(c), sorted(c)) # keep o riginal ordering 335 self.assertEqual(list(c), sorted(c)) # keep o riginal ordering
336 self.assertTrue(all(e in values for e in c)) # ele ments taken from input iterable 336 self.assertTrue(all(e in values for e in c)) # ele ments taken from input iterable
337 self.assertEqual(noruns, 337 self.assertEqual(noruns,
338 [e for e in values if e in c]) # comb i s a subsequence of the input iterable 338 [e for e in values if e in c]) # comb i s a subsequence of the input iterable
339 self.assertEqual(result, list(cwr1(values, r))) # matche s first pure python version 339 self.assertEqual(result, list(cwr1(values, r))) # matche s first pure python version
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after
1184 self.assertRaises(ValueError, tee, [], -1) 1184 self.assertRaises(ValueError, tee, [], -1)
1185 for n in range(5): 1185 for n in range(5):
1186 result = tee('abc', n) 1186 result = tee('abc', n)
1187 self.assertEqual(type(result), tuple) 1187 self.assertEqual(type(result), tuple)
1188 self.assertEqual(len(result), n) 1188 self.assertEqual(len(result), n)
1189 self.assertEqual([list(x) for x in result], [list('abc')]*n) 1189 self.assertEqual([list(x) for x in result], [list('abc')]*n)
1190 1190
1191 # tee pass-through to copyable iterator 1191 # tee pass-through to copyable iterator
1192 a, b = tee('abc') 1192 a, b = tee('abc')
1193 c, d = tee(a) 1193 c, d = tee(a)
1194 self.assertTrue(a is c) 1194 self.assertIs(a, c)
1195 1195
1196 # test tee_new 1196 # test tee_new
1197 t1, t2 = tee('abc') 1197 t1, t2 = tee('abc')
1198 tnew = type(t1) 1198 tnew = type(t1)
1199 self.assertRaises(TypeError, tnew) 1199 self.assertRaises(TypeError, tnew)
1200 self.assertRaises(TypeError, tnew, 10) 1200 self.assertRaises(TypeError, tnew, 10)
1201 t3 = tnew(t1) 1201 t3 = tnew(t1)
1202 self.assertTrue(list(t1) == list(t2) == list(t3) == list('abc')) 1202 self.assertEqual(list(t1), list('abc'))
1203 self.assertEqual(list(t2), list('abc'))
1204 self.assertEqual(list(t3), list('abc'))
1203 1205
1204 # test that tee objects are weak referencable 1206 # test that tee objects are weak referencable
1205 a, b = tee(range(10)) 1207 a, b = tee(range(10))
1206 p = proxy(a) 1208 p = proxy(a)
1207 self.assertEqual(getattr(p, '__class__'), type(b)) 1209 self.assertEqual(getattr(p, '__class__'), type(b))
1208 del a 1210 del a
1209 self.assertRaises(ReferenceError, getattr, p, '__class__') 1211 self.assertRaises(ReferenceError, getattr, p, '__class__')
1210 1212
1211 ans = list('abc') 1213 ans = list('abc')
1212 long_ans = list(range(10000)) 1214 long_ans = list(range(10000))
(...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after
2094 support.run_unittest(*test_classes) 2096 support.run_unittest(*test_classes)
2095 gc.collect() 2097 gc.collect()
2096 counts[i] = sys.gettotalrefcount() 2098 counts[i] = sys.gettotalrefcount()
2097 print(counts) 2099 print(counts)
2098 2100
2099 # doctest the examples in the library reference 2101 # doctest the examples in the library reference
2100 support.run_doctest(sys.modules[__name__], verbose) 2102 support.run_doctest(sys.modules[__name__], verbose)
2101 2103
2102 if __name__ == "__main__": 2104 if __name__ == "__main__":
2103 test_main(verbose=True) 2105 test_main(verbose=True)
OLDNEW
« no previous file with comments | « Lib/test/test_iter.py ('k') | Lib/test/test_json/test_decode.py » ('j') | no next file with comments »

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