Skip to content

Commit f8ee5dc

Browse files
committed
fix (test_api_public): patch a bug in API test (get request freezed)
1 parent e6b6b99 commit f8ee5dc

File tree

2 files changed

+30
-21
lines changed

2 files changed

+30
-21
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ name: language_tool_python CI
55

66
on:
77
push:
8-
branches: [ master ]
8+
branches: [ "master" ]
99
pull_request:
10-
branches: [ master ]
10+
branches: [ "master" ]
1111

1212
jobs:
1313
tests:
@@ -52,7 +52,7 @@ jobs:
5252
5353
- name: Test with pytest
5454
run: |
55-
pytest --dist=loadfile -n auto
55+
pytest --dist=loadfile -n auto -s
5656
5757
lint:
5858
name: Lint with Ruff

tests/test_api_public.py

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,44 @@
11
"""Tests for the public API functionality."""
22

3-
import os
3+
import concurrent.futures
44

55
import pytest
66

77
from language_tool_python.exceptions import RateLimitError
88

9-
pytestmark = pytest.mark.skipif(
10-
os.getenv("GITHUB_ACTIONS") == "true",
11-
reason="Skip public API test on CI (depends on external service).",
12-
)
139

14-
15-
def test_remote_es() -> None:
10+
def run_test_remote_es() -> None:
1611
"""
1712
Test the public API with Spanish language text.
1813
This test verifies that the LanguageToolPublicAPI correctly identifies
1914
various errors in a Spanish text sample.
2015
2116
:raises AssertionError: If the detected matches do not match the expected output.
2217
"""
18+
19+
print("Running Spanish public API test...")
20+
2321
import language_tool_python
2422

