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.

authored by danieldk.tngl.sh and committed by Jon fb7acacd 9b55e5bf

+95
+69
pkgs/development/python-modules/spacy/annotation-test/annotate.py
··· 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']
+23
pkgs/development/python-modules/spacy/annotation-test/default.nix
··· 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 + }
+3
pkgs/development/python-modules/spacy/default.nix
··· 1 1 { lib 2 2 , buildPythonPackage 3 + , callPackage 3 4 , fetchPypi 4 5 , pythonOlder 5 6 , pytest ··· 63 64 ''; 64 65 65 66 pythonImportsCheck = [ "spacy" ]; 67 + 68 + passthru.tests = callPackage ./annotation-test {}; 66 69 67 70 meta = with lib; { 68 71 description = "Industrial-strength Natural Language Processing (NLP) with Python and Cython";