From c4fa38ba8bd71ca4dcd7b8c217c58e7b8da5d191 Mon Sep 17 00:00:00 2001 From: MrS0m30n3 Date: Sat, 9 Dec 2017 19:07:05 +0200 Subject: [PATCH] Add test for the default language case --- tests/test_utils.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/test_utils.py b/tests/test_utils.py index 47fa138..38936b5 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -13,6 +13,8 @@ PATH = os.path.realpath(os.path.abspath(__file__)) sys.path.insert(0, os.path.dirname(os.path.dirname(PATH))) try: + import mock + from youtube_dl_gui import utils except ImportError as error: print error @@ -174,6 +176,35 @@ class TestConvertItem(unittest.TestCase): self.check_iter(self.input_dict_s, dict, True) +class TestGetDefaultLang(unittest.TestCase): + + """Test case for the get_default_lang function.""" + + @mock.patch("youtube_dl_gui.utils.locale_getdefaultlocale") + def run_tests(self, ret_value, result, mock_getdefaultlocale): + """Run the main test. + + Args: + ret_value (tuple): Return tuple of the locale.getdefaultlocale module + result (unicode): Result we want to see + mock_getdefaultlocale (MagicMock): Mock object + """ + mock_getdefaultlocale.return_value = ret_value + lang = utils.get_default_lang() + + mock_getdefaultlocale.assert_called_once() + self.assertEqual(lang, result) + + def test_get_default_lang(self): + self.run_tests(("it_IT", "UTF-8"), "it_IT") + + def test_get_default_lang_none(self): + self.run_tests((None, None), "en_US") + + def test_get_default_lang_empty(self): + self.run_tests(("", ""), "en_US") + + def main(): unittest.main()