@@ -1808,6 +1808,121 @@ def __init__(self, newarg=None, *args):
18081808 self .assertNotIn ("does not take keyword arguments" , err .args [0 ])
18091809
18101810
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
1924+
1925+
18111926libreftest = """ Doctest for examples in the library reference: libitertools.tex
18121927
18131928
@@ -2042,7 +2157,7 @@ def __init__(self, newarg=None, *args):
20422157def test_main (verbose = None ):
20432158 test_classes = (TestBasicOps , TestVariousIteratorArgs , TestGC ,
20442159 RegressionTests , LengthTransparency ,
2045- SubclassWithKwargsTest , TestExamples )
2160+ SubclassWithKwargsTest , TestExamples , TestRecursionLimit )
20462161 support .run_unittest (* test_classes )
20472162
20482163 # verify reference counting
0 commit comments