Commit 6209032b by Chris Jerdonek

Added Context.__repr__().

parent 35dc5e2b
...@@ -112,6 +112,19 @@ class Context(object): ...@@ -112,6 +112,19 @@ class Context(object):
""" """
self._stack = list(items) self._stack = list(items)
def __repr__(self):
"""
Return a string representation of the instance.
For example--
>>> context = Context({'alpha': 'abc'}, {'numeric': 123})
>>> repr(context)
"Context({'alpha': 'abc'}, {'numeric': 123})"
"""
return "%s%s" % (self.__class__.__name__, tuple(self._stack))
@staticmethod @staticmethod
def create(*context, **kwargs): def create(*context, **kwargs):
""" """
......
...@@ -189,6 +189,26 @@ class ContextTests(TestCase): ...@@ -189,6 +189,26 @@ class ContextTests(TestCase):
""" """
context = Context({}, {}, {}) context = Context({}, {}, {})
def test__repr(self):
context = Context()
self.assertEquals(repr(context), 'Context()')
context = Context({'foo': 'bar'})
self.assertEquals(repr(context), "Context({'foo': 'bar'},)")
context = Context({'foo': 'bar'}, {'abc': 123})
self.assertEquals(repr(context), "Context({'foo': 'bar'}, {'abc': 123})")
def test__str(self):
context = Context()
self.assertEquals(str(context), 'Context()')
context = Context({'foo': 'bar'})
self.assertEquals(str(context), "Context({'foo': 'bar'},)")
context = Context({'foo': 'bar'}, {'abc': 123})
self.assertEquals(str(context), "Context({'foo': 'bar'}, {'abc': 123})")
## Test the static create() method. ## Test the static create() method.
def test_create__dictionary(self): def test_create__dictionary(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment