diff options
Diffstat (limited to 'Lib/test/test_set.py')
| -rw-r--r-- | Lib/test/test_set.py | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py index f084ebe..7594303 100644 --- a/Lib/test/test_set.py +++ b/Lib/test/test_set.py @@ -362,6 +362,9 @@ class TestJointOps: gc.collect() self.assertTrue(ref() is None, "Cycle was not collected") + def test_free_after_iterating(self): + support.check_free_after_iterating(self, iter, self.thetype) + class TestSet(TestJointOps, unittest.TestCase): thetype = set basetype = set @@ -385,6 +388,21 @@ class TestSet(TestJointOps, unittest.TestCase): t = {1,2,3} self.assertEqual(s, t) + def test_set_literal_insertion_order(self): + # SF Issue #26020 -- Expect left to right insertion + s = {1, 1.0, True} + self.assertEqual(len(s), 1) + stored_value = s.pop() + self.assertEqual(type(stored_value), int) + + def test_set_literal_evaluation_order(self): + # Expect left to right expression evaluation + events = [] + def record(obj): + events.append(obj) + s = {record(1), record(2), record(3)} + self.assertEqual(events, [1, 2, 3]) + def test_hash(self): self.assertRaises(TypeError, hash, self.s) @@ -931,7 +949,7 @@ class TestBasicOpsString(TestBasicOps, unittest.TestCase): class TestBasicOpsBytes(TestBasicOps, unittest.TestCase): def setUp(self): - self.case = "string set" + self.case = "bytes set" self.values = [b"a", b"b", b"c"] self.set = set(self.values) self.dup = set(self.values) @@ -1742,6 +1760,19 @@ class TestWeirdBugs(unittest.TestCase): s.update(range(100)) list(si) + def test_merge_and_mutate(self): + class X: + def __hash__(self): + return hash(0) + def __eq__(self, o): + other.clear() + return False + + other = set() + other = {X() for i in range(10)} + s = {0} + s.update(other) + # Application tests (based on David Eppstein's graph recipes ==================================== def powerset(U): @@ -1820,7 +1851,7 @@ class TestGraphs(unittest.TestCase): # http://en.wikipedia.org/wiki/Cuboctahedron # 8 triangular faces and 6 square faces - # 12 indentical vertices each connecting a triangle and square + # 12 identical vertices each connecting a triangle and square g = cube(3) cuboctahedron = linegraph(g) # V( --> {V1, V2, V3, V4} |
