From 3b2a433d2b8f5e3e043f1b8ad1eafc16aa041802 Mon Sep 17 00:00:00 2001 From: Eric Joanis Date: Tue, 28 Feb 2023 13:46:44 -0500 Subject: [PATCH] fix: do not fail when the lang code is invalid plus, adjust the test suite to the updated code --- readalongs/text/convert_xml.py | 4 ++-- test/test_g2p_cli.py | 7 ++++--- test/test_web_api.py | 11 ++--------- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/readalongs/text/convert_xml.py b/readalongs/text/convert_xml.py index 115caf54..18bac10f 100644 --- a/readalongs/text/convert_xml.py +++ b/readalongs/text/convert_xml.py @@ -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) diff --git a/test/test_g2p_cli.py b/test/test_g2p_cli.py index 57a052b0..e60a502d 100755 --- a/test/test_g2p_cli.py +++ b/test/test_g2p_cli.py @@ -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""" @@ -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, @@ -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) diff --git a/test/test_web_api.py b/test/test_web_api.py index 9553912f..9333f0a8 100755 --- a/test/test_web_api.py +++ b/test/test_web_api.py @@ -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): @@ -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