aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2018-11-20 13:02:14 -0500
committerYury Selivanov <yury@magic.io>2018-11-20 14:25:07 -0500
commit24c575b6eec2abe396ece52460672d26e01ad284 (patch)
treea9f708d3d104f79b8b65648123a1b672ce7d292b /tests
parent4276e0c82cb0c2f7f7858063a2fe8bdd8b4240cf (diff)
downloadimmutables-24c575b6eec2abe396ece52460672d26e01ad284.tar.gz
immutables-24c575b6eec2abe396ece52460672d26e01ad284.zip
Implement mutable mapping API for MapMutation; add after-finalize checks
Diffstat (limited to 'tests')
-rw-r--r--tests/test_map.py79
1 files changed, 77 insertions, 2 deletions
diff --git a/tests/test_map.py b/tests/test_map.py
index bbf0a52..4fc87e3 100644
--- a/tests/test_map.py
+++ b/tests/test_map.py
@@ -992,7 +992,7 @@ class BaseMapTest:
hm2.set('a', 10)
self.assertEqual(hm1, hm2)
- hm2.delete('a')
+ self.assertEqual(hm2.pop('a'), 10)
self.assertNotEqual(hm1, hm2)
def test_map_mut_5(self):
@@ -1099,6 +1099,81 @@ class BaseMapTest:
with self.assertRaises(HashingError):
self.Map(src)
+ def test_map_mut_10(self):
+ key1 = HashKey(123, 'aaa')
+
+ m = self.Map({key1: 123})
+
+ mm = m.mutate()
+ with HashKeyCrasher(error_on_hash=True):
+ with self.assertRaises(HashingError):
+ del mm[key1]
+
+ mm = m.mutate()
+ with HashKeyCrasher(error_on_hash=True):
+ with self.assertRaises(HashingError):
+ mm.pop(key1, None)
+
+ mm = m.mutate()
+ with HashKeyCrasher(error_on_hash=True):
+ with self.assertRaises(HashingError):
+ mm.set(key1, 123)
+
+ def test_map_mut_11(self):
+ m = self.Map({'a': 1, 'b': 2})
+
+ mm = m.mutate()
+ self.assertEqual(mm.pop('a', 1), 1)
+ self.assertEqual(mm.finalize(), self.Map({'b': 2}))
+
+ mm = m.mutate()
+ self.assertEqual(mm.pop('b', 1), 2)
+ self.assertEqual(mm.finalize(), self.Map({'a': 1}))
+
+ mm = m.mutate()
+ self.assertEqual(mm.pop('b', 1), 2)
+ del mm['a']
+ self.assertEqual(mm.finalize(), self.Map())
+
+ def test_map_mut_12(self):
+ m = self.Map({'a': 1, 'b': 2})
+
+ mm = m.mutate()
+ mm.finalize()
+
+ with self.assertRaisesRegex(ValueError, 'has been finalized'):
+ mm.pop('a')
+
+ with self.assertRaisesRegex(ValueError, 'has been finalized'):
+ del mm['a']
+
+ with self.assertRaisesRegex(ValueError, 'has been finalized'):
+ mm.set('a', 'b')
+
+ with self.assertRaisesRegex(ValueError, 'has been finalized'):
+ mm['a'] = 'b'
+
+ def test_map_mut_13(self):
+ key1 = HashKey(123, 'aaa')
+ key2 = HashKey(123, 'aaa')
+
+ m = self.Map({key1: 123})
+
+ mm = m.mutate()
+ with HashKeyCrasher(error_on_eq=True):
+ with self.assertRaises(EqError):
+ del mm[key2]
+
+ mm = m.mutate()
+ with HashKeyCrasher(error_on_eq=True):
+ with self.assertRaises(EqError):
+ mm.pop(key2, None)
+
+ mm = m.mutate()
+ with HashKeyCrasher(error_on_eq=True):
+ with self.assertRaises(EqError):
+ mm.set(key2, 123)
+
def test_map_mut_stress(self):
COLLECTION_SIZE = 7000
TEST_ITERS_EVERY = 647
@@ -1138,7 +1213,7 @@ class BaseMapTest:
break
del d[key]
- hm.delete(key)
+ del hm[key]
self.assertEqual(len(hm), len(d))