aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2018-11-20 13:15:08 -0500
committerYury Selivanov <yury@magic.io>2018-11-20 14:25:07 -0500
commit2a14bc7bb3e523d74c9abe5246303976c013d91a (patch)
tree050b86c11521580d44af1d8d09132467001f2e85 /tests
parent24c575b6eec2abe396ece52460672d26e01ad284 (diff)
downloadimmutables-2a14bc7bb3e523d74c9abe5246303976c013d91a.tar.gz
immutables-2a14bc7bb3e523d74c9abe5246303976c013d91a.zip
Make MapMutation a context manager
Diffstat (limited to 'tests')
-rw-r--r--tests/test_map.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/test_map.py b/tests/test_map.py
index 4fc87e3..d3b11fb 100644
--- a/tests/test_map.py
+++ b/tests/test_map.py
@@ -1174,6 +1174,27 @@ class BaseMapTest:
with self.assertRaises(EqError):
mm.set(key2, 123)
+ def test_map_mut_14(self):
+ m = self.Map(a=1, b=2)
+
+ with m.mutate() as mm:
+ mm['z'] = 100
+ del mm['a']
+
+ self.assertEqual(mm.finalize(), self.Map(z=100, b=2))
+
+ def test_map_mut_15(self):
+ m = self.Map(a=1, b=2)
+
+ with self.assertRaises(ZeroDivisionError):
+ with m.mutate() as mm:
+ mm['z'] = 100
+ del mm['a']
+ 1 / 0
+
+ self.assertEqual(mm.finalize(), self.Map(z=100, b=2))
+ self.assertEqual(m, self.Map(a=1, b=2))
+
def test_map_mut_stress(self):
COLLECTION_SIZE = 7000
TEST_ITERS_EVERY = 647