summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2018-11-19 22:02:25 -0500
committerYury Selivanov <yury@magic.io>2018-11-20 14:25:07 -0500
commita9dc2d83794a9cada687f6b92609fe6ef16c2bb9 (patch)
tree0d0eb43f576d9326f089254373569e0dbed8d3f9 /tests
parent666613d4a5400fd1ce0267a0bcf9cd70afae7392 (diff)
downloadimmutables-a9dc2d83794a9cada687f6b92609fe6ef16c2bb9.tar.gz
immutables-a9dc2d83794a9cada687f6b92609fe6ef16c2bb9.zip
Fix .keys() and other views to support being iterated more than once
Diffstat (limited to 'tests')
-rw-r--r--tests/test_map.py28
1 files changed, 23 insertions, 5 deletions
diff --git a/tests/test_map.py b/tests/test_map.py
index afa2e2e..13c6cb1 100644
--- a/tests/test_map.py
+++ b/tests/test_map.py
@@ -637,6 +637,17 @@ class BaseMapTest:
set(list(it)),
{(A, 'a'), (B, 'b'), (C, 'c'), (D, 'd'), (E, 'e'), (F, 'f')})
+ def test_map_items_3(self):
+ h = self.Map()
+ self.assertEqual(len(h.items()), 0)
+ self.assertEqual(list(h.items()), [])
+
+ def test_map_items_4(self):
+ h = self.Map(a=1, b=2, c=3)
+ k = h.items()
+ self.assertEqual(set(k), {('a', 1), ('b', 2), ('c', 3)})
+ self.assertEqual(set(k), {('a', 1), ('b', 2), ('c', 3)})
+
def test_map_keys_1(self):
A = HashKey(100, 'A')
B = HashKey(101, 'B')
@@ -656,6 +667,12 @@ class BaseMapTest:
self.assertEqual(set(list(h.keys())), {A, B, C, D, E, F})
self.assertEqual(set(list(h)), {A, B, C, D, E, F})
+ def test_map_keys_2(self):
+ h = self.Map(a=1, b=2, c=3)
+ k = h.keys()
+ self.assertEqual(set(k), {'a', 'b', 'c'})
+ self.assertEqual(set(k), {'a', 'b', 'c'})
+
def test_map_values_1(self):
A = HashKey(100, 'A')
B = HashKey(101, 'B')
@@ -674,10 +691,11 @@ class BaseMapTest:
self.assertEqual(set(list(h.values())), {'a', 'b', 'c', 'd', 'e', 'f'})
- def test_map_items_3(self):
- h = self.Map()
- self.assertEqual(len(h.items()), 0)
- self.assertEqual(list(h.items()), [])
+ def test_map_values_2(self):
+ h = self.Map(a=1, b=2, c=3)
+ k = h.values()
+ self.assertEqual(set(k), {1, 2, 3})
+ self.assertEqual(set(k), {1, 2, 3})
def test_map_eq_1(self):
A = HashKey(100, 'A')
@@ -776,7 +794,7 @@ class BaseMapTest:
h = h.set(A, h)
ref = weakref.ref(h)
- hi = h.items()
+ hi = iter(h.items())
next(hi)
del h, hi