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