aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2018-12-13 12:48:29 -0500
committerYury Selivanov <yury@magic.io>2018-12-13 12:55:50 -0500
commit7642044a0c6dd484e259933fce976b2725f9ac59 (patch)
tree87864a69b3b78beb30a3ec9d4242e82f13b14738 /tests
parent5a9c2fa8131819523403a6b7a92ad0918f1c595d (diff)
downloadimmutables-7642044a0c6dd484e259933fce976b2725f9ac59.tar.gz
immutables-7642044a0c6dd484e259933fce976b2725f9ac59.zip
Add MapMutation.update(); make creating Map from a Map faster; fix bugs
* Add new MapMutation.update() method that behaves like MutableMapping.update() * Make it faster to create a Map() from another Map() -- it's now an O(1) operation. * update() method had a bug that could cause the update Map object to have a wrong number of elements.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_map.py46
1 files changed, 41 insertions, 5 deletions
diff --git a/tests/test_map.py b/tests/test_map.py
index 959e00c..66d07e7 100644
--- a/tests/test_map.py
+++ b/tests/test_map.py
@@ -1089,11 +1089,6 @@ class BaseMapTest:
with self.assertRaises(HashingError):
self.Map(src)
- src = self.Map({key1: 123})
- with HashKeyCrasher(error_on_hash=True):
- with self.assertRaises(HashingError):
- self.Map(src)
-
src = [(1, 2), (key1, 123)]
with HashKeyCrasher(error_on_hash=True):
with self.assertRaises(HashingError):
@@ -1195,6 +1190,47 @@ class BaseMapTest:
self.assertEqual(mm.finish(), self.Map(z=100, b=2))
self.assertEqual(m, self.Map(a=1, b=2))
+ def test_map_mut_16(self):
+ m = self.Map(a=1, b=2)
+ hash(m)
+
+ m2 = self.Map(m)
+ m3 = self.Map(m, c=3)
+
+ self.assertEqual(m, m2)
+ self.assertEqual(len(m), len(m2))
+ self.assertEqual(hash(m), hash(m2))
+
+ self.assertIsNot(m, m2)
+ self.assertEqual(m3, self.Map(a=1, b=2, c=3))
+
+ def test_map_mut_17(self):
+ m = self.Map(a=1)
+ with m.mutate() as mm:
+ with self.assertRaisesRegex(
+ TypeError, 'cannot create Maps from MapMutations'):
+ self.Map(mm)
+
+ def test_map_mut_18(self):
+ m = self.Map(a=1, b=2)
+ with m.mutate() as mm:
+ mm.update(self.Map(x=1), z=2)
+ mm.update(c=3)
+ mm.update({'n': 100, 'a': 20})
+ m2 = mm.finish()
+
+ expected = self.Map(
+ {'b': 2, 'c': 3, 'n': 100, 'z': 2, 'x': 1, 'a': 20})
+
+ self.assertEqual(len(m2), 6)
+ self.assertEqual(m2, expected)
+ self.assertEqual(m, self.Map(a=1, b=2))
+
+ def test_map_mut_19(self):
+ m = self.Map(a=1, b=2)
+ m2 = m.update({'a': 20})
+ self.assertEqual(len(m2), 2)
+
def test_map_mut_stress(self):
COLLECTION_SIZE = 7000
TEST_ITERS_EVERY = 647