summaryrefslogtreecommitdiff
path: root/templates
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-09-10 10:13:32 +0300
committerLars Wirzenius <liw@liw.fi>2020-09-10 10:13:32 +0300
commit017de1442c02403cf30f2a9bc5c6c5cc28331eee (patch)
tree00af0a77d3ccbabcce72709754d5aedcbfb50757 /templates
parent04d23939695d903d57bc72d7c3921b087d8f47d9 (diff)
downloadsubplot-017de1442c02403cf30f2a9bc5c6c5cc28331eee.tar.gz
feat(python template): add "foo in ctx" support
Diffstat (limited to 'templates')
-rw-r--r--templates/python/context.py3
-rw-r--r--templates/python/context_tests.py9
2 files changed, 12 insertions, 0 deletions
diff --git a/templates/python/context.py b/templates/python/context.py
index 8d9894f..9bb8056 100644
--- a/templates/python/context.py
+++ b/templates/python/context.py
@@ -18,3 +18,6 @@ class Context:
def __setitem__(self, key, value):
logging.info("Context: {}={!r}".format(key, value))
self._vars[key] = value
+
+ def __contains__(self, key):
+ return key in self._vars
diff --git a/templates/python/context_tests.py b/templates/python/context_tests.py
index fc99af5..9db6bd0 100644
--- a/templates/python/context_tests.py
+++ b/templates/python/context_tests.py
@@ -13,6 +13,15 @@ class ContextTests(unittest.TestCase):
ctx["foo"] = "bar"
self.assertEqual(ctx["foo"], "bar")
+ def test_does_not_contain_item(self):
+ ctx = Context()
+ self.assertFalse("foo" in ctx)
+
+ def test_contains_item(self):
+ ctx = Context()
+ ctx["foo"] = "bar"
+ self.assertTrue("foo" in ctx)
+
def test_get_returns_default_if_item_does_not_exist(self):
ctx = Context()
self.assertEqual(ctx.get("foo"), None)