Skip to content

Commit

Permalink
fix: do not fail when the lang code is invalid
Browse files Browse the repository at this point in the history
plus, adjust the test suite to the updated code
  • Loading branch information
joanise authored and roedoejet committed Feb 28, 2023
1 parent 04eb40e commit 3b2a433
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
4 changes: 2 additions & 2 deletions readalongs/text/convert_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ def convert_word(word: str, lang: str):
if g2p_fallback_warning_count < 2 or verbose_warnings:
g2p_fallback_warning_count += 1
LOGGER.warning(
f'Could not g2p "{text_to_g2p}" as {langs[g2p_lang]} ({g2p_lang}). '
f"Trying fallback: {langs[lang]} ({lang})."
f'Could not g2p "{text_to_g2p}" as {langs.get(g2p_lang, "")} ({g2p_lang}). '
f"Trying fallback: {langs.get(lang, '')} ({lang})."
)
g2p_lang = lang.strip()
g2p_text, valid = convert_word(text_to_g2p, g2p_lang)
Expand Down
7 changes: 4 additions & 3 deletions test/test_g2p_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def test_three_way_fallback(self):
)
results = self.runner.invoke(g2p, [tok_file2, "-"])
self.assertEqual(results.exit_code, 0)
self.assertIn("Trying fallback: und", results.output)
self.assertIn("Trying fallback: Und", results.output)

def test_align_with_error(self):
"""handling g2p errors in readalongs align with --g2p-fallback"""
Expand Down Expand Up @@ -251,6 +251,7 @@ def test_align_with_error(self):
"eng", # lang 1 is eng
"-f",
"--language=fra:iku", # fallback langs are fra and iku
"--debug-g2p",
text_file,
os.path.join(self.data_dir, "noise.mp3"),
output_dir,
Expand All @@ -262,8 +263,8 @@ def test_align_with_error(self):
f"results.output='{results.output}' "
f"results.exception={results.exception!r}"
)
self.assertIn("Trying fallback: fra", results.output)
self.assertIn("Trying fallback: iku", results.output)
self.assertIn("Trying fallback: French", results.output)
self.assertIn("Trying fallback: Inuktitut", results.output)
self.assertNotIn("could not be g2p", results.output)
self.assertIn("Number of aligned segments", results.output)

Expand Down
11 changes: 2 additions & 9 deletions test/test_web_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,7 @@ def test_empty_g2p(self):
response = API_CLIENT.post("/api/v1/assemble", json=request)
self.assertEqual(response.status_code, 200)
content_log = response.json()["log"]
for message_part in [
"The g2p output for",
"24",
"23",
"99",
"1234",
"is empty",
]:
for message_part in ["The output of the g2p process", "24", "23", "is empty"]:
self.assertIn(message_part, content_log)

def test_langs(self):
Expand All @@ -164,7 +157,7 @@ def test_logs(self):
response = API_CLIENT.post("/api/v1/assemble", json=request)
content = response.json()
# print("Content", content)
self.assertIn('Could not g2p "ña" as fra', content["log"])
self.assertIn('Could not g2p "ña" as French', content["log"])

def test_debug(self):
# Test the assemble endpoint with debug mode on
Expand Down

0 comments on commit 3b2a433

Please sign in to comment.