Exemplo n.º 1
0
 def test__contains__(self):
     a = Conjunction()
     assert 'ATTR' not in a
     a.add(AVM({'ATTR': TypeIdentifier('val')}))
     assert 'ATTR' in a
     a.add(AVM({'ATTR': TypeIdentifier('val2')}))  # two AVMs
     assert 'ATTR' in a
Exemplo n.º 2
0
 def test__getitem__(self):
     a = Conjunction()
     with pytest.raises(KeyError):
         a['ATTR']
     a.add(AVM({'ATTR': TypeIdentifier('val')}))
     assert a['ATTR'] == TypeIdentifier('val')
     a.add(AVM({'ATTR': TypeIdentifier('val2')}))  # two AVMs
     assert a['ATTR'] == Conjunction([TypeIdentifier('val'),
                                      TypeIdentifier('val2')])
Exemplo n.º 3
0
def test_Conjunction():
    c = Conjunction()
    orig_c = c
    assert len(c.terms) == 0
    c &= TypeIdentifier('a')
    assert len(c.terms) == 1
    assert len(orig_c.terms) == 0
    with pytest.raises(TypeError):
        c &= 'b'
    with pytest.raises(TypeError):
        c.add('b')
Exemplo n.º 4
0
 def test__setitem__(self):
     a = Conjunction()
     with pytest.raises(TDLError):
         a['ATTR'] = TypeIdentifier('val')
     a.add(AVM())
     a['ATTR'] = TypeIdentifier('val')
     assert a['ATTR'] == TypeIdentifier('val')
     # reassignment overwrites
     a['ATTR'] = TypeIdentifier('val2')
     assert a['ATTR'] == TypeIdentifier('val2')
     a['ATTR'] &= TypeIdentifier('val3')
     assert a['ATTR'] == Conjunction([TypeIdentifier('val2'),
                                      TypeIdentifier('val3')])
     # setitem adds to the last AVM
     a.add(AVM())
     a['ATTR'] = TypeIdentifier('val4')
     assert a.terms[1]['ATTR'] == TypeIdentifier('val4')
Exemplo n.º 5
0
 def test_add(self):
     c = Conjunction()
     with pytest.raises(TypeError):
         c.add('b')
     c.add(TypeIdentifier('a'))
     assert c.terms == [TypeIdentifier('a')]