Пример #1
0
    def test_new_from_generator(self):
        def gen():
            for i in ('txt', 'ns', (1, 2), 'id', None):
                yield i

        s = segment(gen())
        assert s.offset == (1, 2)
Пример #2
0
    def test_new_from_generator(self):
        def gen():
            for i in ('txt', 'ns', (1, 2), 'id', None):
                yield i

        s = segment(gen())
        assert s.offset == (1, 2)
Пример #3
0
 def test_new_bad_values(self):
     with raises(AssertionError):
         segment(1, 'ns', (1, 2))
     with raises(AssertionError):
         segment('txt', 1, (1, 2))
     with raises(TypeError):
         segment('txt', 'ns', 1)
     with raises(ValueError):
         segment('txt', 'ns', (1, 2, 3))
Пример #4
0
 def test_new_bad_values(self):
     with raises(AssertionError):
         segment(1, 'ns', (1, 2))
     with raises(AssertionError):
         segment('txt', 1, (1, 2))
     with raises(TypeError):
         segment('txt', 'ns', 1)
     with raises(ValueError):
         segment('txt', 'ns', (1, 2, 3))
Пример #5
0
 def test_Update(self):
     s1 = segment('txt', 'ns', (1, 2), identifier='id')
     assert 'id' == s1.identifier.get_or('sentinel')
     s2 = s1.Update(identifier='other')
     assert 'other' == s2.identifier.get_or('sentinel')
     s3 = s2.Update(text='another', namespace='different', offset=(2, 3))
     assert 'another' == s3.text
     assert 'different' == s3.namespace
     assert (2, 3) == s3.offset
Пример #6
0
 def test_Update(self):
     s1 = segment('txt', 'ns', (1, 2), identifier='id')
     assert 'id' == s1.identifier.get_or('sentinel')
     s2 = s1.Update(identifier='other')
     assert 'other' == s2.identifier.get_or('sentinel')
     s3 = s2.Update(text='another', namespace='different', offset=(2, 3))
     assert 'another' == s3.text
     assert 'different' == s3.namespace
     assert (2, 3) == s3.offset
Пример #7
0
    def test_Update_bad_values(self):
        t = segment('txt', 'ns', (1, 2), identifier='id')

        with raises(AssertionError):
            t.Update(text=1)
        with raises(AssertionError):
            t.Update(namespace=1)
        with raises(TypeError):
            t.Update(offset=1)
        with raises(ValueError):
            t.Update(offset=(1, 2, 3))
Пример #8
0
    def test_Update_bad_values(self):
        t = segment('txt', 'ns', (1, 2), identifier='id')

        with raises(AssertionError):
            t.Update(text=1)
        with raises(AssertionError):
            t.Update(namespace=1)
        with raises(TypeError):
            t.Update(offset=1)
        with raises(ValueError):
            t.Update(offset=(1, 2, 3))
Пример #9
0
 def test_new_missing_values(self):
     with raises(ValueError):
         segment('txt', 'ns')
     with raises(ValueError):
         segment('txt')
     with raises(ValueError):
         segment('12345')
Пример #10
0
 def test_new_missing_values(self):
     with raises(ValueError):
         segment('txt', 'ns')
     with raises(ValueError):
         segment('txt')
     with raises(ValueError):
         segment('12345')
Пример #11
0
 def test_str(self):
     s = segment('txt', 'ns', (1, 2), annotations='TODO')
     assert "ns\t1:2\t\\N\tTODO" == str(s)
Пример #12
0
 def test_repr(self):
     s = segment('txt', 'ns', (1, 2), identifier='UID')
     assert "segment(ns, 1:2, identifier='UID')" == repr(s)
Пример #13
0
 def test_str_with_tabs(self):
     s = segment('txt', 'n\ts', (1, 2), identifier='st\t\tem')
     assert "n\\ts\t1:2\tst\\t\\tem\t\\N" == str(s)
Пример #14
0
 def test_copy_list(self):
     s = segment(['txt', 'ns', (1, 2), 'id', None])
     CheckAttributes(s)
     CheckMeta(s, 'id')
Пример #15
0
 def test_alternative_offsets(self):
     segment('txt', 'ns', (1, ))
     segment('txt', 'ns', (1, 2, 3, 4))
Пример #16
0
 def test_new_most_values(self):
     s = segment('txt', 'ns', (1, 2), 'id')
     CheckAttributes(s)
     CheckMeta(s, 'id')
