1from mako import compat 2from mako.ext.turbogears import TGPlugin 3from test import template_base 4from test import TemplateTest 5from test.util import result_lines 6 7tl = TGPlugin(options=dict(directories=[template_base]), extension="html") 8 9 10class TestTGPlugin(TemplateTest): 11 def test_basic(self): 12 t = tl.load_template("/index.html") 13 assert result_lines(t.render()) == ["this is index"] 14 15 def test_subdir(self): 16 t = tl.load_template("/subdir/index.html") 17 assert result_lines(t.render()) == [ 18 "this is sub index", 19 "this is include 2", 20 ] 21 22 assert ( 23 tl.load_template("/subdir/index.html").module_id 24 == "_subdir_index_html" 25 ) 26 27 def test_basic_dot(self): 28 t = tl.load_template("index") 29 assert result_lines(t.render()) == ["this is index"] 30 31 def test_subdir_dot(self): 32 t = tl.load_template("subdir.index") 33 assert result_lines(t.render()) == [ 34 "this is sub index", 35 "this is include 2", 36 ] 37 38 assert ( 39 tl.load_template("subdir.index").module_id == "_subdir_index_html" 40 ) 41 42 def test_string(self): 43 t = tl.load_template("foo", "hello world") 44 assert t.render() == "hello world" 45 46 def test_render(self): 47 assert result_lines(tl.render({}, template="/index.html")) == [ 48 "this is index" 49 ] 50 assert result_lines( 51 tl.render({}, template=compat.u("/index.html")) 52 ) == ["this is index"] 53