25-
try:
26-
with language_tool_python.LanguageToolPublicAPI("es") as tool:
27-
es_text = "Escriba un texto aquí. LanguageTool le ayudará a afrentar algunas dificultades propias de la escritura. Se a hecho un esfuerzo para detectar errores tipográficos, ortograficos y incluso gramaticales. También algunos errores de estilo, a grosso modo."
28-
matches = tool.check(es_text)
29-
assert (
30-
str(matches)
31-
== """[Match({'rule_id': 'AFRENTAR_DIFICULTADES', 'message': 'Confusión entre «afrontar» y «afrentar».', 'replacements': ['afrontar'], 'offset_in_context': 43, 'context': '...n texto aquí. LanguageTool le ayudará a afrentar algunas dificultades propias de la escr...', 'offset': 49, 'error_length': 8, 'category': 'INCORRECT_EXPRESSIONS', 'rule_issue_type': 'grammar', 'sentence': 'LanguageTool le ayudará a afrentar algunas dificultades propias de la escritura.'}), Match({'rule_id': 'PRON_HABER_PARTICIPIO', 'message': 'El v. ‘haber’ se escribe con hache.', 'replacements': ['ha'], 'offset_in_context': 43, 'context': '...ificultades propias de la escritura. Se a hecho un esfuerzo para detectar errores...', 'offset': 107, 'error_length': 1, 'category': 'MISSPELLING', 'rule_issue_type': 'misspelling', 'sentence': 'Se a hecho un esfuerzo para detectar errores tipográficos, ortograficos y incluso gramaticales.'}), Match({'rule_id': 'MORFOLOGIK_RULE_ES', 'message': 'Se ha encontrado un posible error ortográfico.', 'replacements': ['ortográficos', 'ortográficas', 'ortográfico', 'orográficos', 'ortografiaos', 'ortografíeos'], 'offset_in_context': 43, 'context': '...rzo para detectar errores tipográficos, ortograficos y incluso gramaticales. También algunos...', 'offset': 163, 'error_length': 12, 'category': 'TYPOS', 'rule_issue_type': 'misspelling', 'sentence': 'Se a hecho un esfuerzo para detectar errores tipográficos, ortograficos y incluso gramaticales.'}), Match({'rule_id': 'Y_E_O_U', 'message': 'Cuando precede a palabras que comienzan por ‘i’, la conjunción ‘y’ se transforma en ‘e’.', 'replacements': ['e'], 'offset_in_context': 43, 'context': '...ctar errores tipográficos, ortograficos y incluso gramaticales. También algunos e...', 'offset': 176, 'error_length': 1, 'category': 'GRAMMAR', 'rule_issue_type': 'grammar', 'sentence': 'Se a hecho un esfuerzo para detectar errores tipográficos, ortograficos y incluso gramaticales.'}), Match({'rule_id': 'GROSSO_MODO', 'message': 'Esta expresión latina se usa sin preposición.', 'replacements': ['grosso modo'], 'offset_in_context': 43, 'context': '...les. También algunos errores de estilo, a grosso modo.', 'offset': 235, 'error_length': 13, 'category': 'GRAMMAR', 'rule_issue_type': 'grammar', 'sentence': 'También algunos errores de estilo, a grosso modo.'})]"""
32-
)
33-
except RateLimitError:
34-
print("Rate limit error: skipping test about public API.")
35-
return
23+
with language_tool_python.LanguageToolPublicAPI("es") as tool:
24+
es_text = "Escriba un texto aquí. LanguageTool le ayudará a afrentar algunas dificultades propias de la escritura. Se a hecho un esfuerzo para detectar errores tipográficos, ortograficos y incluso gramaticales. También algunos errores de estilo, a grosso modo."
25+
print(es_text)
26+
matches = tool.check(es_text)
27+
print(matches)
28+
assert (
29+
str(matches)
30+
== """[Match({'rule_id': 'AFRENTAR_DIFICULTADES', 'message': 'Confusión entre «afrontar» y «afrentar».', 'replacements': ['afrontar'], 'offset_in_context': 43, 'context': '...n texto aquí. LanguageTool le ayudará a afrentar algunas dificultades propias de la escr...', 'offset': 49, 'error_length': 8, 'category': 'INCORRECT_EXPRESSIONS', 'rule_issue_type': 'grammar', 'sentence': 'LanguageTool le ayudará a afrentar algunas dificultades propias de la escritura.'}), Match({'rule_id': 'PRON_HABER_PARTICIPIO', 'message': 'El v. ‘haber’ se escribe con hache.', 'replacements': ['ha'], 'offset_in_context': 43, 'context': '...ificultades propias de la escritura. Se a hecho un esfuerzo para detectar errores...', 'offset': 107, 'error_length': 1, 'category': 'MISSPELLING', 'rule_issue_type': 'misspelling', 'sentence': 'Se a hecho un esfuerzo para detectar errores tipográficos, ortograficos y incluso gramaticales.'}), Match({'rule_id': 'MORFOLOGIK_RULE_ES', 'message': 'Se ha encontrado un posible error ortográfico.', 'replacements': ['ortográficos', 'ortográficas', 'ortográfico', 'orográficos', 'ortografiaos', 'ortografíeos'], 'offset_in_context': 43, 'context': '...rzo para detectar errores tipográficos, ortograficos y incluso gramaticales. También algunos...', 'offset': 163, 'error_length': 12, 'category': 'TYPOS', 'rule_issue_type': 'misspelling', 'sentence': 'Se a hecho un esfuerzo para detectar errores tipográficos, ortograficos y incluso gramaticales.'}), Match({'rule_id': 'Y_E_O_U', 'message': 'Cuando precede a palabras que comienzan por ‘i’, la conjunción ‘y’ se transforma en ‘e’.', 'replacements': ['e'], 'offset_in_context': 43, 'context': '...ctar errores tipográficos, ortograficos y incluso gramaticales. También algunos e...', 'offset': 176, 'error_length': 1, 'category': 'GRAMMAR', 'rule_issue_type': 'grammar', 'sentence': 'Se a hecho un esfuerzo para detectar errores tipográficos, ortograficos y incluso gramaticales.'}), Match({'rule_id': 'GROSSO_MODO', 'message': 'Esta expresión latina se usa sin preposición.', 'replacements': ['grosso modo'], 'offset_in_context': 43, 'context': '...les. También algunos errores de estilo, a grosso modo.', 'offset': 235, 'error_length': 13, 'category': 'GRAMMAR', 'rule_issue_type': 'grammar', 'sentence': 'También algunos errores de estilo, a grosso modo.'})]"""
31+
)
32+
33+
34+
def test_remote_es() -> None:
35+
"""Wrapper to run the Spanish public API test with a timeout."""
36+
with concurrent.futures.ThreadPoolExecutor() as executor:
37+
future = executor.submit(run_test_remote_es)
38+
print("Submitted Spanish public API test...")
39+
try:
40+
future.result(timeout=60)
41+
except RateLimitError:
42+
pytest.skip("Rate limit exceeded for public API.")
43+
except concurrent.futures.TimeoutError:
44+
pytest.fail("Test for remote Spanish API timed out.")

0 commit comments

Comments
 (0)