Simplify underscore tests

This commit is contained in:
ines 2018-04-28 23:30:33 +02:00
parent 6fb6371670
commit abdb853ebf

View File

@ -5,7 +5,7 @@ import pytest
from mock import Mock from mock import Mock
from ..vocab import Vocab from ..vocab import Vocab
from ..tokens.doc import Doc from ..tokens import Doc, Span, Token
from ..tokens.underscore import Underscore from ..tokens.underscore import Underscore
@ -60,10 +60,7 @@ def test_token_underscore_method():
assert token._.hello() == 'cheese' assert token._.hello() == 'cheese'
@pytest.mark.parametrize('obj', [ @pytest.mark.parametrize('obj', [Doc, Span, Token])
Doc(Vocab(), words=['hello', 'world']),
Doc(Vocab(), words=['hello', 'world'])[1],
Doc(Vocab(), words=['hello', 'world'])[0:2]])
def test_underscore_raises_for_dup(obj): def test_underscore_raises_for_dup(obj):
obj.set_extension('test', default=None) obj.set_extension('test', default=None)
with pytest.raises(ValueError): with pytest.raises(ValueError):
@ -78,9 +75,8 @@ def test_underscore_raises_for_dup(obj):
{'getter': True}]) {'getter': True}])
def test_underscore_raises_for_invalid(invalid_kwargs): def test_underscore_raises_for_invalid(invalid_kwargs):
invalid_kwargs['force'] = True invalid_kwargs['force'] = True
doc = Doc(Vocab(), words=['hello', 'world'])
with pytest.raises(ValueError): with pytest.raises(ValueError):
doc.set_extension('test', **invalid_kwargs) Doc.set_extension('test', **invalid_kwargs)
@pytest.mark.parametrize('valid_kwargs', [ @pytest.mark.parametrize('valid_kwargs', [
@ -91,5 +87,4 @@ def test_underscore_raises_for_invalid(invalid_kwargs):
{'method': lambda: None}]) {'method': lambda: None}])
def test_underscore_accepts_valid(valid_kwargs): def test_underscore_accepts_valid(valid_kwargs):
valid_kwargs['force'] = True valid_kwargs['force'] = True
doc = Doc(Vocab(), words=['hello', 'world']) Doc.set_extension('test', **valid_kwargs)
doc.set_extension('test', **valid_kwargs)