def test_multi_level(self): x, y, z = 423, 324, 321 f1 = FieldExpression(x, y, ops.add) f2 = FieldExpression(y, z, ops.add) f3 = FieldExpression(f1, f2, ops.sub) self.assertTrue(f3.eval() == ops.sub(ops.add(x, y), ops.add(y, z))) self.assertTrue(f3.to_string() == "(423 + 324) - (324 + 321)")
def test_partly_evaluation(self): x, y = 123, "varname" f1 = FieldExpression(x, y, ops.add) f2 = f1.eval() self.assertTrue(isinstance(f1.eval(), FieldExpression)) self.assertTrue(f1.to_string() == "123 + varname") f1.context["varname"] = 313 self.assertTrue(isinstance(f1.eval(), int)) self.assertTrue(f1.eval() == 436)