summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_set.py34
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)