diff options
author | Lars Wirzenius <liw@liw.fi> | 2020-09-10 10:20:12 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2020-09-10 10:20:12 +0300 |
commit | ec3d07e305e0d1d4b6369f512b71d92d19ab4add (patch) | |
tree | bcf2012c9e5284f03bc9b6d9e41484e4edd33fb3 | |
parent | 5cf964d1a635c9c4a6aa0124ee4e23656dc9bf5e (diff) | |
download | subplot-ec3d07e305e0d1d4b6369f512b71d92d19ab4add.tar.gz |
feat(python template): delete items from Context
-rw-r--r-- | templates/python/context.py | 3 | ||||
-rw-r--r-- | templates/python/context_tests.py | 6 |
2 files changed, 9 insertions, 0 deletions
diff --git a/templates/python/context.py b/templates/python/context.py index 9bb8056..df86b02 100644 --- a/templates/python/context.py +++ b/templates/python/context.py @@ -21,3 +21,6 @@ class Context: def __contains__(self, key): return key in self._vars + + def __delitem__(self, key): + del self._vars[key] diff --git a/templates/python/context_tests.py b/templates/python/context_tests.py index 9db6bd0..24d8f51 100644 --- a/templates/python/context_tests.py +++ b/templates/python/context_tests.py @@ -17,6 +17,12 @@ class ContextTests(unittest.TestCase): ctx = Context() self.assertFalse("foo" in ctx) + def test_no_longer_contains_item(self): + ctx = Context() + ctx["foo"] = "bar" + del ctx["foo"] + self.assertFalse("foo" in ctx) + def test_contains_item(self): ctx = Context() ctx["foo"] = "bar" |