From 9ca5209864f501bd6f37dd8c47b80908943a0506 Mon Sep 17 00:00:00 2001 From: Dev Aggarwal Date: Tue, 25 Jun 2024 23:06:00 +0530 Subject: [PATCH] fix translation tests --- .github/workflows/python-tests.yml | 3 +++ glossary_resources/tests.py | 6 +---- tests/test_translation.py | 36 +++++++++++++++++++++++------- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index a50ccc382..36537db39 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -101,5 +101,8 @@ jobs: AZURE_SPEECH_KEY: ${{ secrets.AZURE_SPEECH_KEY }} AZURE_FORM_RECOGNIZER_ENDPOINT: ${{ secrets.AZURE_FORM_RECOGNIZER_ENDPOINT }} AZURE_FORM_RECOGNIZER_KEY: ${{ secrets.AZURE_FORM_RECOGNIZER_KEY }} + TEST_SLACK_TEAM_ID: ${{ secrets.TEST_SLACK_TEAM_ID }} + TEST_SLACK_USER_ID: ${{ secrets.TEST_SLACK_USER_ID }} + TEST_SLACK_AUTH_TOKEN: ${{ secrets.TEST_SLACK_AUTH_TOKEN }} run: | poetry run ./scripts/run-tests.sh diff --git a/glossary_resources/tests.py b/glossary_resources/tests.py index 362e3c759..9fa9bf5f6 100644 --- a/glossary_resources/tests.py +++ b/glossary_resources/tests.py @@ -67,11 +67,7 @@ def glossary_url(): @pytest.mark.django_db def test_run_google_translate_glossary(glossary_url, threadpool_subtest): for text, expected, expected_with_glossary in TRANSLATION_TESTS_GLOSSARY: - threadpool_subtest( - _test_run_google_translate_one, - text, - expected, - ) + threadpool_subtest(_test_run_google_translate_one, text, expected) threadpool_subtest( _test_run_google_translate_one, text, diff --git a/tests/test_translation.py b/tests/test_translation.py index d3bf7318a..5d819653a 100644 --- a/tests/test_translation.py +++ b/tests/test_translation.py @@ -5,50 +5,70 @@ TRANSLATION_TESTS = [ # hindi romanized ( + "hi", "Hi Sir Mera khet me mircha ke ped me fal gal Kar gir hai to iske liye ham kon sa dawa de please help me", "hi sir in my field the fruits of chilli tree are rotting and falling so which medicine should i give for this please help", ), ( + "hi", "Mirchi ka ped", "pepper tree", ), # telugu ( + "te", "90 రోజుల తర్వాత మిర్చి తోటలో ఏమేమి పోషకాలు వేసి వేయాలి", "after 90 days what nutrients should be added to the pepper garden?", ), # swahili ( + "sw", "Unastahili kuchanganya mchanga na nini unapopanda kahawa?", "What should you mix sand with when planting coffee?", ), # amharic ( + "am", "ለዘር የሚሆን የስንዴ ምርጥ ዘር ዓይነት ስንት ናቸው?እንደ ሀገረችን እትዮጵያ ደረጃ?", "What are the best types of wheat for seed? According to our country, Ethiopia?", ), + # spanish + ( + "es", + "hola senor me gusta el chile", + "hello sir, i like chili", + ), # english ( + "en", "what is the best type of wheat for seed?", "what is the best type of wheat for seed?", ), - ( - "hola senor me gusta el chile", - "hello sir, i like chili", - ), ] def test_run_google_translate(threadpool_subtest): - for text, expected in TRANSLATION_TESTS: - threadpool_subtest(_test_run_google_translate_one, text, expected) + for lang, text, expected in TRANSLATION_TESTS: + threadpool_subtest( + _test_run_google_translate_one, text, expected, source_language=lang + ) @flaky def _test_run_google_translate_one( - text: str, expected: str, glossary_url=None, target_lang="en" + text: str, + expected: str, + *, + glossary_url: str = None, + target_language: str = "en", + source_language: str = None ): - actual = run_google_translate([text], target_lang, glossary_url=glossary_url)[0] + actual = run_google_translate( + texts=[text], + target_language=target_language, + source_language=source_language, + glossary_url=glossary_url, + )[0] assert ( actual.replace(".", "").replace(",", "").strip().lower() == expected.replace(".", "").replace(",", "").strip().lower()