@@ -1809,6 +1809,121 @@ def __init__(self, newarg=None, *args):
18091809 self .assertNotIn ("does not take keyword arguments" , err .args [0 ])
18101810
18111811
1812+ class TestRecursionLimit (unittest .TestCase ):
1813+ # Issue #14010
1814+ recursionlimit = sys .getrecursionlimit ()
1815+
1816+ def test_accumulate (self ):
1817+ it = (0 , 1 )
1818+ for _ in range (self .recursionlimit ):
1819+ it = accumulate (it )
1820+ with self .assertRaises (RuntimeError ):
1821+ for _ in it :
1822+ pass
1823+ del it
1824+
1825+ def test_chain (self ):
1826+ it = (0 , 1 )
1827+ for _ in range (self .recursionlimit ):
1828+ it = chain (it , ())
1829+ with self .assertRaises (RuntimeError ):
1830+ for _ in it :
1831+ pass
1832+ del it
1833+
1834+ def test_compress (self ):
1835+ data = (0 , 1 )
1836+ selectors = (True , True )
1837+ it = data
1838+ for _ in range (self .recursionlimit ):
1839+ it = compress (it , selectors )
1840+ with self .assertRaises (RuntimeError ):
1841+ for _ in it :
1842+ pass
1843+ del it
1844+
1845+ it = selectors
1846+ for _ in range (self .recursionlimit ):
1847+ it = compress (data , it )
1848+ with self .assertRaises (RuntimeError ):
1849+ for _ in it :
1850+ pass
1851+ del it
1852+
1853+ def test_cycle (self ):
1854+ it = (0 , 1 )
1855+ for _ in range (self .recursionlimit ):
1856+ it = cycle (it )
1857+ with self .assertRaises (RuntimeError ):
1858+ for _ in range (3 ):
1859+ next (it )
1860+ del it
1861+
1862+ def test_dropwhile (self ):
1863+ it = (0 , 1 , 0 )
1864+ for _ in range (self .recursionlimit ):
1865+ it = dropwhile (bool , it )
1866+ with self .assertRaises (RuntimeError ):
1867+ for _ in it :
1868+ pass
1869+ del it
1870+
1871+ def test_filterfalse (self ):
1872+ it = (0 , 1 )
1873+ for _ in range (self .recursionlimit ):
1874+ it = filterfalse (bool , it )
1875+ with self .assertRaises (RuntimeError ):
1876+ for _ in it :
1877+ pass
1878+ del it
1879+
1880+ def test_groupby (self ):
1881+ key = operator .itemgetter (0 )
1882+ it = ((0 , []), (1 , []))
1883+ for _ in range (self .recursionlimit ):
1884+ it = groupby (it , key )
1885+ with self .assertRaises (RuntimeError ):
1886+ for _ in it :
1887+ pass
1888+ del it
1889+
1890+ def test_islice (self ):
1891+ it = (0 , 1 )
1892+ for _ in range (self .recursionlimit ):
1893+ it = islice (it , 2 )
1894+ with self .assertRaises (RuntimeError ):
1895+ for _ in it :
1896+ pass
1897+ del it
1898+
1899+ def test_starmap (self ):
1900+ it = 'ab'
1901+ for _ in range (self .recursionlimit ):
1902+ it = starmap (tuple , it )
1903+ with self .assertRaises (RuntimeError ):
1904+ for _ in it :
1905+ pass
1906+ del it
1907+
1908+ def test_takewhile (self ):
1909+ it = (1 , 0 )
1910+ for _ in range (self .recursionlimit ):
1911+ it = takewhile (bool , it )
1912+ with self .assertRaises (RuntimeError ):
1913+ for _ in it :
1914+ pass
1915+ del it
1916+
1917+ def test_zip_longest (self ):
1918+ it = (0 , 1 )
1919+ for _ in range (self .recursionlimit ):
1920+ it = zip_longest (it )
1921+ with self .assertRaises (RuntimeError ):
1922+ for _ in it :
1923+ pass
1924+ del it
1925+
1926+
18121927libreftest = """ Doctest for examples in the library reference: libitertools.tex
18131928
18141929
@@ -2043,7 +2158,7 @@ def __init__(self, newarg=None, *args):
20432158def test_main (verbose = None ):
20442159 test_classes = (TestBasicOps , TestVariousIteratorArgs , TestGC ,
20452160 RegressionTests , LengthTransparency ,
2046- SubclassWithKwargsTest , TestExamples )
2161+ SubclassWithKwargsTest , TestExamples , TestRecursionLimit )
20472162 support .run_unittest (* test_classes )
20482163
20492164 # verify reference counting
0 commit comments