def test__escape__uses_renderer_escape(self): """ Test that escape uses the renderer's escape function. """ renderer = Renderer() renderer.escape = lambda s: "**" + s engine = renderer._make_render_engine() escape = engine.escape self.assertEquals(escape("foo"), "**foo")
def test__escape__uses_renderer_unicode(self): """ Test that escape uses the renderer's unicode function. """ renderer = Renderer() renderer.unicode = lambda s: s.upper() engine = renderer._make_render_engine() escape = engine.escape self.assertEquals(escape("foo"), "FOO")
def test__literal__handles_unicode(self): """ Test that literal doesn't try to "double decode" unicode. """ renderer = Renderer() renderer.default_encoding = 'ascii' engine = renderer._make_render_engine() literal = engine.literal self.assertEquals(literal(u"foo"), "foo")
def test__literal__uses_renderer_unicode(self): """ Test that literal uses the renderer's unicode function. """ renderer = Renderer() renderer.unicode = lambda s: s.upper() engine = renderer._make_render_engine() literal = engine.literal self.assertEquals(literal("foo"), "FOO")
def test__load_partial__not_found(self): """ Check that load_partial provides a nice message when a template is not found. """ renderer = Renderer() renderer.partials = {} engine = renderer._make_render_engine() load_partial = engine.load_partial try: load_partial("foo") raise Exception("Shouldn't get here") except Exception, err: self.assertEquals(str(err), "Partial not found with name: 'foo'")
def test__escape__has_access_to_original_unicode_subclass(self): """ Test that escape receives strings with the unicode subclass intact. """ renderer = Renderer() renderer.escape = lambda s: type(s).__name__ engine = renderer._make_render_engine() escape = engine.escape class MyUnicode(unicode): pass self.assertEquals(escape("foo"), "unicode") self.assertEquals(escape(u"foo"), "unicode") self.assertEquals(escape(MyUnicode("foo")), "MyUnicode")
def test__literal__returns_unicode(self): """ Test that literal returns unicode (and not a subclass). """ renderer = Renderer() renderer.default_encoding = 'ascii' engine = renderer._make_render_engine() literal = engine.literal self.assertEquals(type(literal("foo")), unicode) class MyUnicode(unicode): pass s = MyUnicode("abc") self.assertEquals(type(s), MyUnicode) self.assertTrue(isinstance(s, unicode)) self.assertEquals(type(literal(s)), unicode)
def test__escape__returns_unicode(self): """ Test that literal returns unicode (and not a subclass). """ renderer = Renderer() renderer.default_encoding = 'ascii' engine = renderer._make_render_engine() escape = engine.escape self.assertEquals(type(escape("foo")), unicode) # Check that literal doesn't preserve unicode subclasses. class MyUnicode(unicode): pass s = MyUnicode("abc") self.assertEquals(type(s), MyUnicode) self.assertTrue(isinstance(s, unicode)) self.assertEquals(type(escape(s)), unicode)
def test__load_partial__returns_unicode(self): """ Check that load_partial returns unicode (and not a subclass). """ class MyUnicode(unicode): pass renderer = Renderer() renderer.default_encoding = 'ascii' renderer.partials = {'str': 'foo', 'subclass': MyUnicode('abc')} engine = renderer._make_render_engine() actual = engine.load_partial('str') self.assertEquals(actual, "foo") self.assertEquals(type(actual), unicode) # Check that unicode subclasses are not preserved. actual = engine.load_partial('subclass') self.assertEquals(actual, "abc") self.assertEquals(type(actual), unicode)