diff options
author | Yury Selivanov <yury@magic.io> | 2018-11-20 13:15:08 -0500 |
---|---|---|
committer | Yury Selivanov <yury@magic.io> | 2018-11-20 14:25:07 -0500 |
commit | 2a14bc7bb3e523d74c9abe5246303976c013d91a (patch) | |
tree | 050b86c11521580d44af1d8d09132467001f2e85 /tests/test_map.py | |
parent | 24c575b6eec2abe396ece52460672d26e01ad284 (diff) | |
download | immutables-2a14bc7bb3e523d74c9abe5246303976c013d91a.tar.gz immutables-2a14bc7bb3e523d74c9abe5246303976c013d91a.zip |
Make MapMutation a context manager
Diffstat (limited to 'tests/test_map.py')
-rw-r--r-- | tests/test_map.py | 21 |
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 |