def test_load_template_from_string(self): plugin = MarkupTemplateEnginePlugin() tmpl = plugin.load_template(None, template_string="""<p> $message </p>""") self.assertEqual(None, tmpl.filename) assert isinstance(tmpl, MarkupTemplate)
def test_load_template_from_string(self): plugin = MarkupTemplateEnginePlugin() tmpl = plugin.load_template(None, template_string="""<p> $message </p>""") self.assertEqual(None, tmpl.filename) assert isinstance(tmpl, MarkupTemplate)
def test_helper_functions(self): plugin = MarkupTemplateEnginePlugin() tmpl = plugin.load_template(PACKAGE + '.templates.functions') output = plugin.render({'snippet': u'<b>Foo</b>'}, template=tmpl) self.assertEqual("""<div> False bar <b>Foo</b> <b>Foo</b> </div>""", output)
def test_helper_functions(self): plugin = MarkupTemplateEnginePlugin() tmpl = plugin.load_template(PACKAGE + '.templates.functions') output = plugin.render({'snippet': '<b>Foo</b>'}, template=tmpl) self.assertEqual("""<div> False bar <b>Foo</b> <b>Foo</b> </div>""", output)
def test_render(self): plugin = MarkupTemplateEnginePlugin() tmpl = plugin.load_template(PACKAGE + '.templates.test') output = plugin.render({'message': 'Hello'}, template=tmpl) self.assertEqual("""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="en"> <head> <title>Test</title> </head> <body> <h1>Test</h1> <p>Hello</p> </body> </html>""", output)
def test_render(self): plugin = MarkupTemplateEnginePlugin() tmpl = plugin.load_template(PACKAGE + '.templates.test') output = plugin.render({'message': 'Hello'}, template=tmpl) self.assertEqual("""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="en"> <head> <title>Test</title> </head> <body> <h1>Test</h1> <p>Hello</p> </body> </html>""", output)
def test_render_fragment_with_doctype(self): plugin = MarkupTemplateEnginePlugin(options={ 'genshi.default_doctype': 'html-strict', }) tmpl = plugin.load_template(PACKAGE + '.templates.test_no_doctype') output = plugin.render({'message': 'Hello'}, template=tmpl, fragment=True) self.assertEqual("""<html lang="en"> <head> <title>Test</title> </head> <body> <h1>Test</h1> <p>Hello</p> </body> </html>""", output)
def test_render_with_doctype(self): plugin = MarkupTemplateEnginePlugin(options={ 'genshi.default_doctype': 'html-strict', }) tmpl = plugin.load_template(PACKAGE + '.templates.test') output = plugin.render({'message': 'Hello'}, template=tmpl) self.assertEqual("""<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <title>Test</title> </head> <body> <h1>Test</h1> <p>Hello</p> </body> </html>""", output)
def test_render_fragment_with_doctype(self): plugin = MarkupTemplateEnginePlugin(options={ 'genshi.default_doctype': 'html-strict', }) tmpl = plugin.load_template(PACKAGE + '.templates.test_no_doctype') output = plugin.render({'message': 'Hello'}, template=tmpl, fragment=True) self.assertEqual("""<html lang="en"> <head> <title>Test</title> </head> <body> <h1>Test</h1> <p>Hello</p> </body> </html>""", output)
def test_render_with_doctype(self): plugin = MarkupTemplateEnginePlugin(options={ 'genshi.default_doctype': 'html-strict', }) tmpl = plugin.load_template(PACKAGE + '.templates.test') output = plugin.render({'message': 'Hello'}, template=tmpl) self.assertEqual("""<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <title>Test</title> </head> <body> <h1>Test</h1> <p>Hello</p> </body> </html>""", output)
def test_transform_with_load(self): plugin = MarkupTemplateEnginePlugin() tmpl = plugin.load_template(PACKAGE + '.templates.test') stream = plugin.transform({'message': 'Hello'}, tmpl) assert isinstance(stream, Stream)
def test_load_template_from_file(self): plugin = MarkupTemplateEnginePlugin() tmpl = plugin.load_template(PACKAGE + '.templates.test') self.assertEqual('test.html', os.path.basename(tmpl.filename)) assert isinstance(tmpl, MarkupTemplate)
def test_transform_with_load(self): plugin = MarkupTemplateEnginePlugin() tmpl = plugin.load_template(PACKAGE + '.templates.test') stream = plugin.transform({'message': 'Hello'}, tmpl) assert isinstance(stream, Stream)
def test_load_template_from_file(self): plugin = MarkupTemplateEnginePlugin() tmpl = plugin.load_template(PACKAGE + '.templates.test') self.assertEqual('test.html', os.path.basename(tmpl.filename)) assert isinstance(tmpl, MarkupTemplate)