Ejemplo n.º 1
0
 def test_if(self):       
     text = """{if angry < 5}привет{else}пока{/if}"""
     template = Template(text)
     
     a = template.render(Context(angry=10))
     self.assertEqual(a, "пока")
     
     a = template.render(Context(angry=3))
     self.assertEqual(a, "привет")
Ejemplo n.º 2
0
 def test_strange_cycle_behaviour(self):
     text = """
     {for x in range(10)}
         {if x > 1} [x] {else} x {/if}
     {/for}
     """
     template = Template(text)
     a = template.render(Context(range=range))
     self.assertEqual(a.strip().split(),
         ['x', 'x', '2', '3', '4', '5', '6', '7', '8', '9'])
Ejemplo n.º 3
0
 def test_mod(self):
     text = """
     {crazy+}перемешанный{crazy-} нормальный {upper+}большой_нормальный{/upper} {/crazy}перемешанный{/crazy}"""
     template = Template(text)
     a = template.render()
     arr = a.split()
     self.assertNotEqual(arr[0], "перемешанный")
     self.assertEqual(arr[1], "нормальный")
     self.assertEqual(arr[2], "большой_нормальный".upper())
     self.assertNotEqual(arr[3], "перемешанный")
Ejemplo n.º 4
0
 def test_comment(self):
     text = """{#'Комментарий'}"""
     template = Template(text)
     a = template.render()
     self.assertEquals(a, "")
Ejemplo n.º 5
0
 def test_block(self):
     text = """{block: name}привет{/block}"""
     template = Template(text)
     a = template.render()
     self.assertEqual(a, "привет")
Ejemplo n.º 6
0
 def test_for_many_val(self):
     text = """{for var1, var2 in test}[var1]+[var2] {/for}"""
     template = Template(text)
     
     a = template.render(Context(test=((1, 2), (2, 3))))
     self.assertEqual(a.strip(), "1+2 2+3")
Ejemplo n.º 7
0
 def test_for(self):
     text = """{for value in range(10)}[value] {/for}"""
     template = Template(text)
     
     a = template.render(Context(range=range))
     self.assertEqual(list(map(int, a.split())), list(range(10)))
Ejemplo n.º 8
0
 def test_chain(self):       
     text = """text me [name > lower()] [name > upper()] [name]"""
     template = Template(text)
     
     a = template.render(Context(name="Avatar"))
     self.assertEqual(a, "text me avatar AVATAR Avatar")