Testing that all elements in a dot-notation path are called (if applicable).…

Testing that all elements in a dot-notation path are called (if applicable). Better repr for Attachable test class.
parent f1d22a44
......@@ -64,7 +64,10 @@ class Attachable(object):
of the universe
"""
def __init__(self, **kwargs):
self.__args__ = kwargs
for arg, value in kwargs.iteritems():
setattr(self, arg, value)
def __repr__(self):
return "A(%s)" % (", ".join("%s=%s" % (k, v)
for k, v in self.__args__.iteritems()))
......@@ -435,14 +435,13 @@ class ContextTests(unittest.TestCase, AssertIsMixin):
def test_dot_notattion__autocall(self):
key = "foo.bar.baz"
# When the last element is callable, it should be automatically invoked
# When any element in the path is callable, it should be automatically invoked
original = Context({"foo": Attachable(bar=Attachable(baz=lambda: "Called!"))})
self.assertEquals(original.get(key), "Called!")
# An element in the middle of the dotted path should NOT be invoked,
# even if it is callable
class Callable(Attachable):
def __call__(self):
return 'Called!'
original = Context({"foo": Callable(bar=Callable(baz='Not called!'))})
self.assertEquals(original.get(key), "Not called!")
class Foo(object):
def bar(self):
return Attachable(baz='Baz')
original = Context({"foo": Foo()})
self.assertEquals(original.get(key), "Baz")
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