Browse Source

Add test for the default language case

doc-issue-template
MrS0m30n3 7 years ago
parent
commit
c4fa38ba8b
1 changed files with 31 additions and 0 deletions
  1. 31
      tests/test_utils.py

31
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))) sys.path.insert(0, os.path.dirname(os.path.dirname(PATH)))
try: try:
import mock
from youtube_dl_gui import utils from youtube_dl_gui import utils
except ImportError as error: except ImportError as error:
print error print error
@ -174,6 +176,35 @@ class TestConvertItem(unittest.TestCase):
self.check_iter(self.input_dict_s, dict, True) 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(): def main():
unittest.main() unittest.main()

Loading…
Cancel
Save