1111
1212
1313class TestLanguageTool (unittest .TestCase ):
14- Test = namedtuple ("Test " , ("text" , "matches" ))
14+ CheckTest = namedtuple ("CheckTest " , ("text" , "matches" ))
1515 Match = namedtuple ("Match" , ("fromy" , "fromx" , "ruleId" ))
1616
17- tests = {
17+ check_tests = {
1818 "en" : [
19- Test (
19+ CheckTest (
2020 ("Paste your own text here... or check this text too see "
2121 "a few of the problems that that LanguageTool can detect. "
2222 "Did you notice that their is no spelcheckin included?" ),
@@ -27,7 +27,7 @@ class TestLanguageTool(unittest.TestCase):
2727 ),
2828 ],
2929 "fr" : [
30- Test (
30+ CheckTest (
3131 ("Se texte est un exemple pour pour vous montrer "
3232 "le fonctionnement de LanguageTool. "
3333 "notez que LanguageTool ne comporte pas "
@@ -39,33 +39,44 @@ class TestLanguageTool(unittest.TestCase):
3939 Match (0 , 82 , "UPPERCASE_SENTENCE_START" ),
4040 ]
4141 ),
42- Test (
43- "C'est un soucis, comme même !" ,
42+ CheckTest (
43+ "je me rappelle de tout sans aucun soucis !" ,
4444 [
45- Match (0 , 6 , "ACCORD_NOMBRE" ),
46- Match (0 , 17 , "COMME_MEME" ),
47- Match (0 , 23 , "FRENCH_WHITESPACE" ),
45+ Match (0 , 0 , "UPPERCASE_SENTENCE_START" ),
46+ Match (0 , 6 , "RAPPELER_DE" ),
47+ Match (0 , 28 , "ACCORD_NOMBRE" ),
48+ Match (0 , 34 , "FRENCH_WHITESPACE" ),
4849 ]
4950 ),
5051 ],
51- "ja" : [
52- Test ("日本語" , []),
53- ],
5452 }
5553
56- def test_samples (self ):
57- languages = language_tool .get_languages ()
58- for language , tests in self .tests .items ():
59- if language not in languages :
54+ correct_tests = {
55+ "en-US" : {
56+ "that would of been to impressive." :
57+ "That would have been too impressive." ,
58+ },
59+ "fr" : {
60+ "il monte en haut si il veut." :
61+ "Il monte s’il veut." ,
62+ },
63+ }
64+
65+ def setUp (self ):
66+ self .lang_tool = language_tool .LanguageTool ()
67+
68+ def test_check (self ):
69+ for language , tests in self .check_tests .items ():
70+ try :
71+ self .lang_tool .language = language
72+ except ValueError :
6073 version = language_tool .get_version ()
6174 warnings .warn (
6275 "LanguageTool {} doesn’t support language {!r}"
6376 .format (version , language )
6477 )
65- continue
66- lang_tool = language_tool .LanguageTool (language )
6778 for text , expected_matches in tests :
68- matches = lang_tool .check (text )
79+ matches = self . lang_tool .check (text )
6980 for expected_match in expected_matches :
7081 for match in matches :
7182 if (
@@ -78,6 +89,19 @@ def test_samples(self):
7889 raise IndexError (
7990 "can’t find {!r}" .format (expected_match ))
8091
92+ def test_correct (self ):
93+ for language , tests in self .correct_tests .items ():
94+ try :
95+ self .lang_tool .language = language
96+ except ValueError :
97+ version = language_tool .get_version ()
98+ warnings .warn (
99+ "LanguageTool {} doesn’t support language {!r}"
100+ .format (version , language )
101+ )
102+ for text , result in tests .items ():
103+ self .assertEqual (self .lang_tool .correct (text ), result )
104+
81105 def test_languages (self ):
82106 languages = language_tool .get_languages ()
83107 self .assertIn ("en" , languages )
0 commit comments