def bootstrap(self, template, jslibs, css, **kwargs): """ Bootstraps an application template. Returns a cubictemp Template instance. """ kwargs["css"] = css kwargs["jslibs"] = jslibs bootstrap = cubictemp.Template(template) bootstrap = unicode(bootstrap(**kwargs)) return cubictemp.Template(unicode(bootstrap))
def test_unicode(self): s = unicode(cubictemp.Template(u"\ue2e2foo")) assert s == u"\ue2e2foo" s = cubictemp.Template("@!foo!@") assert unicode(s(foo=u"\ue2e2")) s = cubictemp.Template(u""" <!--(for i in uc)--> @!i!@ <!--(end)--> """) assert unicode(s(uc=[u"\ue2e2"]))
def test_complexIterable(self): s = """ <!--(for i in [1, 2, 3, "flibble", range(10)])--> @!i!@ <!--(end)--> """ s = unicode(cubictemp.Template(s)) assert "[0, 1, 2, 3, 4" in s
def test_blockspacing(self): s = """ <!--(block|strip|dummyproc)--> one <!--(end)--> """ t = cubictemp.Template(s, strip=string.strip) assert unicode(t(dummyproc=dummyproc)).strip() == "::one::"
def test_processorchain(self): s = """ <!--(block|strip|dummyproc|dummyproc2)--> one <!--(end)--> """ t = cubictemp.Template(s, strip=string.strip, dummyproc2=dummyproc2) assert unicode(t(dummyproc=dummyproc)).strip() == "**::one::**"
def test_format_execution(self): s = """ <!--(block foo)--> @!bar!@ <!--(end)--> @!foo!@ """ libpry.raises("line 3", unicode, cubictemp.Template(s))
def test_inlineproc(self): s = """ <!--(block | strip | dummyproc)--> one <!--(end)--> """ t = cubictemp.Template(s, strip=string.strip) assert "::one::" in unicode(t(dummyproc=dummyproc))
def test_namespace_follow(self): s = """ <!--(block one)--> one <!--(end)--> @!one!@ """ t = cubictemp.Template(s) assert t().strip() == "one"
def test_lines(self): s = """ :<!--(block foo)--> one :<!--(end)--> """ t = cubictemp.Template(s) s = t() assert ":<!" in unicode(s)
def test_namespace_simplenest(self): s = """ <!--(block one)--> @!two!@ @!three!@ <!--(end)--> @!one(three="bar")!@ """ t = cubictemp.Template(s) assert "foo" in unicode(t(two="foo"))
def test_block_following_whitespace(self): s = """ <!--(block|dummyproc)--> one <!--(end)--> test """ t = cubictemp.Template(s, strip=string.strip) assert "\n\n" in unicode(t(dummyproc=dummyproc))
def test_init(self): c = cubictemp.Template(self.s).block assert len(c) == 4 assert not c[0].txt.strip() assert not c[1].txt.strip() assert c[2].expr == "foo" assert c[3].txt.strip() == "one" assert c.ns["foo"] nest = c.ns["foo"].ns["foo"] assert len(nest) == 1 assert nest[0].iterable == "[1, 2, 3]" assert nest[0][1].expr == "tag"
def test_namespace_follow(self): s = """ <!--(block one)--> one <!--(end)--> @!one!@ <!--(block one)--> two <!--(end)--> @!one!@ """ t = unicode(cubictemp.Template(s)) assert "one" in t assert "two" in t
def test_namespace_nest(self): s = """ <!--(block one)--> foo <!--(end)--> <!--(block one)--> <!--(block two)--> @!one!@ <!--(end)--> @!two!@ <!--(end)--> @!one!@ <!--(block one)--> bar <!--(end)--> @!one!@ """ t = unicode(cubictemp.Template(s)) assert "foo" in t assert "bar" in t
def test_bench(self): t = cubictemp.Template(tmpl) str(t)
def setUp(self): self.s = cubictemp.Template("text")
def test_simple(self): test = "@!1!@" ct = cubictemp.Template(test) assert unicode(ct) == "1"
def test_call(self): s = cubictemp.Template(self.s)(tag="voing") assert "voing" in unicode(s)
def setUp(self): self.s = cubictemp.Template("text") self.t = cubictemp.TemplateError("foo", 0, self.s)
def test_simple2(self): test = "@!a!@" ns = {"a": 1} ct = cubictemp.Template(test, **ns) assert unicode(ct) == "1"
def test_namespace_err(self): s = """ @!one!@ """ t = cubictemp.Template(s) libpry.raises("not defined", unicode, t)