Skip to content

Commit

Permalink
add test case for when spell check is required but hunspell import is…
Browse files Browse the repository at this point in the history
… not available (#28)
  • Loading branch information
suzinyou authored Apr 6, 2023
1 parent 4844ed3 commit 69447fd
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/test_preprocessing/test_preprocess_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,22 @@ def test_check_gibberish_with_spell_check(self, tokens, expected):
)
def test_check_gibberish_without_spell_check(self, tokens, expected):
assert is_gibberish(tokens, spell_check=False) == expected

def test_import_error_raised_if_hunspell_unavailable_and_token_list_length_is_1(
self,
):
# Patch the module-level global variable that's set during import
import faqt

faqt.preprocessing.tokens._has_hunspell = False

with pytest.raises(ImportError, match=r"Could not import hunspell library."):
is_gibberish(["hello"], spell_check=True)

# Set correct values at the end of test
try:
from hunspell import Hunspell
except ImportError:
faqt.preprocessing.tokens._has_hunspell = False
else:
faqt.preprocessing.tokens._has_hunspell = True

0 comments on commit 69447fd

Please sign in to comment.