Beispiel #1
0
 def test_access_value(self):
     value = "this is variable nodes value."
     scope = Scope()
     node = VariableNode("a", scope)
     self.assertEqual(node.get_value(defaultvalue=None), None)  # test
     node.set_value(value)
     self.assertEqual(node.get_value(defaultvalue=None), value)  # test
Beispiel #2
0
 def test_access_value2(self):
     value1 = "example value."
     scope = Scope()
     scope.set_value("a", value1)
     with scope:
         value2 = "example value2."
         scope.set_value("a", value2)
         self.assertEqual(scope.get_value("a"), value2)
     self.assertEqual(scope.get_value("a"), value1)
Beispiel #3
0
 def test_write(self):
     value = "this is variable nodes value."
     scope = Scope()
     node = VariableNode("a", scope)
     node.set_value(value)
     with StringIO() as stream:
         node.write(stream)
         self.assertEqual(stream.getvalue(), value)  # test
Beispiel #4
0
 def test_get_value(self):
     scope = Scope()
     variable = VariableNode("person", scope)
     member = MemberNode("name", variable)
     # when undefined
     self.assertEqual(member.get_value(defaultvalue=None), None)
     # when did set
     variable.set_value({"name": "tikubonn"})
     self.assertEqual(member.get_value(defaultvalue=None), "tikubonn")
Beispiel #5
0
 def test_write(self):
     with StringIO() as stream:
         separator = TextNode(",")
         scope = Scope()
         variable = VariableNode("a", scope)
         variable.set_value(["a", "b", "c"])
         node = JoinNode(separator, variable)
         node.write(stream)
         self.assertEqual(stream.getvalue(), "a,b,c")
Beispiel #6
0
 def test_render(self):
     with StringIO() as stream:
         scope = Scope()
         sentence = SentenceNode()
         sentence.add(VariableNode("a", scope))
         sentence.add(VariableNode("b", scope))
         sentence.add(VariableNode("c", scope))
         template = Template(sentence, scope)
         template.render(stream, a="a", b="b", c="c")
         self.assertEqual(stream.getvalue(), "abc")
Beispiel #7
0
 def test_write(self):
     with StringIO() as stream:
         scope = Scope()
         source = VariableNode("a", scope)
         source.set_value(["a", "b", "c"])
         variable = VariableNode("a", scope)
         sentence = SentenceNode()
         sentence.add(variable)
         fornode = ForNode(source, variable, sentence, scope)
         fornode.write(stream)
         self.assertEqual(stream.getvalue(), "abc")
Beispiel #8
0
 def test_write(self):
     scope = Scope()
     variable = VariableNode("person", scope)
     member = MemberNode("name", variable)
     # when undefined
     with StringIO() as stream:
         member.write(stream)
         self.assertEqual(stream.getvalue(), "")
     # when did set
     variable.set_value({"name": "tikubonn"})
     with StringIO() as stream:
         member.write(stream)
         self.assertEqual(stream.getvalue(), "tikubonn")
Beispiel #9
0
 def test_write(self):
     scope = Scope()
     variable = VariableNode("a", scope)
     node = SanitizeNode(variable)
     # when undefined
     with StringIO() as stream:
         node.write(stream)
         self.assertEqual(stream.getvalue(), "")
     # when set value
     variable.set_value("<br>")
     with StringIO() as stream:
         node.write(stream)
         self.assertEqual(stream.getvalue(), "&lt;br&gt;")
Beispiel #10
0
 def test_write(self):
     scope = Scope()
     variable = VariableNode("a", scope)
     thennode = TextNode("true")
     elsenode = TextNode("false")
     ifnode = IfNode(variable, thennode, elsenode)
     # when undefined
     with StringIO() as stream:
         ifnode.write(stream)
         self.assertEqual(stream.getvalue(), "false")
     # when true
     variable.set_value(True)
     with StringIO() as stream:
         ifnode.write(stream)
         self.assertEqual(stream.getvalue(), "true")
     # when false
     variable.set_value(False)
     with StringIO() as stream:
         ifnode.write(stream)
         self.assertEqual(stream.getvalue(), "false")
Beispiel #11
0
 def __init__(self, syntaxtable=default_syntax_table):
     self.syntaxtable = syntaxtable
     self.scope = Scope()
     self.sentencenode = SentenceNode()
Beispiel #12
0
 def test_access_value1(self):
     value = "example value."
     scope = Scope()
     self.assertEqual(scope.get_value("a", defaultvalue=None), None)  # test
     scope.set_value("a", value)
     self.assertEqual(scope.get_value("a"), value)