summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-09-10 10:20:12 +0300
committerLars Wirzenius <liw@liw.fi>2020-09-10 10:20:12 +0300
commitec3d07e305e0d1d4b6369f512b71d92d19ab4add (patch)
treebcf2012c9e5284f03bc9b6d9e41484e4edd33fb3
parent5cf964d1a635c9c4a6aa0124ee4e23656dc9bf5e (diff)
downloadsubplot-ec3d07e305e0d1d4b6369f512b71d92d19ab4add.tar.gz
feat(python template): delete items from Context
-rw-r--r--templates/python/context.py3
-rw-r--r--templates/python/context_tests.py6
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"