Commit 743ed3c2 by Chris Jerdonek

The "ComplexView" tests no longer depend on pystache.View.

parent a6064355
<h1>{{ header }}</h1>{{#list}}<ul>{{#item}}{{# current }}<li><strong>{{name}}</strong></li>{{/ current }}{{#link}}<li><a href="{{url}}">{{name}}</a></li>{{/link}}{{/item}}</ul>{{/list}}{{#empty}}<p>The list is empty.</p>{{/empty}}
\ No newline at end of file
<h1>{{ header }}</h1>
{{#list}}
<ul>
{{#item}}{{# current }}<li><strong>{{name}}</strong></li>
{{/ current }}{{#link}}<li><a href="{{url}}">{{name}}</a></li>
{{/link}}{{/item}}</ul>{{/list}}{{#empty}}<p>The list is empty.</p>{{/empty}}
\ No newline at end of file
import pystache
class ComplexView(pystache.View):
class ComplexView(object):
template_path = 'examples'
def header(self):
......@@ -18,6 +16,6 @@ class ComplexView(pystache.View):
def empty(self):
return len(self.item()) == 0
def empty_list(self):
return [];
......@@ -11,7 +11,7 @@ from examples.delimiters import Delimiters
from examples.unicode_output import UnicodeOutput
from examples.unicode_input import UnicodeInput
from examples.nested_context import NestedContext
from pystache.renderer import Renderer
from pystache import Renderer
from tests.common import assert_strings
......
......@@ -19,12 +19,14 @@ class TestSimple(unittest.TestCase):
self.assertEquals(view.render(), "one and foo and two")
def test_looping_and_negation_context(self):
view = ComplexView()
view.template = '{{#item}}{{header}}: {{name}} {{/item}}{{^item}} Shouldnt see me{{/item}}'
self.assertEquals(view.render(), "Colors: red Colors: green Colors: blue ")
template = '{{#item}}{{header}}: {{name}} {{/item}}{{^item}} Shouldnt see me{{/item}}'
context = ComplexView()
renderer = Renderer()
expected = renderer.render(template, context)
self.assertEquals(expected, "Colors: red Colors: green Colors: blue ")
def test_empty_context(self):
view = ComplexView()
template = '{{#empty_list}}Shouldnt see me {{/empty_list}}{{^empty_list}}Should see me{{/empty_list}}'
self.assertEquals(pystache.Renderer().render(template), "Should see me")
......
......@@ -12,6 +12,7 @@ from examples.simple import Simple
from examples.complex_view import ComplexView
from examples.lambdas import Lambdas
from examples.inverted import Inverted, InvertedLists
from pystache import Renderer
from pystache.reader import Reader
from pystache.view import View
from pystache.view import Locator as ViewLocator
......@@ -78,8 +79,15 @@ class ViewTestCase(unittest.TestCase):
self.assertEquals(view.render(), "Hi Chris!")
def test_complex(self):
self.assertEquals(ComplexView().render(),
"""<h1>Colors</h1><ul><li><strong>red</strong></li><li><a href="#Green">green</a></li><li><a href="#Blue">blue</a></li></ul>""")
renderer = Renderer()
expected = renderer.render(ComplexView())
self.assertEquals(expected, """\
<h1>Colors</h1>
<ul>
<li><strong>red</strong></li>
<li><a href="#Green">green</a></li>
<li><a href="#Blue">blue</a></li>
</ul>""")
def test_higher_order_replace(self):
view = Lambdas()
......
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