diff options
author | Lars Wirzenius <liw@liw.fi> | 2020-09-10 10:28:33 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2020-09-10 10:37:44 +0300 |
commit | a06c0e0f255358bf74e53aeaa4e9aa308e0a5f99 (patch) | |
tree | 9f7501bb2d947a8bf1efb358ddb542ccd63f2c9c /templates | |
parent | 1b6ea85c9b8425ca9dc553fb70ae3b161e877304 (diff) | |
download | subplot-a06c0e0f255358bf74e53aeaa4e9aa308e0a5f99.tar.gz |
feat(python template): repr(Context)
Diffstat (limited to 'templates')
-rw-r--r-- | templates/python/context.py | 3 | ||||
-rw-r--r-- | templates/python/context_tests.py | 10 |
2 files changed, 13 insertions, 0 deletions
diff --git a/templates/python/context.py b/templates/python/context.py index df86b02..8e89195 100644 --- a/templates/python/context.py +++ b/templates/python/context.py @@ -24,3 +24,6 @@ class Context: def __delitem__(self, key): del self._vars[key] + + def __repr__(self): + return repr(self._vars) diff --git a/templates/python/context_tests.py b/templates/python/context_tests.py index 24d8f51..c358f6e 100644 --- a/templates/python/context_tests.py +++ b/templates/python/context_tests.py @@ -41,5 +41,15 @@ class ContextTests(unittest.TestCase): ctx["foo"] = "bar" self.assertEqual(ctx.get("foo", "yo"), "bar") + def test_reprs_itself_when_empty(self): + ctx = Context() + self.assertFalse("foo" in repr(ctx)) + + def test_reprs_itself_when_not_empty(self): + ctx = Context() + ctx["foo"] = "bar" + self.assertTrue("foo" in repr(ctx)) + self.assertTrue("bar" in repr(ctx)) + unittest.main() |