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

Side by Side Diff: Lib/test/test_builtin.py

Issue 14010: deeply nested filter segfaults
Patch Set: Created 6 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Lib/test/test_itertools.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Python test set -- built-in functions 1 # Python test set -- built-in functions
2 2
3 import ast 3 import ast
4 import builtins 4 import builtins
5 import collections 5 import collections
6 import io 6 import io
7 import locale 7 import locale
8 import os 8 import os
9 import pickle 9 import pickle
10 import platform 10 import platform
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 628
629 # test bltinmodule.c::filtertuple() 629 # test bltinmodule.c::filtertuple()
630 self.assertEqual(list(filter(None, (1, 2))), [1, 2]) 630 self.assertEqual(list(filter(None, (1, 2))), [1, 2])
631 self.assertEqual(list(filter(lambda x: x>=3, (1, 2, 3, 4))), [3, 4]) 631 self.assertEqual(list(filter(lambda x: x>=3, (1, 2, 3, 4))), [3, 4])
632 self.assertRaises(TypeError, list, filter(42, (1, 2))) 632 self.assertRaises(TypeError, list, filter(42, (1, 2)))
633 633
634 def test_filter_pickle(self): 634 def test_filter_pickle(self):
635 f1 = filter(filter_char, "abcdeabcde") 635 f1 = filter(filter_char, "abcdeabcde")
636 f2 = filter(filter_char, "abcdeabcde") 636 f2 = filter(filter_char, "abcdeabcde")
637 self.check_iter_pickle(f1, list(f2)) 637 self.check_iter_pickle(f1, list(f2))
638
639 def test_filter_deep_recursion(self):
640 # Issue #14010
641 it = (0, 1)
642 for _ in range(1000000):
643 it = filter(bool, it)
644 with self.assertRaises(RuntimeError):
645 for _ in it:
646 pass
647 del it
638 648
639 def test_getattr(self): 649 def test_getattr(self):
640 self.assertTrue(getattr(sys, 'stdout') is sys.stdout) 650 self.assertTrue(getattr(sys, 'stdout') is sys.stdout)
641 self.assertRaises(TypeError, getattr, sys, 1) 651 self.assertRaises(TypeError, getattr, sys, 1)
642 self.assertRaises(TypeError, getattr, sys, 1, "foo") 652 self.assertRaises(TypeError, getattr, sys, 1, "foo")
643 self.assertRaises(TypeError, getattr) 653 self.assertRaises(TypeError, getattr)
644 self.assertRaises(AttributeError, getattr, sys, chr(sys.maxunicode)) 654 self.assertRaises(AttributeError, getattr, sys, chr(sys.maxunicode))
645 # unicode surrogates are not encodable to the default encoding (utf8) 655 # unicode surrogates are not encodable to the default encoding (utf8)
646 self.assertRaises(AttributeError, getattr, 1, "\uDAD1\uD51E") 656 self.assertRaises(AttributeError, getattr, 1, "\uDAD1\uD51E")
647 657
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 yield None 836 yield None
827 self.assertRaises(ValueError, list, map(lambda x: x, BadSeq())) 837 self.assertRaises(ValueError, list, map(lambda x: x, BadSeq()))
828 def badfunc(x): 838 def badfunc(x):
829 raise RuntimeError 839 raise RuntimeError
830 self.assertRaises(RuntimeError, list, map(badfunc, range(5))) 840 self.assertRaises(RuntimeError, list, map(badfunc, range(5)))
831 841
832 def test_map_pickle(self): 842 def test_map_pickle(self):
833 m1 = map(map_char, "Is this the real life?") 843 m1 = map(map_char, "Is this the real life?")
834 m2 = map(map_char, "Is this the real life?") 844 m2 = map(map_char, "Is this the real life?")
835 self.check_iter_pickle(m1, list(m2)) 845 self.check_iter_pickle(m1, list(m2))
846
847 def test_map_deep_recursion(self):
848 # Issue #14010
849 it = (0, 1)
850 for _ in range(1000000):
851 it = map(int, it)
852 with self.assertRaises(RuntimeError):
853 for _ in it:
854 pass
855 del it
836 856
837 def test_max(self): 857 def test_max(self):
838 self.assertEqual(max('123123'), '3') 858 self.assertEqual(max('123123'), '3')
839 self.assertEqual(max(1, 2, 3), 3) 859 self.assertEqual(max(1, 2, 3), 3)
840 self.assertEqual(max((1, 2, 3, 1, 2, 3)), 3) 860 self.assertEqual(max((1, 2, 3, 1, 2, 3)), 3)
841 self.assertEqual(max([1, 2, 3, 1, 2, 3]), 3) 861 self.assertEqual(max([1, 2, 3, 1, 2, 3]), 3)
842 862
843 self.assertEqual(max(1, 2, 3.0), 3.0) 863 self.assertEqual(max(1, 2, 3.0), 3.0)
844 self.assertEqual(max(1, 2.0, 3), 3) 864 self.assertEqual(max(1, 2.0, 3), 3)
845 self.assertEqual(max(1.0, 2, 3), 3) 865 self.assertEqual(max(1.0, 2, 3), 3)
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
1399 else: 1419 else:
1400 return i 1420 return i
1401 self.assertRaises(ValueError, list, zip(BadSeq(), BadSeq())) 1421 self.assertRaises(ValueError, list, zip(BadSeq(), BadSeq()))
1402 1422
1403 def test_zip_pickle(self): 1423 def test_zip_pickle(self):
1404 a = (1, 2, 3) 1424 a = (1, 2, 3)
1405 b = (4, 5, 6) 1425 b = (4, 5, 6)
1406 t = [(1, 4), (2, 5), (3, 6)] 1426 t = [(1, 4), (2, 5), (3, 6)]
1407 z1 = zip(a, b) 1427 z1 = zip(a, b)
1408 self.check_iter_pickle(z1, t) 1428 self.check_iter_pickle(z1, t)
1429
1430 def test_zip_deep_recursion(self):
1431 # Issue #14010
1432 it = (0, 1)
1433 for _ in range(1000000):
1434 it = zip(it)
1435 with self.assertRaises(RuntimeError):
1436 for _ in it:
1437 pass
1438 del it
1409 1439
1410 def test_format(self): 1440 def test_format(self):
1411 # Test the basic machinery of the format() builtin. Don't test 1441 # Test the basic machinery of the format() builtin. Don't test
1412 # the specifics of the various formatters 1442 # the specifics of the various formatters
1413 self.assertEqual(format(3, ''), '3') 1443 self.assertEqual(format(3, ''), '3')
1414 1444
1415 # Returns some classes to use for various tests. There's 1445 # Returns some classes to use for various tests. There's
1416 # an old-style version, and a new-style version 1446 # an old-style version, and a new-style version
1417 def classes_new(): 1447 def classes_new():
1418 class A(object): 1448 class A(object):
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1557 1587
1558 s = ''.join(set(s)) # unique letters only 1588 s = ''.join(set(s)) # unique letters only
1559 types = [str, set, frozenset, list, tuple, dict.fromkeys] 1589 types = [str, set, frozenset, list, tuple, dict.fromkeys]
1560 for T in types: 1590 for T in types:
1561 self.assertEqual(sorted(s), sorted(T(s))) 1591 self.assertEqual(sorted(s), sorted(T(s)))
1562 1592
1563 def test_baddecorator(self): 1593 def test_baddecorator(self):
1564 data = 'The quick Brown fox Jumped over The lazy Dog'.split() 1594 data = 'The quick Brown fox Jumped over The lazy Dog'.split()
1565 self.assertRaises(TypeError, sorted, data, None, lambda x,y: 0) 1595 self.assertRaises(TypeError, sorted, data, None, lambda x,y: 0)
1566 1596
1597 class TestRecursionLimit(unittest.TestCase):
1598 # Issue #14010
1599 recursionlimit = sys.getrecursionlimit()
1600
1601 def test_filter(self):
1602 it = (0, 1)
1603 for _ in range(self.recursionlimit):
1604 it = filter(bool, it)
1605 with self.assertRaises(RuntimeError):
1606 for _ in it:
1607 pass
1608 del it
1609
1610 def test_map(self):
1611 it = (0, 1)
1612 for _ in range(self.recursionlimit):
1613 it = map(int, it)
1614 with self.assertRaises(RuntimeError):
1615 for _ in it:
1616 pass
1617 del it
1618
1619 def test_zip(self):
1620 it = (0, 1)
1621 for _ in range(self.recursionlimit):
1622 it = zip(it)
1623 with self.assertRaises(RuntimeError):
1624 for _ in it:
1625 pass
1626 del it
1627
1628
1567 def test_main(verbose=None): 1629 def test_main(verbose=None):
1568 test_classes = (BuiltinTest, TestSorted) 1630 test_classes = (BuiltinTest, TestSorted, TestRecursionLimit)
1569 1631
1570 run_unittest(*test_classes) 1632 run_unittest(*test_classes)
1571 1633
1572 # verify reference counting 1634 # verify reference counting
1573 if verbose and hasattr(sys, "gettotalrefcount"): 1635 if verbose and hasattr(sys, "gettotalrefcount"):
1574 import gc 1636 import gc
1575 counts = [None] * 5 1637 counts = [None] * 5
1576 for i in range(len(counts)): 1638 for i in range(len(counts)):
1577 run_unittest(*test_classes) 1639 run_unittest(*test_classes)
1578 gc.collect() 1640 gc.collect()
1579 counts[i] = sys.gettotalrefcount() 1641 counts[i] = sys.gettotalrefcount()
1580 print(counts) 1642 print(counts)
1581 1643
1582 1644
1583 if __name__ == "__main__": 1645 if __name__ == "__main__":
1584 test_main(verbose=True) 1646 test_main(verbose=True)
OLDNEW
« no previous file with comments | « no previous file | Lib/test/test_itertools.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+