def setUp(self): self.env = Env() self.v_uri = Uri('http://test.triplepack/#variable') self.env.assign(self.v_uri, Value(42)) self.template = Template(Name('A'), [Name('x'), Name('y')], [ Property(Name('x'), Value(42)), Property(Uri('http://example.eg/predicate'), Name('y')) ]) self.expansion = Expansion(Name('e'), Name('A'), [Value(1), Value(2)], []) self.template.evaluate(self.env) def triple_eval(triple): (s, p, o) = triple s = s.evaluate(self.env) p = p.evaluate(self.env) o = o.evaluate(self.env) return (s, p, o) triples = self.expansion.as_triples(self.env) triples = [triple_eval(triple) for triple in triples] bindings = self.env._symbol_table templates = self.env._template_table self.pack = TriplePack(triples, bindings, templates, [])
def test_extension_in_body_with_arg(self): script = 'A()(@extension ExtensionName(12345))' forms = self.parser.parse(script) a = forms[0] expected_template = Template(Identifier( Name('A')), [], [ExtensionPragma('ExtensionName', [Value(12345)])]) self.assertEqual(expected_template, a)
def test_expansion_in_property_with_args(self): script = 'A()(x = e is a B(12345))' forms = self.parser.parse(script) e = self.parser.parse('e is a B(12345)')[0] expected_template = Template(Identifier(Name('A')), [], [Property(Identifier(Name('x')), e)]) self.assertEqual(expected_template, forms[0])
def test_template_onearg_nobase(self): script = 'DNASequence(x)(encoding = <SBOL:IUPACDNA>)' forms = self.parser.parse(script) expected_template = Template(Identifier(Name('DNASequence')), ['x'], [ Property(Identifier(Name('encoding')), Identifier(Uri('SBOL:IUPACDNA'))) ]) self.assertCountEqual(forms, [expected_template])
def test_empty_template_noargs(self): script = 'DNASequence()(Other())' forms = self.parser.parse(script) expected_template = Template( Identifier(Name('DNASequence')), [], [Expansion(None, Identifier(Name('Other')), [], [])]) self.assertCountEqual(forms, [expected_template])
def test_template_onearg_base(self): script = 'B(x)(x = 42)\nA(x)(B(x) encoding = <SBOL:IUPACDNA>)' forms = self.parser.parse(script) expected_template = Template(Identifier(Name('A')), ['x'], [ Expansion(None, Identifier(Name('B')), [Identifier(Name('x'))], []), Property(Identifier(Name('encoding')), Identifier(Uri('SBOL:IUPACDNA'))) ]) self.assertCountEqual([forms[1]], [expected_template])
def test_as_triples_empty(self): ''' Tests if triples list is empty when no parser call. ''' template = Template(Identifier(Name('x')), [], []) self.assertCountEqual(template.as_triples(self.env), [])
def test_init(self): ''' Simplest check, does Templates Identifier get added to parts list. ''' template = Template(Identifier(Name('x')), [], []) self.assertEqual(template.identifier.parts[0], Name('x'))
def test_empty_template_args_nobase(self): script = 'DNASequence(x, y, z)' forms = self.parser.parse(script) expected_template = Template(Identifier(Name('DNASequence')), ['x', 'y', 'z'], []) self.assertCountEqual(forms, [expected_template])
def test_expansion_in_body(self): script = 'A()(e is a B())' forms = self.parser.parse(script) e = self.parser.parse('e is a B()')[0] expected_template = Template(Identifier(Name('A')), [], [e]) self.assertEqual(expected_template, forms[0])