Skip to content

Commit 3a0d95c

Browse files
committed
add test for UK correction
1 parent 00d3ecc commit 3a0d95c

3 files changed

Lines changed: 17 additions & 8 deletions

File tree

‎language_tool_python/server.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from .utils import *
1414

1515

16-
DEBUG_MODE = False
16+
DEBUG_MODE = True
1717

1818
# Keep track of running server PIDs in a global list. This way,
1919
# we can ensure they're killed on exit.
@@ -95,7 +95,7 @@ def _spell_checking_categories(self):
9595
def check(self, text: str) -> [Match]:
9696
"""Match text against enabled rules."""
9797
url = urllib.parse.urljoin(self._url, 'check')
98-
response = self._get_root(url, self._encode(text))
98+
response = self._query_server(url, self._encode(text))
9999
matches = response['matches']
100100
return [Match(match) for match in matches]
101101

@@ -142,7 +142,7 @@ def _get_languages(self) -> set:
142142
self._start_server_if_needed()
143143
url = urllib.parse.urljoin(self._url, 'languages')
144144
languages = set()
145-
for e in self._get_root(url, num_tries=1):
145+
for e in self._query_server(url, num_tries=1):
146146
languages.add(e.get('code'))
147147
languages.add(e.get('longCode'))
148148
return languages
@@ -156,9 +156,9 @@ def _update_remote_server_config(self, url):
156156
self._url = url
157157
self._remote = True
158158

159-
def _get_root(self, url, data=None, num_tries=2):
159+
def _query_server(self, url, data=None, num_tries=2):
160160
if DEBUG_MODE:
161-
print('_get_root url:', url, 'data:', data)
161+
print('_query_server url:', url, 'data:', data)
162162
for n in range(num_tries):
163163
try:
164164
with urlopen(url, data, self._TIMEOUT) as f:

‎tests/test_major_functionality.py‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ def test_langtool_load():
33
import language_tool_python
44
lang_tool = language_tool_python.LanguageTool("en-US")
55
matches = lang_tool.check('ain\'t nothin but a thang')
6-
open('test_langtool_load', 'w').write(str(matches))
76
assert str(matches) == """[Match({'ruleId': 'UPPERCASE_SENTENCE_START', 'message': 'This sentence does not start with an uppercase letter.', 'replacements': ['Ain'], 'offsetInContext': 0, 'context': "ain't nothin but a thang", 'offset': 0, 'errorLength': 3, 'category': 'CASING', 'ruleIssueType': 'typographical', 'sentence': "ain't nothin but a thang"}), Match({'ruleId': 'MORFOLOGIK_RULE_EN_US', 'message': 'Possible spelling mistake found.', 'replacements': ['nothing', 'no thin'], 'offsetInContext': 6, 'context': "ain't nothin but a thang", 'offset': 6, 'errorLength': 6, 'category': 'TYPOS', 'ruleIssueType': 'misspelling', 'sentence': "ain't nothin but a thang"}), Match({'ruleId': 'MORFOLOGIK_RULE_EN_US', 'message': 'Possible spelling mistake found.', 'replacements': ['than', 'thing', 'hang', 'thank', 'Chang', 'tang', 'thong', 'twang', 'Thant', 'thane', 'Thanh', 't hang', 'Shang', 'Zhang'], 'offsetInContext': 19, 'context': "ain't nothin but a thang", 'offset': 19, 'errorLength': 5, 'category': 'TYPOS', 'ruleIssueType': 'misspelling', 'sentence': "ain't nothin but a thang"})]"""
87

98
def test_langtool_languages():
@@ -17,9 +16,19 @@ def test_match():
1716
text = u'A sentence with a error in the Hitchhiker’s Guide tot he Galaxy'
1817
matches = tool.check(text)
1918
assert len(matches) == 2
20-
open('test_match', 'w').write(str(matches[0]))
2119
assert str(matches[0]) == 'Offset 16, length 1, Rule ID: EN_A_VS_AN\nMessage: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’\nSuggestion: an\nA sentence with a error in the Hitchhiker’s Guide tot he ...\n ^'
2220

21+
def test_uk_typo():
22+
import language_tool_python
23+
language = language_tool_python.LanguageTool("en-UK")
24+
25+
sentence1 = "If you think this sentence is fine then, your wrong."
26+
results1 = language.check(sentence1)
27+
assert len(results1) == 1
28+
assert language_tool_python.utils.correct(sentence1, results1) == "If you think this sentence is fine then, you're wrong."
29+
30+
results2 = language.check("You're mum is called Emily, is that right?")
31+
assert len(results2) == 0
2332

2433
def test_remote_es():
2534
import language_tool_python

‎tests/test_remote.bash‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -eux
44

55
readonly port=8081
66
readonly ltp_path=$(printf "import language_tool_python\nprint(language_tool_python.utils.get_language_tool_download_path())\n" | python)
7-
readonly jar="${ltp_path}LanguageTool-*/languagetool-server.jar"
7+
readonly jar="${ltp_path}/LanguageTool-*/languagetool-server.jar"
88

99
java -cp $jar org.languagetool.server.HTTPServer --port "$port" &
1010
java_pid=$!

0 commit comments

Comments
 (0)