-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: display explicit error message when model not downloaded
For a couple of functionalities, we need to load a spacy model that is not included by default. The developer has to download it manually in addition to the package. If the model is not present locally, an error will occur. The message is not meaningful. This commit will make it more explicit.
- Loading branch information
1 parent
8094379
commit 254c4d1
Showing
2 changed files
with
44 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import pytest | ||
import spacy | ||
from nlpretext.token.tokenizer import SpacyModel, LanguageNotInstalledError | ||
|
||
@pytest.mark.parametrize( | ||
"fake_input, expected_model_in_message", | ||
[ | ||
("en", "en_core_web_sm"), | ||
("fr", "fr_core_news_sm") | ||
] | ||
) | ||
def test_get_spacy_tokenizer_when_model_not_downloaded(monkeypatch, fake_input, expected_model_in_message): | ||
|
||
def mock_spacy_load(lang): | ||
raise OSError( | ||
"[E050] Can't find model 'en_core_web_sm'. It doesn't seem to be ..." | ||
) | ||
|
||
monkeypatch.setattr(spacy, "load", mock_spacy_load) | ||
with pytest.raises(LanguageNotInstalledError) as e: | ||
SpacyModel.SingletonSpacyModel(fake_input) | ||
assert expected_model_in_message in str(e.value) |