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

## Delta Between Two Patch Sets: Lib/test/test_itertools.py

Issue 16510: Using appropriate checks in tests
Left Patch Set: Created 6 years ago
Right Patch Set: Created 5 years, 10 months ago
 Left: Base Patch Set 1: None Patch Set 2: None Patch Set 3: None Patch Set 4: None Patch Set 5: None Right: Patch Set 1: None Patch Set 2: None Patch Set 3: None Patch Set 4: None Patch Set 5: None
« no previous file with change/comment | « Lib/test/test_iter.py ('k') | Lib/test/test_json/test_decode.py » ('j') | no next file with change/comment »
LEFTRIGHT
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
11 import pickle 11 import pickle
12 from functools import reduce 12 from functools import reduce
13 import sys
14 import struct
13 maxsize = support.MAX_Py_ssize_t 15 maxsize = support.MAX_Py_ssize_t
14 minsize = -maxsize-1 16 minsize = -maxsize-1
15 17
16 def lzip(*args): 18 def lzip(*args):
17 return list(zip(*args)) 19 return list(zip(*args))
18 20
19 def onearg(x): 21 def onearg(x):
20 'Test function of one argument' 22 'Test function of one argument'
21 return 2*x 23 return 2*x
22 24
(...skipping 1779 matching lines...)
1802 starmap, islice, takewhile, dropwhile, cycle, compress): 1804 starmap, islice, takewhile, dropwhile, cycle, compress):
1803 class Subclass(cls): 1805 class Subclass(cls):
1804 def __init__(self, newarg=None, *args): 1806 def __init__(self, newarg=None, *args):
1805 cls.__init__(self, *args) 1807 cls.__init__(self, *args)
1806 try: 1808 try:
1807 Subclass(newarg=1) 1809 Subclass(newarg=1)
1808 except TypeError as err: 1810 except TypeError as err:
1809 # we expect type errors because of wrong argument count 1811 # we expect type errors because of wrong argument count
1810 self.assertNotIn("does not take keyword arguments", err.args[0]) 1812 self.assertNotIn("does not take keyword arguments", err.args[0])
1811 1813
1814 @support.cpython_only
1815 class SizeofTest(unittest.TestCase):
1816 def setUp(self):
1817 self.ssize_t = struct.calcsize('n')
1818
1819 check_sizeof = support.check_sizeof
1820
1821 def test_product_sizeof(self):
1822 basesize = support.calcobjsize('3Pi')
1823 check = self.check_sizeof
1824 check(product('ab', '12'), basesize + 2 * self.ssize_t)
1825 check(product(*(('abc',) * 10)), basesize + 10 * self.ssize_t)
1826
1827 def test_combinations_sizeof(self):
1828 basesize = support.calcobjsize('3Pni')
1829 check = self.check_sizeof
1830 check(combinations('abcd', 3), basesize + 3 * self.ssize_t)
1831 check(combinations(range(10), 4), basesize + 4 * self.ssize_t)
1832
1833 def test_combinations_with_replacement_sizeof(self):
1834 cwr = combinations_with_replacement
1835 basesize = support.calcobjsize('3Pni')
1836 check = self.check_sizeof
1837 check(cwr('abcd', 3), basesize + 3 * self.ssize_t)
1838 check(cwr(range(10), 4), basesize + 4 * self.ssize_t)
1839
1840 def test_permutations_sizeof(self):
1841 basesize = support.calcobjsize('4Pni')
1842 check = self.check_sizeof
1843 check(permutations('abcd'),
1844 basesize + 4 * self.ssize_t + 4 * self.ssize_t)
1845 check(permutations('abcd', 3),
1846 basesize + 4 * self.ssize_t + 3 * self.ssize_t)
1847 check(permutations('abcde', 3),
1848 basesize + 5 * self.ssize_t + 3 * self.ssize_t)
1849 check(permutations(range(10), 4),
1850 basesize + 10 * self.ssize_t + 4 * self.ssize_t)
1851
1812 1852
1813 libreftest = """ Doctest for examples in the library reference: libitertools.tex 1853 libreftest = """ Doctest for examples in the library reference: libitertools.tex
1814 1854
1815 1855
1816 >>> amounts = [120.15, 764.05, 823.14] 1856 >>> amounts = [120.15, 764.05, 823.14]
1817 >>> for checknum, amount in zip(count(1200), amounts): 1857 >>> for checknum, amount in zip(count(1200), amounts):
1818 ... print('Check %d is for \$%.2f' % (checknum, amount)) 1858 ... print('Check %d is for \$%.2f' % (checknum, amount))
1819 ... 1859 ...
1820 Check 1200 is for \$120.15 1860 Check 1200 is for \$120.15
1821 Check 1201 is for \$764.05 1861 Check 1201 is for \$764.05
(...skipping 215 matching lines...)
2038 ['A', 'B', 'C', 'A', 'D'] 2078 ['A', 'B', 'C', 'A', 'D']
2039 2079
2040 """ 2080 """
2041 2081
2042 __test__ = {'libreftest' : libreftest} 2082 __test__ = {'libreftest' : libreftest}
2043 2083
2044 def test_main(verbose=None): 2084 def test_main(verbose=None):
2045 test_classes = (TestBasicOps, TestVariousIteratorArgs, TestGC, 2085 test_classes = (TestBasicOps, TestVariousIteratorArgs, TestGC,
2046 RegressionTests, LengthTransparency, 2086 RegressionTests, LengthTransparency,
2047 SubclassWithKwargsTest, TestExamples) 2087 SubclassWithKwargsTest, TestExamples,
2088 SizeofTest)
2048 support.run_unittest(*test_classes) 2089 support.run_unittest(*test_classes)
2049 2090
2050 # verify reference counting 2091 # verify reference counting
2051 if verbose and hasattr(sys, "gettotalrefcount"): 2092 if verbose and hasattr(sys, "gettotalrefcount"):
2052 import gc 2093 import gc
2053 counts = [None] * 5 2094 counts = [None] * 5
2054 for i in range(len(counts)): 2095 for i in range(len(counts)):
2055 support.run_unittest(*test_classes) 2096 support.run_unittest(*test_classes)
2056 gc.collect() 2097 gc.collect()
2057 counts[i] = sys.gettotalrefcount() 2098 counts[i] = sys.gettotalrefcount()
2058 print(counts) 2099 print(counts)
2059 2100
2060 # doctest the examples in the library reference 2101 # doctest the examples in the library reference
2061 support.run_doctest(sys.modules[__name__], verbose) 2102 support.run_doctest(sys.modules[__name__], verbose)
2062 2103
2063 if __name__ == "__main__": 2104 if __name__ == "__main__":
2064 test_main(verbose=True) 2105 test_main(verbose=True)
LEFTRIGHT

This is Rietveld 894c83f36cb7+