diff options
author | Raymond Hettinger <python@rcn.com> | 2010-09-03 10:00:50 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2010-09-03 10:00:50 (GMT) |
commit | faf7b7f4ec58a26cc4044dd29c7dd8ebdfb65269 (patch) | |
tree | 4f399ee83fd6d7e060977fc1ff54cc895e7add96 /Lib/test/test_set.py | |
parent | 8844441ae68358c832e04d8b48ba7b035f67d9bf (diff) | |
download | cpython-faf7b7f4ec58a26cc4044dd29c7dd8ebdfb65269.zip cpython-faf7b7f4ec58a26cc4044dd29c7dd8ebdfb65269.tar.gz cpython-faf7b7f4ec58a26cc4044dd29c7dd8ebdfb65269.tar.bz2 |
Issue 8420: Fix obscure set crashers.
Diffstat (limited to 'Lib/test/test_set.py')
-rw-r--r-- | Lib/test/test_set.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py index ff88a34..c9d0466 100644 --- a/Lib/test/test_set.py +++ b/Lib/test/test_set.py @@ -1660,6 +1660,39 @@ class TestVariousIteratorArgs(unittest.TestCase): self.assertRaises(TypeError, getattr(set('january'), methname), N(data)) self.assertRaises(ZeroDivisionError, getattr(set('january'), methname), E(data)) +class bad_eq: + def __eq__(self, other): + if be_bad: + set2.clear() + raise ZeroDivisionError + return self is other + def __hash__(self): + return 0 + +class bad_dict_clear: + def __eq__(self, other): + if be_bad: + dict2.clear() + return self is other + def __hash__(self): + return 0 + +class Test_Weird_Bugs(unittest.TestCase): + def test_8420_set_merge(self): + # This used to segfault + global be_bad, set2, dict2 + be_bad = False + set1 = {bad_eq()} + set2 = {bad_eq() for i in range(75)} + be_bad = True + self.assertRaises(ZeroDivisionError, set1.update, set2) + + be_bad = False + set1 = {bad_dict_clear()} + dict2 = {bad_dict_clear(): None} + be_bad = True + set1.symmetric_difference_update(dict2) + # Application tests (based on David Eppstein's graph recipes ==================================== def powerset(U): @@ -1804,6 +1837,7 @@ def test_main(verbose=None): TestIdentities, TestVariousIteratorArgs, TestGraphs, + Test_Weird_Bugs, ) support.run_unittest(*test_classes) |