From 3a65a0c970ec235d7e5b306924a90e8552c6568c Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Sat, 7 Oct 2017 01:48:23 +0200 Subject: [PATCH] Start adding tests for new pipeline management --- spacy/tests/pipeline/__init__.py | 0 spacy/tests/pipeline/test_add_pipe.py | 43 +++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 spacy/tests/pipeline/__init__.py create mode 100644 spacy/tests/pipeline/test_add_pipe.py diff --git a/spacy/tests/pipeline/__init__.py b/spacy/tests/pipeline/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/spacy/tests/pipeline/test_add_pipe.py b/spacy/tests/pipeline/test_add_pipe.py new file mode 100644 index 000000000..13fb4acaf --- /dev/null +++ b/spacy/tests/pipeline/test_add_pipe.py @@ -0,0 +1,43 @@ +from __future__ import unicode_literals +import pytest + +from ... import language +from ...language import Language + +@pytest.fixture +def nlp(): + return Language() + +@pytest.fixture +def name(): + return 'parser' + +def new_pipe(doc): + return doc + + +def test_add_pipe_no_name(nlp): + nlp.add_pipe(new_pipe) + assert 'new_pipe' in nlp.pipe_names + +def test_add_pipe_duplicate_name(nlp): + nlp.add_pipe(new_pipe, name='duplicate_name') + with pytest.raises(ValueError): + nlp.add_pipe(new_pipe, name='duplicate_name') + + +def test_add_pipe_first(nlp, name): + nlp.add_pipe(new_pipe, name=name, first=True) + assert nlp.pipeline[0][0] == name + + +def test_add_pipe_last(nlp, name): + nlp.add_pipe(lambda doc: doc, name='lambda_pipe') + nlp.add_pipe(new_pipe, name=name, last=True) + assert nlp.pipeline[0][0] != name + assert nlp.pipeline[-1][0] == name + + +def test_cant_add_pipe_first_and_last(nlp): + with pytest.raises(ValueError): + nlp.add_pipe(new_pipe, first=True, last=True)