From dca6f6fa315562e9ebb40e5c6a01247e6b51ef6d Mon Sep 17 00:00:00 2001 From: BLKSerene Date: Mon, 16 Oct 2023 11:21:31 +0800 Subject: [PATCH] Make return values of laonlp.translate.word_dictionary consistent with type hint --- laonlp/translate/mopt_dict.py | 6 +++--- tests/test_translate.py | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/laonlp/translate/mopt_dict.py b/laonlp/translate/mopt_dict.py index 2393f72..098428e 100644 --- a/laonlp/translate/mopt_dict.py +++ b/laonlp/translate/mopt_dict.py @@ -21,12 +21,12 @@ def dictionary(word: str, src: str, target: str) -> list: if src == "lao" and target == "eng": _temp = mopt_dict.get_lao_eng() if word not in list(_temp.keys()): - return None + return [] return _temp[word] elif src == "eng" and target == "lao": _temp = mopt_dict.get_eng_lao() if word not in list(_temp.keys()): - return None + return [] return _temp[word] else: - return word + return [word] diff --git a/tests/test_translate.py b/tests/test_translate.py index 39d2ba5..9e5b486 100644 --- a/tests/test_translate.py +++ b/tests/test_translate.py @@ -6,4 +6,8 @@ class TestTagPackage(unittest.TestCase): def test_word_dictionary(self): - self.assertIsNotNone(word_dictionary("cat", "en", "lao")) + self.assertNotEqual(word_dictionary("cat", "eng", "lao"), ["cat"]) + self.assertNotEqual(word_dictionary("ມັດ້າຣະ", "lao", "eng"), ["ມັດ້າຣະ"]) + self.assertEqual(word_dictionary("nonexistent_word", "eng", "lao"), []) + self.assertEqual(word_dictionary("nonexistent_word", "lao", "eng"), []) + self.assertEqual(word_dictionary("nonexistent_word", "test", "test"), ["nonexistent_word"])