diff options
author | Benjamin Peterson <benjamin@python.org> | 2015-02-02 02:34:07 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2015-02-02 02:34:07 (GMT) |
commit | 0eaabf1c05127793753dbb3641d4d107b284ae77 (patch) | |
tree | 339d052650eadbf997c68401f6917c2fcc6654bd /Lib | |
parent | 6f082297b260d3eb4975d6d4305eba6fd26f9ae9 (diff) | |
download | cpython-0eaabf1c05127793753dbb3641d4d107b284ae77.zip cpython-0eaabf1c05127793753dbb3641d4d107b284ae77.tar.gz cpython-0eaabf1c05127793753dbb3641d4d107b284ae77.tar.bz2 |
check for overflows in permutations() and product() (closes #23363, closes #23364)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_itertools.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py index 355c690..3d02914 100644 --- a/Lib/test/test_itertools.py +++ b/Lib/test/test_itertools.py @@ -418,6 +418,13 @@ class TestBasicOps(unittest.TestCase): self.pickletest(permutations(values, r)) # test pickling + @support.bigaddrspacetest + def test_permutations_overflow(self): + with self.assertRaises(OverflowError): + permutations("A", 2**30) + with self.assertRaises(OverflowError): + permutations("A", 2, 2**30) + @support.impl_detail("tuple resuse is CPython specific") def test_permutations_tuple_reuse(self): self.assertEqual(len(set(map(id, permutations('abcde', 3)))), 1) @@ -930,6 +937,11 @@ class TestBasicOps(unittest.TestCase): args = map(iter, args) self.assertEqual(len(list(product(*args))), expected_len) + @support.bigaddrspacetest + def test_product_overflow(self): + with self.assertRaises(OverflowError): + product(["a"]*(2**16), repeat=2**16) + @support.impl_detail("tuple reuse is specific to CPython") def test_product_tuple_reuse(self): self.assertEqual(len(set(map(id, product('abc', 'def')))), 1) |