Пример #1
0
 def test_attributes(self):
     t = D(1, 'some-thing')
     assert t.id == 1
     assert t.entity == 'some-thing'
     assert t.score == -1
     assert t.start == -1
     assert t.end == -1
     assert t.daughters == []
     t = D(1, 'some-thing', 0.5, 1, 6, [T('some token')])
     assert t.id == 1
     assert t.entity == 'some-thing'
     assert t.score == 0.5
     assert t.start == 1
     assert t.end == 6
     assert t.daughters == [T('some token')]
     t = D(None, 'some-root', daughters=[D(1, 'some-thing')])
     assert t.id is None
     assert t.entity == 'some-root'
     assert t.score is None
     assert t.start is None
     assert t.end is None
     assert len(t.daughters) == 1
Пример #2
0
 def test_attributes(self):
     t = D(1, 'some-type')
     assert t.id == 1
     assert t.entity == 'some-type'
     assert t.score == -1
     assert t.start == -1
     assert t.end == -1
     assert t.daughters == []
     t = D(1, 'some-type', 0.5, 1, 6, ['some token'])
     assert t.id == 1
     assert t.entity == 'some-type'
     assert t.score == 0.5
     assert t.start == 1
     assert t.end == 6
     assert t.daughters == ['some token']
     t = D(None, 'some-root', daughters=[D(1, 'some-type')])
     assert t.id == None
     assert t.entity == 'some-root'
     assert t.score == None
     assert t.start == None
     assert t.end == None
     assert len(t.daughters) == 1
Пример #3
0
 def test_init(self):
     with pytest.raises(TypeError):
         D()
     with pytest.raises(TypeError):
         D(1)
     D(1, 'some-thing')
     D(1, 'some-thing', 0.5, 0, 3, [T('some-token')])
     # roots are special: id is None, entity is root, daughters must
     # exactly 1 node; rest are None
     with pytest.raises(TypeError):
         D(None)
     with pytest.raises(TypeError):
         D(None, 'some-root', 0.5)
     with pytest.raises(TypeError):
         D(None, 'some-root', start=1)
     with pytest.raises(TypeError):
         D(None, 'some-root', end=1)
     with pytest.raises(ValueError):
         D(None,
           'some-root',
           daughters=[N(1, 'some-thing'),
                      N(2, 'some-thing')])
     with pytest.raises(ValueError):
         D(None, 'some-root', daughters=[T('some-token')])
     D(None, 'some-root', daughters=[N(1, 'some-thing')])
     D(None, 'some-root', None, None, None, daughters=[N(1, 'some-thing')])
     # root not as top
     with pytest.raises(ValueError):
         D(1,
           'some-thing',
           daughters=[
               N(None,
                 'some-root',
                 daughters=[N(2, 'a-lex', daughters=[T('some-token')])])
           ])