|
1 | 1 | """Tests for the public API functionality.""" |
2 | 2 |
|
3 | | -import os |
| 3 | +import concurrent.futures |
4 | 4 |
|
5 | 5 | import pytest |
6 | 6 |
|
7 | 7 | from language_tool_python.exceptions import RateLimitError |
8 | 8 |
|
9 | | -pytestmark = pytest.mark.skipif( |
10 | | - os.getenv("GITHUB_ACTIONS") == "true", |
11 | | - reason="Skip public API test on CI (depends on external service).", |
12 | | -) |
13 | 9 |
|
14 | | - |
15 | | -def test_remote_es() -> None: |
| 10 | +def run_test_remote_es() -> None: |
16 | 11 | """ |
17 | 12 | Test the public API with Spanish language text. |
18 | 13 | This test verifies that the LanguageToolPublicAPI correctly identifies |
19 | 14 | various errors in a Spanish text sample. |
20 | 15 |
|
21 | 16 | :raises AssertionError: If the detected matches do not match the expected output. |
22 | 17 | """ |
| 18 | + |
| 19 | + print("Running Spanish public API test...") |
| 20 | + |
23 | 21 | import language_tool_python |
24 | 22 |
|
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