Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding simple tests for dot notation

  • Loading branch information...
commit d5df7f1536d50597ff81d665ca885fb9f36f49c6 1 parent 3460b41
Rodrigo Bernardo Pimentel authored
Showing with 19 additions and 0 deletions.
  1. +19 −0 tests/test_simple.py
19 tests/test_simple.py
View
@@ -60,6 +60,25 @@ def test_non_existent_value_renders_blank(self):
template = '{{not_set}} {{blank}}'
self.assertEquals(pystache.Renderer().render(template), ' ')
+ def test_dot_notation_with_dict(self):
+ template = 'Name: {{person.name}}. Age: {{person.details.age}}. Intimate details (should be empty): {{person.details.intimate}}.'
+ renderer = Renderer()
+ context = {'person': {'name': 'Biggles', 'details': {'age': 42}}}
+ actual = renderer.render(template, context)
+ self.assertEquals(actual, 'Name: Biggles. Age: 42. Intimate details (should be empty): .')
+
+ def test_dot_notation_with_user_objects(self):
+ template = 'Name: {{person.name}}. Age: {{person.details.age}}. Intimate details (should be empty): {{person.details.intimate}}.'
+ renderer = Renderer()
+
+ class Person(object):
+ def __init__(self, name, details):
+ self.name = name
+ self.details = details
+
+ context = {'person': Person('Biggles', {'age': 42})}
+ actual = renderer.render(template, context)
+ self.assertEquals(actual, 'Name: Biggles. Age: 42. Intimate details (should be empty): .')
def test_template_partial_extension(self):
"""
Please sign in to comment.
Something went wrong with that request. Please try again.