Skip to content

Commit fb7acac

Browse files
danieldkJon
authored andcommitted
python3Packages.spacy: add passthru test
I have been using the main example of the spaCy web page for testing updates of spacy (and its transitive dependencies). Let's convert this into a proper test to take out manual testing.
1 parent 9b55e5b commit fb7acac

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import pytest
2+
import spacy
3+
4+
en_text = (
5+
"When Sebastian Thrun started working on self-driving cars at "
6+
"Google in 2007, few people outside of the company took him "
7+
"seriously. “I can tell you very senior CEOs of major American "
8+
"car companies would shake my hand and turn away because I wasn’t "
9+
"worth talking to,” said Thrun, in an interview with Recode earlier "
10+
"this week.")
11+
12+
13+
@pytest.fixture
14+
def en_core_web_sm():
15+
return spacy.load("en_core_web_sm")
16+
17+
18+
@pytest.fixture
19+
def doc_en_core_web_sm(en_core_web_sm):
20+
return en_core_web_sm(en_text)
21+
22+
23+
def test_entities(doc_en_core_web_sm):
24+
entities = list(map(lambda e: (e.text, e.label_),
25+
doc_en_core_web_sm.ents))
26+
27+
assert entities == [
28+
('Sebastian Thrun', 'PERSON'),
29+
('Google', 'ORG'), ('2007', 'DATE'),
30+
('American', 'NORP'),
31+
('Thrun', 'ORG'),
32+
('earlier this week', 'DATE')
33+
]
34+
35+
36+
def test_nouns(doc_en_core_web_sm):
37+
assert [
38+
chunk.text for chunk in doc_en_core_web_sm.noun_chunks] == [
39+
'Sebastian Thrun',
40+
'self-driving cars',
41+
'Google',
42+
'few people',
43+
'the company',
44+
'him',
45+
'I',
46+
'you',
47+
'very senior CEOs',
48+
'major American car companies',
49+
'my hand',
50+
'I',
51+
'Thrun',
52+
'an interview',
53+
'Recode']
54+
55+
56+
def test_verbs(doc_en_core_web_sm):
57+
assert [
58+
token.lemma_ for token in doc_en_core_web_sm if token.pos_ == "VERB"] == [
59+
'start',
60+
'work',
61+
'drive',
62+
'take',
63+
'can',
64+
'tell',
65+
'would',
66+
'shake',
67+
'turn',
68+
'talk',
69+
'say']
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{ stdenv, pytest, spacy_models }:
2+
3+
stdenv.mkDerivation {
4+
name = "spacy-annotation-test";
5+
6+
src = ./.;
7+
8+
dontConfigure = true;
9+
dontBuild = true;
10+
doCheck = true;
11+
12+
checkInputs = [ pytest spacy_models.en_core_web_sm ];
13+
14+
checkPhase = ''
15+
pytest annotate.py
16+
'';
17+
18+
installPhase = ''
19+
touch $out
20+
'';
21+
22+
meta.timeout = 60;
23+
}

pkgs/development/python-modules/spacy/default.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{ lib
22
, buildPythonPackage
3+
, callPackage
34
, fetchPypi
45
, pythonOlder
56
, pytest
@@ -64,6 +65,8 @@ buildPythonPackage rec {
6465

6566
pythonImportsCheck = [ "spacy" ];
6667

68+
passthru.tests = callPackage ./annotation-test {};
69+
6770
meta = with lib; {
6871
description = "Industrial-strength Natural Language Processing (NLP) with Python and Cython";
6972
homepage = "https://github.com/explosion/spaCy";

0 commit comments

Comments
 (0)