Пример #1
0
 def setUp(self):
     p0 = ir.TemplateNode(
         defs=[
             ir.DefNode(
                 '__main__()',
                 ir.TextNode('Parent 0'))])
     p1 = ir.TemplateNode(
         defs=[
             ir.DefNode(
                 '__main__()',
                 ir.TextNode('Parent 1'))])
     child = ir.TemplateNode(
         defs=[
             ir.DefNode(
                 '__main__()',
                 ir.IfNode(
                     'p==0',
                     ir.ExtendNode('parent0.txt')),
                 ir.ElseNode(
                     ir.ExtendNode('parent1.txt')))])
     loader = kajiki.loader.MockLoader({
         'parent0.txt': kajiki.template.from_ir(p0),
         'parent1.txt': kajiki.template.from_ir(p1),
         'child.txt': kajiki.template.from_ir(child)})
     self.loader = loader
     self.tpl = loader.import_('child.txt')
Пример #2
0
 def setUp(self):
     lib = ir.TemplateNode(
         defs=[ir.DefNode(
               'evenness(n)',
               ir.IfNode(
                   'n % 2 == 0',
                   ir.TextNode('even')),
               ir.ElseNode(
               ir.TextNode('odd'))),
               ir.DefNode(
               'half_evenness(n)',
               ir.TextNode(' half of '),
               ir.ExprNode('n'),
               ir.TextNode(' is '),
               ir.ExprNode('evenness(n/2)'))])
     tpl = ir.TemplateNode(
         defs=[ir.DefNode(
               '__main__()',
               ir.ImportNode(
                   'lib.txt',
                   'simple_function'),
               ir.ForNode(
               'i in range(4)',
               ir.ExprNode('i'),
               ir.TextNode(' is '),
               ir.ExprNode('simple_function.evenness(i)'),
               ir.ExprNode('simple_function.half_evenness(i)'),
               ir.TextNode('\n')))])
     loader = kajiki.loader.MockLoader({
         'lib.txt': kajiki.template.from_ir(lib),
         'tpl.txt': kajiki.template.from_ir(tpl)})
     self.tpl = loader.import_('tpl.txt')
Пример #3
0
 def setUp(self):
     self.tpl = ir.TemplateNode(
         defs=[ir.DefNode(
               '__main__()',
               ir.ForNode(
                   'i in range(2)',
                   ir.ExprNode('i'),
                   ir.TextNode(' is '),
                   ir.SwitchNode(
                       'i % 2',
                       ir.CaseNode(
                           '0',
                           ir.TextNode('even\n')),
                       ir.ElseNode(
                           ir.TextNode('odd\n')))))])
Пример #4
0
 def setUp(self):
     self.tpl = ir.TemplateNode(defs=[
         ir.DefNode(
             "__main__()",
             ir.ForNode(
                 "i in range(2)",
                 ir.ExprNode("i"),
                 ir.TextNode(" is "),
                 ir.SwitchNode(
                     "i % 2",
                     ir.CaseNode("0", ir.TextNode("even\n")),
                     ir.ElseNode(ir.TextNode("odd\n")),
                 ),
             ),
         )
     ])
Пример #5
0
 def setUp(self):
     self.tpl = ir.TemplateNode(
         defs=[ir.DefNode(
               'evenness(n)',
               ir.IfNode(
                   'n % 2 == 0',
                   ir.TextNode('even')),
               ir.ElseNode(
               ir.TextNode('odd'))),
               ir.DefNode(
               '__main__()',
               ir.ForNode(
                   'i in range(2)',
                   ir.ExprNode('i'),
                   ir.TextNode(' is '),
                   ir.ExprNode('evenness(i)'),
                   ir.TextNode('\n')))])
Пример #6
0
 def setUp(self):
     self.tpl = ir.TemplateNode(defs=[
         ir.DefNode(
             "evenness(n)",
             ir.IfNode("n % 2 == 0", ir.TextNode("even")),
             ir.ElseNode(ir.TextNode("odd")),
         ),
         ir.DefNode(
             "__main__()",
             ir.ForNode(
                 "i in range(2)",
                 ir.ExprNode("i"),
                 ir.TextNode(" is "),
                 ir.ExprNode("evenness(i)"),
                 ir.TextNode("\n"),
             ),
         ),
     ])
Пример #7
0
 def setUp(self):
     p0 = ir.TemplateNode(
         defs=[ir.DefNode("__main__()", ir.TextNode("Parent 0"))])
     p1 = ir.TemplateNode(
         defs=[ir.DefNode("__main__()", ir.TextNode("Parent 1"))])
     child = ir.TemplateNode(defs=[
         ir.DefNode(
             "__main__()",
             ir.IfNode("p==0", ir.ExtendNode("parent0.txt")),
             ir.ElseNode(ir.ExtendNode("parent1.txt")),
         )
     ])
     loader = kajiki.loader.MockLoader({
         "parent0.txt":
         kajiki.template.from_ir(p0),
         "parent1.txt":
         kajiki.template.from_ir(p1),
         "child.txt":
         kajiki.template.from_ir(child),
     })
     self.loader = loader
     self.tpl = loader.import_("child.txt")
Пример #8
0
 def setUp(self):
     lib = ir.TemplateNode(defs=[
         ir.DefNode(
             "evenness(n)",
             ir.IfNode("n % 2 == 0", ir.TextNode("even")),
             ir.ElseNode(ir.TextNode("odd")),
         ),
         ir.DefNode(
             "half_evenness(n)",
             ir.TextNode(" half of "),
             ir.ExprNode("n"),
             ir.TextNode(" is "),
             ir.ExprNode("evenness(n/2)"),
         ),
     ])
     tpl = ir.TemplateNode(defs=[
         ir.DefNode(
             "__main__()",
             ir.ImportNode("lib.txt", "simple_function"),
             ir.ForNode(
                 "i in range(4)",
                 ir.ExprNode("i"),
                 ir.TextNode(" is "),
                 ir.ExprNode("simple_function.evenness(i)"),
                 ir.ExprNode("simple_function.half_evenness(i)"),
                 ir.TextNode("\n"),
             ),
         )
     ])
     loader = kajiki.loader.MockLoader({
         "lib.txt":
         kajiki.template.from_ir(lib),
         "tpl.txt":
         kajiki.template.from_ir(tpl),
     })
     self.tpl = loader.import_("tpl.txt")