Skip to content

Commit

Permalink
fix translation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
devxpy committed Jun 25, 2024
1 parent 8a323a9 commit 9ca5209
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 1 addition & 5 deletions glossary_resources/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
36 changes: 28 additions & 8 deletions tests/test_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 9ca5209

Please sign in to comment.