summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_collections.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2009-04-01 19:05:50 (GMT)
committerRaymond Hettinger <python@rcn.com>2009-04-01 19:05:50 (GMT)
commit3f10a952f6056b6797e4187bcfa1a97c21d1b3bb (patch)
treefd77e13d51d8e407ecc12a206b67cbb670ee88bc /Lib/test/test_collections.py
parent0759dd66c581a65381412a2ff98dac8edd58ddee (diff)
downloadcpython-3f10a952f6056b6797e4187bcfa1a97c21d1b3bb.zip
cpython-3f10a952f6056b6797e4187bcfa1a97c21d1b3bb.tar.gz
cpython-3f10a952f6056b6797e4187bcfa1a97c21d1b3bb.tar.bz2
Issue #5647: MutableSet.__iand__() no longer mutates self during iteration.
Diffstat (limited to 'Lib/test/test_collections.py')
-rw-r--r--Lib/test/test_collections.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
index 3d00973..e8d72ee 100644
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -327,6 +327,25 @@ class TestOneTrickPonyABCs(ABCTestCase):
B.register(C)
self.failUnless(issubclass(C, B))
+class WithSet(MutableSet):
+
+ def __init__(self, it=()):
+ self.data = set(it)
+
+ def __len__(self):
+ return len(self.data)
+
+ def __iter__(self):
+ return iter(self.data)
+
+ def __contains__(self, item):
+ return item in self.data
+
+ def add(self, item):
+ self.data.add(item)
+
+ def discard(self, item):
+ self.data.discard(item)
class TestCollectionABCs(ABCTestCase):
@@ -363,6 +382,12 @@ class TestCollectionABCs(ABCTestCase):
self.validate_abstract_methods(MutableSet, '__contains__', '__iter__', '__len__',
'add', 'discard')
+ def test_issue_5647(self):
+ # MutableSet.__iand__ mutated the set during iteration
+ s = WithSet('abcd')
+ s &= WithSet('cdef') # This used to fail
+ self.assertEqual(set(s), set('cd'))
+
def test_issue_4920(self):
# MutableSet.pop() method did not work
class MySet(collections.MutableSet):