11"""
22Tests for stop-words
33"""
4+ import random
45from unittest import TestCase
56from unittest import TestSuite
67from unittest import TestLoader
78
89import stop_words
9- from stop_words import StopWordError
1010from stop_words import get_stop_words
1111from stop_words import safe_get_stop_words
12+ from stop_words import StopWordError
1213from stop_words import STOP_WORDS_CACHE
14+ from stop_words import LANGUAGE_MAPPING
15+ from stop_words import AVAILABLE_LANGUAGES
1316
1417
1518class StopWordsTestCase (TestCase ):
@@ -29,7 +32,7 @@ def test_get_stop_words_cache(self):
2932 sw = get_stop_words ('fr' )
3033 self .assertTrue ('french' in STOP_WORDS_CACHE )
3134 original_stop_words_dir = stop_words .STOP_WORDS_DIR
32- stop_words .STOP_WORDS_DIR = '/trash/ '
35+ stop_words .STOP_WORDS_DIR = 'not-existing-directory '
3336 self .assertEqual (sw , get_stop_words ('french' ))
3437 stop_words .STOP_WORDS_DIR = original_stop_words_dir
3538 try :
@@ -43,14 +46,23 @@ def test_get_stop_words_unavailable_language(self):
4346
4447 def test_get_stop_words_install_issue (self ):
4548 original_stop_words_dir = stop_words .STOP_WORDS_DIR
46- stop_words .STOP_WORDS_DIR = '/trash/ '
49+ stop_words .STOP_WORDS_DIR = 'not-existing-directory '
4750 self .assertRaises (StopWordError , get_stop_words , 'german' )
4851 stop_words .STOP_WORDS_DIR = original_stop_words_dir
4952
5053 def test_safe_get_stop_words (self ):
5154 self .assertRaises (StopWordError , get_stop_words , 'huttese' )
5255 self .assertEqual (safe_get_stop_words ('huttese' ), [])
5356
57+ def test_random_language_stop_words_load (self ):
58+ languages = list (LANGUAGE_MAPPING .keys ()) + list (AVAILABLE_LANGUAGES )
59+ sample = random .sample (languages , len (languages ))
60+ for language in sample :
61+ stop_words = safe_get_stop_words (language )
62+ self .assertTrue (
63+ len (stop_words ) > 0 ,
64+ 'Cannot load stopwords for {0} language' .format (language )
65+ )
5466
5567loader = TestLoader ()
5668
0 commit comments