def testSetMacro(self): self.assertEqual(moody.render("{% set 'foo' as test %}{{test}}"), "foo") self.assertEqual( moody.render( "{% set 'foo', 'bar', as test1, test2 %}{{test1}}{{test2}}"), "foobar") self.assertEqual(moody.render("{% set 'foo', as test1, %}{{test1}}"), "foo") self.assertRaises(TemplateRenderError, lambda: moody.render("{% set 'foo', as foo, bar %}")) self.assertRaises( TemplateRenderError, lambda: moody.render("{% set 'foo', 'bar' as bar, %}"))
def testCommentTag(self): self.assertEqual(moody.render("{# A comment. #}"), "") self.assertEqual(moody.render("{# Multi\nLine\nComment #}"), "")
def testImportMacro(self): self.assertEqual( moody.render("{% from operator import add %}{{add(1,1)}}"), "2") self.assertEqual( moody.render("{% import operator %}{{operator.add(1,1)}}"), "2")
def testStringTag(self): self.assertEqual(moody.render("Hello world"), "Hello world")
def testExpressionTag(self): self.assertEqual(moody.render("{{'Hello world'}}"), "Hello world") self.assertEqual(moody.render("{{('Hello '\n'world')}}"), "Hello world")
def testImportMacro(self): self.assertEqual(moody.render("{% from operator import add %}{{add(1,1)}}"), "2") self.assertEqual(moody.render("{% import operator %}{{operator.add(1,1)}}"), "2")
def testSetMacro(self): self.assertEqual(moody.render("{% set 'foo' as test %}{{test}}"), "foo") self.assertEqual(moody.render("{% set 'foo', 'bar', as test1, test2 %}{{test1}}{{test2}}"), "foobar") self.assertEqual(moody.render("{% set 'foo', as test1, %}{{test1}}"), "foo") self.assertRaises(TemplateRenderError, lambda: moody.render("{% set 'foo', as foo, bar %}")) self.assertRaises(TemplateRenderError, lambda: moody.render("{% set 'foo', 'bar' as bar, %}"))