From ec3d07e305e0d1d4b6369f512b71d92d19ab4add Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Thu, 10 Sep 2020 10:20:12 +0300 Subject: feat(python template): delete items from Context --- templates/python/context.py | 3 +++ templates/python/context_tests.py | 6 ++++++ 2 files changed, 9 insertions(+) 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" -- cgit v1.2.1