コード例 #1
0
ファイル: test_pyrazor.py プロジェクト: pate/pyRazor
  def testTmpl(self):
    """Tests that the tmpl directive renders correctly"""
    class model:
      pass

    tmpl_file = RenderTests.__writeTemplateToFile("Test")
    try:
      template = '@view.tmpl("' + tmpl_file + '")'
      self.assertEquals("Test", pyrazor.render(template))
    finally:
      os.remove(tmpl_file)

    tmpl_file = RenderTests.__writeTemplateToFile("<head>\n\[email protected]\n</head>")
    try:
      template = '@view.tmpl("' + tmpl_file + '")'
      m = model()
      m.title = "test"
      self.assertEquals("<head>\n\ttest\n</head>", pyrazor.render(template, m))
    finally:
      os.remove(tmpl_file)

    # Tests that we pass the appropriate part of a model
    tmpl_file = RenderTests.__writeTemplateToFile("<head>\n\[email protected]\n</head>")
    try:
      template = '@model.title\[email protected]("' + tmpl_file + '", model.sub)'
      m = model()
      m.title = "Top title"
      m.sub = model()
      m.sub.title = "Sub Title"
      self.assertEquals("Top title\n<head>\n\tSub Title\n</head>", pyrazor.render(template, m))
    finally:
      os.remove(tmpl_file)
コード例 #2
0
 def testMultilineIf(self):
     """Tests that an if statement works"""
     # The renderer will output True\n and False\n due to new line chars.... theres currently no good way around this.
     # Though it's not really a huge issue except when testing for an exact match.
     template = "@if model:\n\tTrue\n@else:\n\tFalse"
     self.assertEquals("True\n", pyrazor.render(template, True))
     self.assertEquals("False", pyrazor.render(template, False))
コード例 #3
0
ファイル: test_pyrazor.py プロジェクト: pate/pyRazor
 def testMultilineIf(self):
   """Tests that an if statement works"""
   # The renderer will output True\n and False\n due to new line chars.... theres currently no good way around this.
   # Though it's not really a huge issue except when testing for an exact match.
   template = "@if model:\n\tTrue\n@else:\n\tFalse"
   self.assertEquals("True\n", pyrazor.render(template, True)) 
   self.assertEquals("False", pyrazor.render(template, False)) 
コード例 #4
0
ファイル: test_pyrazor.py プロジェクト: pate/pyRazor
  def testHtmlEscape(self):
    class test:
      pass

    model = test()
    model.a = "<html>"
    self.assertEquals("<html>", pyrazor.render("@!model.a", model))
    self.assertEquals(cgi.escape("<html>"), pyrazor.render("@model.a", model))
    self.assertEquals("<html>", pyrazor.render("@!(model.a)", model))
    self.assertEquals(cgi.escape("<html>"), pyrazor.render("@(model.a)", model))
コード例 #5
0
    def testSimpleModel(self):
        class test:
            pass

        model = test()
        model.a = 3
        model.b = 5
        self.assertEquals("3", pyrazor.render("@model.a", model))
        self.assertEquals("3 5", pyrazor.render("@model.a @model.b", model))
        self.assertEquals("8", pyrazor.render("@(model.a + model.b)", model))
コード例 #6
0
ファイル: test_pyrazor.py プロジェクト: pate/pyRazor
  def testSimpleModel(self): 
    class test:
      pass

    model = test()
    model.a = 3
    model.b = 5
    self.assertEquals("3", pyrazor.render("@model.a", model))
    self.assertEquals("3 5", pyrazor.render("@model.a @model.b", model))
    self.assertEquals("8", pyrazor.render("@(model.a + model.b)", model))
コード例 #7
0
 def testIgnoreWhitespace(self):
     """Tests that ignoring whitespace will strip all tab/spaces prefix on a line"""
     self.assertEquals(
         "test\ntest", pyrazor.render("test\n\ttest",
                                      ignore_whitespace=True))
     self.assertEquals("test",
                       pyrazor.render("  test", ignore_whitespace=True))
     self.assertEquals("test",
                       pyrazor.render("\t test", ignore_whitespace=True))
     self.assertEquals(
         "test\ntest",
         pyrazor.render("\t test\n\t\ttest", ignore_whitespace=True))
コード例 #8
0
    def testHtmlEscape(self):
        class test:
            pass

        model = test()
        model.a = "<html>"
        self.assertEquals("<html>", pyrazor.render("@!model.a", model))
        self.assertEquals(cgi.escape("<html>"),
                          pyrazor.render("@model.a", model))
        self.assertEquals("<html>", pyrazor.render("@!(model.a)", model))
        self.assertEquals(cgi.escape("<html>"),
                          pyrazor.render("@(model.a)", model))
コード例 #9
0
    def testModelSubclassOf(self):
        class subdict(dict):
            pass

        m = subdict()
        m['test'] = 3
        self.assertEquals("3", pyrazor.render("@model dict\n@model['test']",
                                              m))
コード例 #10
0
    def testHtml(self):
        html = """<html>
  <head>
    <title>Alex</title>
  </head>
  <body>
    <span>Alex</span>
  </body>
</html>"""
        self.assertEquals(html, pyrazor.render(html))
