summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_collections.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2010-08-22 07:44:24 (GMT)
committerRaymond Hettinger <python@rcn.com>2010-08-22 07:44:24 (GMT)
commit9117c751488a98810d758f15b3113527beb920ef (patch)
treee75666f723e74149d9cb0fb0d9d4fd6b85678883 /Lib/test/test_collections.py
parenta52bae7521dc97f37416cf7e03036a8467672833 (diff)
downloadcpython-9117c751488a98810d758f15b3113527beb920ef.zip
cpython-9117c751488a98810d758f15b3113527beb920ef.tar.gz
cpython-9117c751488a98810d758f15b3113527beb920ef.tar.bz2
Issue #9214: Fix set operations on KeysView and ItemsView.
Diffstat (limited to 'Lib/test/test_collections.py')
-rw-r--r--Lib/test/test_collections.py27
1 files changed, 26 insertions, 1 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
index 2af94bf..da80baa 100644
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -13,7 +13,7 @@ import sys
from collections import Hashable, Iterable, Iterator
from collections import Sized, Container, Callable
from collections import Set, MutableSet
-from collections import Mapping, MutableMapping
+from collections import Mapping, MutableMapping, KeysView, ItemsView, UserDict
from collections import Sequence, MutableSequence
from collections import ByteString
@@ -548,6 +548,31 @@ class TestCollectionABCs(ABCTestCase):
self.validate_abstract_methods(MutableMapping, '__contains__', '__iter__', '__len__',
'__getitem__', '__setitem__', '__delitem__')
+ def test_MutableMapping_subclass(self):
+ # Test issue 9214
+ mymap = UserDict()
+ mymap['red'] = 5
+ self.assertIsInstance(mymap.keys(), Set)
+ self.assertIsInstance(mymap.keys(), KeysView)
+ self.assertIsInstance(mymap.items(), Set)
+ self.assertIsInstance(mymap.items(), ItemsView)
+
+ mymap = UserDict()
+ mymap['red'] = 5
+ z = mymap.keys() | {'orange'}
+ self.assertIsInstance(z, set)
+ list(z)
+ mymap['blue'] = 7 # Shouldn't affect 'z'
+ self.assertEqual(sorted(z), ['orange', 'red'])
+
+ mymap = UserDict()
+ mymap['red'] = 5
+ z = mymap.items() | {('orange', 3)}
+ self.assertIsInstance(z, set)
+ list(z)
+ mymap['blue'] = 7 # Shouldn't affect 'z'
+ self.assertEqual(sorted(z), [('orange', 3), ('red', 5)])
+
def test_Sequence(self):
for sample in [tuple, list, bytes, str]:
self.assertIsInstance(sample(), Sequence)