Пример #17
0
 def test_new_most_values(self):
     s = segment('txt', 'ns', (1, 2), 'id')
     CheckAttributes(s)
     CheckMeta(s, 'id')
Пример #18
0
 def test_new_ignore_unused_keywords(self):
     t = segment('txt', 'ns', (1, 2), annotations='ann', funny='haha')
     CheckAttributes(t)
     CheckMeta(t, annotations='ann')
Пример #19
0
 def test_new_using_keywords(self):
     t = segment('txt', 'ns', (1, 2), identifier='id')
     CheckAttributes(t)
     CheckMeta(t, 'id')
Пример #20
0
 def test_new_ignore_excess_values(self):
     s = segment('txt', 'ns', (1, 2), 'id', 'ann', 'junk')
     CheckAttributes(s)
     CheckMeta(s, 'id', 'ann')
Пример #21
0
 def test_str_with_tabs(self):
     s = segment('txt', 'n\ts', (1, 2), identifier='st\t\tem')
     assert "n\\ts\t1:2\tst\\t\\tem\t\\N" == str(s)
Пример #22
0
 def test_new_using_keywords(self):
     t = segment('txt', 'ns', (1, 2), identifier='id')
     CheckAttributes(t)
     CheckMeta(t, 'id')
Пример #23
0
 def test_alternative_offsets(self):
     segment('txt', 'ns', (1,))
     segment('txt', 'ns', (1, 2, 3, 4))
Пример #24
0
 def test_new(self):
     s = segment('txt', 'ns', (1, 2))
     assert isinstance(s, segment)
     CheckAttributes(s)
     CheckMeta(s)
Пример #25
0
 def test_new(self):
     s = segment('txt', 'ns', (1, 2))
     assert isinstance(s, segment)
     CheckAttributes(s)
     CheckMeta(s)
Пример #26
0
 def test_copy(self):
     s = segment(segment('txt', 'ns', (1, 2), 'id', 'ann'))
     assert isinstance(s, segment)
     CheckAttributes(s)
     CheckMeta(s, 'id', 'ann')
Пример #27
0
 def test_new_ignore_excess_values(self):
     s = segment('txt', 'ns', (1, 2), 'id', 'ann', 'junk')
     CheckAttributes(s)
     CheckMeta(s, 'id', 'ann')
Пример #28
0
 def test_copy_list(self):
     s = segment(['txt', 'ns', (1, 2), 'id', None])
     CheckAttributes(s)
     CheckMeta(s, 'id')
Пример #29
0
 def test_new_ignore_unused_keywords(self):
     t = segment('txt', 'ns', (1, 2), annotations='ann', funny='haha')
     CheckAttributes(t)
     CheckMeta(t, annotations='ann')
Пример #30
0
 def test_copy_too_short(self):
     with raises(ValueError):
         segment(('txt', 'ns', (1, 2), 'id'))
Пример #31
0
 def test_copy_too_long(self):
     t = segment(('txt', 'ns', (1, 2), 'id', 'ann', 'junk'))
     CheckAttributes(t)
     CheckMeta(t, 'id', 'ann')
Пример #32
0
 def test_copy_too_long(self):
     t = segment(('txt', 'ns', (1, 2), 'id', 'ann', 'junk'))
     CheckAttributes(t)
     CheckMeta(t, 'id', 'ann')
Пример #33
0
 def test_copy(self):
     s = segment(segment('txt', 'ns', (1, 2), 'id', 'ann'))
     assert isinstance(s, segment)
     CheckAttributes(s)
     CheckMeta(s, 'id', 'ann')
Пример #34
0
 def test_repr(self):
     s = segment('txt', 'ns', (1, 2), identifier='UID')
     assert "segment(ns, 1:2, identifier='UID')" == repr(s)
Пример #35
0
 def test_copy_too_short(self):
     with raises(ValueError):
         segment(('txt', 'ns', (1, 2), 'id'))
Пример #36
0
 def test_str(self):
     s = segment('txt', 'ns', (1, 2), annotations='TODO')
     assert "ns\t1:2\t\\N\tTODO" == str(s)
Пример #37
0
 def test_infered_properties(self):
     s = segment('text', 'ns', (1, 3))
     assert 1 == s.begin
     assert 3 == s.end
Пример #38
0
 def test_infered_properties(self):
     s = segment('text', 'ns', (1, 3))
     assert 1 == s.begin
     assert 3 == s.end