class TestOptionalGroup(unittest.TestCase):
    
    def setUp(self):
        self.store = TripleStore()
        self.store.add_triples(('a', 'name', 'name-a'), ('b', 'name', 'name-b'),
                    ('a', 'weight', 'weight-a'), ('b', 'size', 'size-b'))
        self.p = OptionalGroup(Pattern(self.store, VariableExpression('id'), LiteralExpression('name'), VariableExpression('name')))
    
    def test_match_empty_solution(self):
        self.assertEqual(
            [dict(id='a', name='name-a'), dict(id='b', name='name-b')],
            list(self.p.match({}))
        )
    
    def test_match_with_constraining_solution(self):
        self.assertEqual(
            [dict(id='a', name='name-a')],
            list(self.p.match({'id': 'a'}))
        )
        self.assertEqual(
            [dict(id='b', name='name-b')],
            list(self.p.match({'name': 'name-b'}))
        )
        self.assertEqual(
            [dict(id='c')],
            list(self.p.match({'id': 'c'}))
        )
        self.assertEqual(
            [dict(id='c', name='name-c')],
            list(self.p.match({'id': 'c', 'name': 'name-c'}))
        )
    
    def test_match_with_nonconstraining_solution(self):
        self.assertEqual(
            [dict(id='a', name='name-a', bar='two'),
             dict(id='b', name='name-b', bar='two')],
            list(self.p.match({'bar': 'two'}))
        )
 def setUp(self):
     self.store = TripleStore()
     self.store.add_triples(('a', 'name', 'name-a'), ('b', 'name', 'name-b'),
                 ('a', 'weight', 'weight-a'), ('b', 'size', 'size-b'))
     self.p = OptionalGroup(Pattern(self.store, VariableExpression('id'), LiteralExpression('name'), VariableExpression('name')))