def test_as_triples_multiple_base_args_and_parameters(self): forms = self.parser.parse('a(x, y)(x = y)' + 'b(x, y)(a(x, "string") z=y)' + 'c(x, y)(b(1, 2) x=y)') a = forms[0] b = forms[1] c = forms[2] a.evaluate(self.env) b.evaluate(self.env) expect = [(Identifier(Self()), Value(1), Value("string")), (Identifier(Self()), Identifier(Name('z')).evaluate(self.env), Value(2)), (Identifier(Self()), Identifier(Parameter('x', 0)), Identifier(Parameter('y', 0)))] self.assertCountEqual(expect, c.as_triples(self.env))
def test_as_triples_params(self): ''' Test for correctness when a template is defined with param and set to property ''' forms = self.parser.parse('a(x)(property = x)') a = forms[0] expect = [(Identifier(Self()), Identifier(Name('property')), Identifier(Parameter('x',0)))] for index,triple in enumerate(a.as_triples(self.env)): for tuple_index,element in enumerate(triple): self.assertEqual(element,expect[index][tuple_index]) self.assertCountEqual(a.as_triples(self.env), expect)
def test_as_triples_with_base_with_params(self): ''' Test for correctness when a template is defined and property is set to value. ''' forms = self.parser.parse('a(x)(x = 12345) b(y)(a(y))') a = forms[0] b = forms[1] template_name = a.identifier.evaluate(self.env) self.env.assign_template(template_name, a.as_triples(self.env)) expect = [(Identifier(Self()), Identifier(Parameter('y', 0)), Value(12345))] self.assertCountEqual(expect, b.as_triples(self.env))
def test_evaluate_stores_triples_with_unevaluated_parameters(self): forms = self.parser.parse('q(p)(a=p)' + 's(u,v)(z=u q(v))' + 't(a,b)(x=1 y=2 s(a,b))') q = forms[0] s = forms[1] t = forms[2] with self.assertRaises(KeyError): self.env.lookup_template(t.identifier.evaluate(self.env)) q.evaluate(self.env) s.evaluate(self.env) t.evaluate(self.env) a = Identifier(Parameter('a', 0)) b = Identifier(Parameter('b', 1)) found = self.env.lookup_template(t.identifier.evaluate(self.env)) expect = [(Identifier(Self()), Identifier(Name('x')).evaluate(self.env), Value(1)), (Identifier(Self()), Identifier(Name('y')).evaluate(self.env), Value(2)), (Identifier(Self()), Identifier(Name('z')).evaluate(self.env), a), (Identifier(Self()), Identifier(Name('a')).evaluate(self.env), b)] self.assertCountEqual(found, expect)
def test_marshal_false(self): p = Identifier(Parameter('z', 0)) a = Argument(Value(1), 1) self.assertEqual(a.marshal(p), p)
def test_parameter_name_equality(self): n = Name(Parameter('x', 0)) o = Name(Parameter('x', 0)) self.assertEqual(n, o)
def test_parameter_parameter_equality(self): p = Parameter('x', 0) q = Parameter('y', 0) r = Parameter('x', 0) self.assertNotEqual(p, q) self.assertEqual(p, r)