Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 3 files changed
  • 0 comments
  • 1 contributor
5  pystache/context.py
@@ -49,10 +49,7 @@ def _get_value(item, key):
49 49
         # are considered objects by the test above.
50 50
         if hasattr(item, key):
51 51
             attr = getattr(item, key)
52  
-            # If there are still parts to process (in a dot-notation key),
53  
-            # we do not automatically invoke the object, even if it's callable.
54  
-            autocall = len(rest) == 0
55  
-            if autocall and _is_callable(attr):
  52
+            if  _is_callable(attr):
56 53
                 value = attr()
57 54
             else:
58 55
                 value =  attr
5  tests/common.py
@@ -64,7 +64,10 @@ class Attachable(object):
64 64
     of the universe
65 65
     """
66 66
     def __init__(self, **kwargs):
  67
+        self.__args__ = kwargs
67 68
         for arg, value in kwargs.iteritems():
68 69
             setattr(self, arg, value)
69 70
 
70  
-
  71
+    def __repr__(self):
  72
+        return "A(%s)" % (", ".join("%s=%s" % (k, v)
  73
+                                    for k, v in self.__args__.iteritems()))
15  tests/test_context.py
@@ -435,14 +435,13 @@ def test_dot_notation__missing_attr_or_key(self):
435 435
     def test_dot_notattion__autocall(self):
436 436
         key = "foo.bar.baz"
437 437
 
438  
-        # When the last element is callable, it should be automatically invoked
  438
+        # When any element in the path is callable, it should be automatically invoked
439 439
         original = Context({"foo": Attachable(bar=Attachable(baz=lambda: "Called!"))})
440 440
         self.assertEquals(original.get(key), "Called!")
441 441
 
442  
-        # An element in the middle of the dotted path should NOT be invoked,
443  
-        # even if it is callable
444  
-        class Callable(Attachable):
445  
-            def __call__(self):
446  
-                return 'Called!'
447  
-        original = Context({"foo": Callable(bar=Callable(baz='Not called!'))})
448  
-        self.assertEquals(original.get(key), "Not called!")
  442
+        class Foo(object):
  443
+            def bar(self):
  444
+                return Attachable(baz='Baz')
  445
+
  446
+        original = Context({"foo": Foo()})
  447
+        self.assertEquals(original.get(key), "Baz")

No commit comments for this range

Something went wrong with that request. Please try again.