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

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

Issue 14010: deeply nested filter segfaults
Patch Set: Created 6 years, 6 months ago
 Left: Base Patch Set 1: None Right: Patch Set 1: None
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
« no previous file with comments | « Lib/test/test_builtin.py ('k') | Modules/itertoolsmodule.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | 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 1788 matching lines...)
1799 for cls in (repeat, zip, filter, filterfalse, chain, map, 1799 for cls in (repeat, zip, filter, filterfalse, chain, map,
1800 starmap, islice, takewhile, dropwhile, cycle, compress): 1800 starmap, islice, takewhile, dropwhile, cycle, compress):
1801 class Subclass(cls): 1801 class Subclass(cls):
1802 def __init__(self, newarg=None, *args): 1802 def __init__(self, newarg=None, *args):
1803 cls.__init__(self, *args) 1803 cls.__init__(self, *args)
1804 try: 1804 try:
1805 Subclass(newarg=1) 1805 Subclass(newarg=1)
1806 except TypeError as err: 1806 except TypeError as err:
1807 # we expect type errors because of wrong argument count 1807 # we expect type errors because of wrong argument count
1808 self.assertNotIn("does not take keyword arguments", err.args[0]) 1808 self.assertNotIn("does not take keyword arguments", err.args[0])
1809
1810
1811 class TestRecursionLimit(unittest.TestCase):
1812 # Issue #14010
1813 recursionlimit = sys.getrecursionlimit()
1814
1815 def test_accumulate(self):
1816 it = (0, 1)
1817 for _ in range(self.recursionlimit):
1818 it = accumulate(it)
1819 with self.assertRaises(RuntimeError):
1820 for _ in it:
1821 pass
1822 del it
1823
1824 def test_chain(self):
1825 it = (0, 1)
1826 for _ in range(self.recursionlimit):
1827 it = chain(it, ())
1828 with self.assertRaises(RuntimeError):
1829 for _ in it:
1830 pass
1831 del it
1832
1833 def test_compress(self):
1834 data = (0, 1)
1835 selectors = (True, True)
1836 it = data
1837 for _ in range(self.recursionlimit):
1838 it = compress(it, selectors)
1839 with self.assertRaises(RuntimeError):
1840 for _ in it:
1841 pass
1842 del it
1843
1844 it = selectors
1845 for _ in range(self.recursionlimit):
1846 it = compress(data, it)
1847 with self.assertRaises(RuntimeError):
1848 for _ in it:
1849 pass
1850 del it
1851
1852 def test_cycle(self):
1853 it = (0, 1)
1854 for _ in range(self.recursionlimit):
1855 it = cycle(it)
1856 with self.assertRaises(RuntimeError):
1857 for _ in range(3):
1858 next(it)
1859 del it
1860
1861 def test_dropwhile(self):
1862 it = (0, 1, 0)
1863 for _ in range(self.recursionlimit):
1864 it = dropwhile(bool, it)
1865 with self.assertRaises(RuntimeError):
1866 for _ in it:
1867 pass
1868 del it
1869
1870 def test_filterfalse(self):
1871 it = (0, 1)
1872 for _ in range(self.recursionlimit):
1873 it = filterfalse(bool, it)
1874 with self.assertRaises(RuntimeError):
1875 for _ in it:
1876 pass
1877 del it
1878
1879 def test_groupby(self):
1880 key = operator.itemgetter(0)
1881 it = ((0, []), (1, []))
1882 for _ in range(self.recursionlimit):
1883 it = groupby(it, key)
1884 with self.assertRaises(RuntimeError):
1885 for _ in it:
1886 pass
1887 del it
1888
1889 def test_islice(self):
1890 it = (0, 1)
1891 for _ in range(self.recursionlimit):
1892 it = islice(it, 2)
1893 with self.assertRaises(RuntimeError):
1894 for _ in it:
1895 pass
1896 del it
1897
1898 def test_starmap(self):
1899 it = 'ab'
1900 for _ in range(self.recursionlimit):
1901 it = starmap(tuple, it)
1902 with self.assertRaises(RuntimeError):
1903 for _ in it:
1904 pass
1905 del it
1906
1907 def test_takewhile(self):
1908 it = (1, 0)
1909 for _ in range(self.recursionlimit):
1910 it = takewhile(bool, it)
1911 with self.assertRaises(RuntimeError):
1912 for _ in it:
1913 pass
1914 del it
1915
1916 def test_zip_longest(self):
1917 it = (0, 1)
1918 for _ in range(self.recursionlimit):
1919 it = zip_longest(it)
1920 with self.assertRaises(RuntimeError):
1921 for _ in it:
1922 pass
1923 del it
1809 1924
1810 1925
1811 libreftest = """ Doctest for examples in the library reference: libitertools.tex 1926 libreftest = """ Doctest for examples in the library reference: libitertools.tex
1812 1927
1813 1928
1814 >>> amounts = [120.15, 764.05, 823.14] 1929 >>> amounts = [120.15, 764.05, 823.14]
1815 >>> for checknum, amount in zip(count(1200), amounts): 1930 >>> for checknum, amount in zip(count(1200), amounts):
1816 ... print('Check %d is for \$%.2f' % (checknum, amount)) 1931 ... print('Check %d is for \$%.2f' % (checknum, amount))
1817 ... 1932 ...
1818 Check 1200 is for \$120.15 1933 Check 1200 is for \$120.15
(...skipping 216 matching lines...)
2035 >>> list(unique_justseen('ABBCcAD', str.lower)) 2150 >>> list(unique_justseen('ABBCcAD', str.lower))
2036 ['A', 'B', 'C', 'A', 'D'] 2151 ['A', 'B', 'C', 'A', 'D']
2037 2152
2038 """ 2153 """
2039 2154
2040 __test__ = {'libreftest' : libreftest} 2155 __test__ = {'libreftest' : libreftest}
2041 2156
2042 def test_main(verbose=None): 2157 def test_main(verbose=None):
2043 test_classes = (TestBasicOps, TestVariousIteratorArgs, TestGC, 2158 test_classes = (TestBasicOps, TestVariousIteratorArgs, TestGC,
2044 RegressionTests, LengthTransparency, 2159 RegressionTests, LengthTransparency,
2045 SubclassWithKwargsTest, TestExamples) 2160 SubclassWithKwargsTest, TestExamples, TestRecursionLimit)
2046 support.run_unittest(*test_classes) 2161 support.run_unittest(*test_classes)
2047 2162
2048 # verify reference counting 2163 # verify reference counting
2049 if verbose and hasattr(sys, "gettotalrefcount"): 2164 if verbose and hasattr(sys, "gettotalrefcount"):
2050 import gc 2165 import gc
2051 counts = [None] * 5 2166 counts = [None] * 5
2052 for i in range(len(counts)): 2167 for i in range(len(counts)):
2053 support.run_unittest(*test_classes) 2168 support.run_unittest(*test_classes)
2054 gc.collect() 2169 gc.collect()
2055 counts[i] = sys.gettotalrefcount() 2170 counts[i] = sys.gettotalrefcount()
2056 print(counts) 2171 print(counts)
2057 2172
2058 # doctest the examples in the library reference 2173 # doctest the examples in the library reference
2059 support.run_doctest(sys.modules[__name__], verbose) 2174 support.run_doctest(sys.modules[__name__], verbose)
2060 2175
2061 if __name__ == "__main__": 2176 if __name__ == "__main__":
2062 test_main(verbose=True) 2177 test_main(verbose=True)
OLDNEW
« no previous file with comments | « Lib/test/test_builtin.py ('k') | Modules/itertoolsmodule.c » ('j') | no next file with comments »

This is Rietveld 894c83f36cb7+