Ejemplo n.º 1
0
    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, [])
Ejemplo n.º 2
0
 def test_expansion_multiple_properties(self):
     forms = self.parser.parse('e is a a()(x=true y=false)')
     expect = Expansion(Identifier(Name('e')),
                        Identifier(Name('a')),
                        [],
                        [Property(Identifier(Name('x')), Value(True)),
                         Property(Identifier(Name('y')), Value(False))])
     self.assertEqual(expect, forms[0])
Ejemplo n.º 3
0
    def test_as_triples_expansion(self):
        forms = self.parser.parse('t()(x=1) e is a t()')
        t = forms[0]
        e = forms[1]
        p = Property(Identifier(Name('y')), e)

        t.evaluate(self.env)

        expected = [(Identifier(Name('e')),
                     Identifier(Name('x')).evaluate(self.env), Value(1)),
                    (Identifier(Self()), Identifier(Name('y')),
                     Identifier(Name('e')))]
        actually = p.as_triples(self.env)
        self.assertEqual(expected, actually)
Ejemplo n.º 4
0
 def test_expansion_one_arg_with_body(self):
     forms = self.parser.parse('e is a a(12345)(x=true)')
     expect = Expansion(Identifier(Name('e')),
                        Identifier(Name('a')),
                        [Value(12345)],
                        [Property(Identifier(Name('x')), Value(True))])
     self.assertEqual(expect, forms[0])
Ejemplo n.º 5
0
 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])
Ejemplo n.º 6
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])
Ejemplo n.º 7
0
    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])
Ejemplo n.º 8
0
 def test_as_triples_self_in_name(self):
     p = Property(Identifier(Self()), Value(1))
     expected = [(Identifier(Self()), Identifier(Self()), Value(1))]
     actually = p.as_triples(self.env)
     self.assertEqual(expected, actually)
Ejemplo n.º 9
0
 def test_as_triples_simple(self):
     p = Property(Identifier(Name('x')), Identifier(Name('y')))
     expected = [(Identifier(Self()), Identifier(Name('x')),
                  Identifier(Name('y')))]
     actually = p.as_triples(self.env)
     self.assertEqual(expected, actually)