コード例 #11
0
ファイル: test_pyrazor.py プロジェクト: pate/pyRazor
  def testHtml(self):
    html = """<html>
  <head>
    <title>Alex</title>
  </head>
  <body>
    <span>Alex</span>
  </body>
</html>"""
    self.assertEquals(html, pyrazor.render(html))
コード例 #12
0
    def testTmpl(self):
        """Tests that the tmpl directive renders correctly"""
        class model:
            pass

        tmpl_file = RenderTests.__writeTemplateToFile("Test")
        try:
            template = '@view.tmpl("' + tmpl_file + '")'
            self.assertEquals("Test", pyrazor.render(template))
        finally:
            os.remove(tmpl_file)

        tmpl_file = RenderTests.__writeTemplateToFile(
            "<head>\n\[email protected]\n</head>")
        try:
            template = '@view.tmpl("' + tmpl_file + '")'
            m = model()
            m.title = "test"
            self.assertEquals("<head>\n\ttest\n</head>",
                              pyrazor.render(template, m))
        finally:
            os.remove(tmpl_file)

        # Tests that we pass the appropriate part of a model
        tmpl_file = RenderTests.__writeTemplateToFile(
            "<head>\n\[email protected]\n</head>")
        try:
            template = '@model.title\[email protected]("' + tmpl_file + '", model.sub)'
            m = model()
            m.title = "Top title"
            m.sub = model()
            m.sub.title = "Sub Title"
            self.assertEquals("Top title\n<head>\n\tSub Title\n</head>",
                              pyrazor.render(template, m))
        finally:
            os.remove(tmpl_file)
コード例 #13
0
ファイル: test_pyrazor.py プロジェクト: pate/pyRazor
 def testIgnoreMultiline(self):
   """Tests that the @: does not affect output."""
   self.assertEquals("", pyrazor.render("@:\n\ta=3"))
コード例 #14
0
 def testModelInstaceOf(self):
     m = dict()
     m['test'] = 3
     self.assertEquals("3", pyrazor.render("@model dict\n@model['test']",
                                           m))
コード例 #15
0
ファイル: test_pyrazor.py プロジェクト: pate/pyRazor
 def testModelSubclassOf(self):
   class subdict(dict):
     pass
   m = subdict()
   m['test'] = 3
   self.assertEquals("3", pyrazor.render("@model dict\n@model['test']", m))
コード例 #16
0
 def testIgnoreMultiline(self):
     """Tests that the @: does not affect output."""
     self.assertEquals("", pyrazor.render("@:\n\ta=3"))
コード例 #17
0
 def testSimple(self):
     """Tests a simple rendering case."""
     template = "test"
     self.assertEquals(template, pyrazor.render(template))
コード例 #18
0
ファイル: test_pyrazor.py プロジェクト: pate/pyRazor
 def testModelInstaceOf(self):
   m = dict()
   m['test'] = 3
   self.assertEquals("3", pyrazor.render("@model dict\n@model['test']", m))
コード例 #19
0
 def testCommentIgnored(self):
     self.assertEquals("<html></html>",
                       pyrazor.render("<html>@# Comment! #@</html>"))
     self.assertEquals(
         "<html>\n</html>",
         pyrazor.render("<html>\n@#A whole line is commented!\n</html>"))
コード例 #20
0
ファイル: test_pyrazor.py プロジェクト: pate/pyRazor
 def testHelperFunction(self):
   self.assertEquals("viewtext\n<s>helper</s>\nviewtext", pyrazor.render("@helper test(name):\n\t<s>@name</s>\nviewtext\n@test('helper')\nviewtext"))
コード例 #21
0
ファイル: test_pyrazor.py プロジェクト: pate/pyRazor
 def testCommentIgnored(self):
   self.assertEquals("<html></html>", pyrazor.render("<html>@# Comment! #@</html>"))
   self.assertEquals("<html>\n</html>", pyrazor.render("<html>\n@#A whole line is commented!\n</html>"))
コード例 #22
0
ファイル: test_pyrazor.py プロジェクト: pate/pyRazor
 def testIgnoreWhitespace(self):
   """Tests that ignoring whitespace will strip all tab/spaces prefix on a line"""
   self.assertEquals("test\ntest", pyrazor.render("test\n\ttest", ignore_whitespace=True))
   self.assertEquals("test", pyrazor.render("  test", ignore_whitespace=True))
   self.assertEquals("test", pyrazor.render("\t test", ignore_whitespace=True))
   self.assertEquals("test\ntest", pyrazor.render("\t test\n\t\ttest", ignore_whitespace=True))
コード例 #23
0
 def testHelperFunction(self):
     self.assertEquals(
         "viewtext\n<s>helper</s>\nviewtext",
         pyrazor.render(
             "@helper test(name):\n\t<s>@name</s>\nviewtext\n@test('helper')\nviewtext"
         ))
コード例 #24
0
ファイル: test_pyrazor.py プロジェクト: pate/pyRazor
 def testSimple(self):
   """Tests a simple rendering case."""
   template = "test"
   self.assertEquals(template, pyrazor.render(template))