mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-28 02:46:35 +03:00
75f3234404
## Description Related issues: #2379 (should be fixed by separating model tests) * **total execution time down from > 300 seconds to under 60 seconds** 🎉 * removed all model-specific tests that could only really be run manually anyway – those will now live in a separate test suite in the [`spacy-models`](https://github.com/explosion/spacy-models) repository and are already integrated into our new model training infrastructure * changed all relative imports to absolute imports to prepare for moving the test suite from `/spacy/tests` to `/tests` (it'll now always test against the installed version) * merged old regression tests into collections, e.g. `test_issue1001-1500.py` (about 90% of the regression tests are very short anyways) * tidied up and rewrote existing tests wherever possible ### Todo - [ ] move tests to `/tests` and adjust CI commands accordingly - [x] move model test suite from internal repo to `spacy-models` - [x] ~~investigate why `pipeline/test_textcat.py` is flakey~~ - [x] review old regression tests (leftover files) and see if they can be merged, simplified or deleted - [ ] update documentation on how to run tests ### Types of change enhancement, tests ## Checklist <!--- Before you submit the PR, go over this checklist and make sure you can tick off all the boxes. [] -> [x] --> - [x] I have submitted the spaCy Contributor Agreement. - [x] I ran the tests, and all new and existing tests passed. - [ ] My changes don't require a change to the documentation, or if they do, I've added all required information.
48 lines
1.5 KiB
Python
48 lines
1.5 KiB
Python
# coding: utf8
|
|
from __future__ import unicode_literals
|
|
|
|
import pytest
|
|
from spacy.tokens import Doc
|
|
from spacy.displacy import render
|
|
from spacy.gold import iob_to_biluo
|
|
|
|
from ..util import add_vecs_to_vocab
|
|
|
|
|
|
def test_issue2219(en_vocab):
|
|
vectors = [("a", [1, 2, 3]), ("letter", [4, 5, 6])]
|
|
add_vecs_to_vocab(en_vocab, vectors)
|
|
[(word1, vec1), (word2, vec2)] = vectors
|
|
doc = Doc(en_vocab, words=[word1, word2])
|
|
assert doc[0].similarity(doc[1]) == doc[1].similarity(doc[0])
|
|
|
|
|
|
def test_issue2361(de_tokenizer):
|
|
chars = ('<', '>', '&', '"')
|
|
doc = de_tokenizer('< > & " ')
|
|
doc.is_parsed = True
|
|
doc.is_tagged = True
|
|
html = render(doc)
|
|
for char in chars:
|
|
assert char in html
|
|
|
|
|
|
def test_issue2385():
|
|
"""Test that IOB tags are correctly converted to BILUO tags."""
|
|
# fix bug in labels with a 'b' character
|
|
tags1 = ('B-BRAWLER', 'I-BRAWLER', 'I-BRAWLER')
|
|
assert iob_to_biluo(tags1) == ['B-BRAWLER', 'I-BRAWLER', 'L-BRAWLER']
|
|
# maintain support for iob1 format
|
|
tags2 = ('I-ORG', 'I-ORG', 'B-ORG')
|
|
assert iob_to_biluo(tags2) == ['B-ORG', 'L-ORG', 'U-ORG']
|
|
# maintain support for iob2 format
|
|
tags3 = ('B-PERSON', 'I-PERSON', 'B-PERSON')
|
|
assert iob_to_biluo(tags3) ==['B-PERSON', 'L-PERSON', 'U-PERSON']
|
|
|
|
|
|
@pytest.mark.parametrize('tags', [
|
|
('B-ORG', 'L-ORG'), ('B-PERSON', 'I-PERSON', 'L-PERSON'), ('U-BRAWLER', 'U-BRAWLER')])
|
|
def test_issue2385_biluo(tags):
|
|
"""Test that BILUO-compatible tags aren't modified."""
|
|
assert iob_to_biluo(tags) == list(tags)
|