From 0b75b4e46728c4a3f43849b5d1b44e8e36609f2f Mon Sep 17 00:00:00 2001 From: Omar Agiez Date: Thu, 17 Oct 2024 01:39:25 +0300 Subject: [PATCH] Add unit tests for language formatting and listing: - Positive and negative tests for format_sublanguage_name - Test to validate the output of list_all_languages --- tests/load/test_update_utils.py | 66 +++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tests/load/test_update_utils.py b/tests/load/test_update_utils.py index 489abc4b8..df37317a3 100644 --- a/tests/load/test_update_utils.py +++ b/tests/load/test_update_utils.py @@ -163,6 +163,72 @@ def test_get_language_from_iso_negative(): assert str(excp.value) == "IXI is currently not a supported ISO language." +@pytest.mark.parametrize( + "lang, expected_output", + [ + ("nynorsk", "Norwegian/Nynorsk"), + ("bokmål", "Norwegian/Bokmål"), + ("english", "English"), + ], +) +def test_format_sublanguage_name_positive(lang, expected_output): + assert utils.format_sublanguage_name(lang) == expected_output + + +def test_format_sublanguage_name_negative(): + with pytest.raises(ValueError) as excp: + _ = utils.format_sublanguage_name("soccer") + + assert str(excp.value) == "SOCCER is not a valid language or sub-language." + + +def test_list_all_languages(): + expected_languages = [ + "arabic", + "basque", + "bengali", + "czech", + "danish", + "english", + "esperanto", + "estonian", + "finnish", + "french", + "german", + "greek", + "hausa", + "hebrew", + "hindi", + "urdu", + "indonesian", + "italian", + "japanese", + "kurmanji", + "latin", + "malay", + "malayalam", + "mandarin", + "nynorsk", + "bokmål", + "nigerian", + "polish", + "portuguese", + "shahmukhi", + "gurmukhi", + "russian", + "slovak", + "spanish", + "swahili", + "swedish", + "tajik", + "tamil", + "ukrainian", + "yoruba", + ] + + assert utils.list_all_languages() == expected_languages + + def test_get_ios_data_path(): assert ( utils.get_ios_data_path("suomi")