Пример #1
0
 def test_neg_expression(self):
     exp = rules.NegExpression(None, rules.ValueTerminal(None, "10"))
     c = DictContext({})
     self.assertEquals(exp.eval(c), -10)
     exp = rules.NegExpression(None,
                               rules.ReferenceTerminal(None, "${foo}"))
     c = DictContext({'foo': 2})
     self.assertEquals(exp.eval(c), -2)
Пример #2
0
 def test_one_param_expression(self):
     exp = rules.OneParamExpression(None, rules.ValueTerminal(None, "10"))
     c = DictContext({})
     self.assertEquals(exp.eval(c), 10)
     exp = rules.OneParamExpression(None,
                                    rules.ReferenceTerminal(None, "${foo}"))
     c = DictContext({'foo': 'Foo string'})
     self.assertEquals(exp.eval(c), 'Foo string')
Пример #3
0
 def test_and_expression(self):
     exp = rules.AndExpression(None, rules.ValueTerminal(None, True),
                               rules.ReferenceTerminal(None, "${foo}"))
     c = DictContext({'foo': 1})
     self.assertEquals(exp.eval(c), True)
     c = DictContext({'foo': 0})
     self.assertEquals(exp.eval(c), False)
     c = DictContext({'foo': ""})
     self.assertEquals(exp.eval(c), False)
     c = DictContext({'foo': False})
     self.assertEquals(exp.eval(c), False)
     c = DictContext({'foo': True})
     self.assertEquals(exp.eval(c), True)
Пример #4
0
 def test_set_expression(self):
     exp = rules.SetExpression(None, rules.ReferenceTerminal(None, "${t}"),
                               rules.ValueTerminal(None, "10"))
     c = DictContext({'foo': 10, 't': None})
     self.assertEquals(exp.eval(c), True)
     self.assertEquals(c.data['t'], 10)
Пример #5
0
 def test_div_expression(self):
     exp = rules.DivideExpression(None, rules.ValueTerminal(None, "10"),
                                  rules.ReferenceTerminal(None, "${foo}"))
     c = DictContext({'foo': 10})
     self.assertEquals(exp.eval(c), 1)