Example #1
0
 def test_if_with_logicChain(self):       
     text = """{if not((a1 and (a1 > a1) and a1) xor (b1 > foo()))}привет{else}пока{/if}"""
     template = Template(text)
     
     a = template.render(Context(a1=1,b1=1,foo=foo))
     self.assertEqual(a, "привет")        
     a = template.render(Context(a1=1,b1=0,foo=foo))
     self.assertEqual(a, "пока") 
Example #2
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, "привет")
Example #3
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'])
Example #4
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], "перемешанный")
Example #5
0
 def test_comment(self):
     text = """{#'Комментарий'}"""
     template = Template(text)
     a = template.render()
     self.assertEquals(a, "")    
Example #6
0
 def test_block(self):
     text = """{block: name}привет{/block}"""
     template = Template(text)
     a = template.render()
     self.assertEqual(a, "привет")
Example #7
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")
Example #8
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)))
Example #9
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")