From 96b6a0b001e009eec37044d3016774ff24e078c6 Mon Sep 17 00:00:00 2001 From: Chris Caron Date: Sun, 20 Aug 2023 20:37:54 -0400 Subject: [PATCH] more windows edge case testing --- test/test_apprise_translations.py | 43 +++++++++++++++---------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/test/test_apprise_translations.py b/test/test_apprise_translations.py index 5b0c92d88c..a42d80251f 100644 --- a/test/test_apprise_translations.py +++ b/test/test_apprise_translations.py @@ -220,7 +220,7 @@ def test_apprise_trans_add(): @pytest.mark.skipif( - sys.platform != "win32", reason="Unique Windows test cases") + not hasattr(ctypes, 'windll'), reason="Unique Windows test cases") @pytest.mark.skipif( 'gettext' not in sys.modules, reason="Requires gettext") def test_apprise_trans_detect_language_windows_users(): @@ -229,34 +229,33 @@ def test_apprise_trans_detect_language_windows_users(): """ - if hasattr(ctypes, 'windll'): - from ctypes import windll + with mock.patch( + 'ctypes.windll.kernel32.GetUserDefaultUILanguage') as ui_lang: - else: - windll = mock.Mock() # 4105 = en_CA - windll.kernel32.GetUserDefaultUILanguage.return_value = 4105 - setattr(ctypes, 'windll', windll) + ui_lang.return_value = 4105 - with environ('LANGUAGE', 'LC_ALL', 'LC_CTYPE', 'LANG'): - # Our default language - AppriseLocale.AppriseLocale._default_language = 'zz' + with environ('LANGUAGE', 'LC_ALL', 'LC_CTYPE', 'LANG'): + # Our default language which won't get picked because we'll match + # our detected windows environment + AppriseLocale.AppriseLocale._default_language = 'zz' - # We will pick up the windll module - assert AppriseLocale.AppriseLocale.detect_language() == 'en' + # We will pick up the windll module + assert AppriseLocale.AppriseLocale.detect_language() == 'en' - # The below accesses the windows fallback code - with environ('LANG', 'LANGUAGE', 'LC_ALL', 'LC_CTYPE', LANG="fr_CA"): - assert AppriseLocale.AppriseLocale.detect_language() == 'fr' + # The below accesses the windows fallback code + with environ('LANG', 'LANGUAGE', 'LC_ALL', 'LC_CTYPE', LANG="fr_CA"): + # Environment variables trump detected windll library and + # locale() calls + assert AppriseLocale.AppriseLocale.detect_language() == 'fr' - assert AppriseLocale.AppriseLocale\ - .detect_language(detect_fallback=False) is None + assert AppriseLocale.AppriseLocale\ + .detect_language(detect_fallback=False) is None - # 0 = IndexError - windll.kernel32.GetUserDefaultUILanguage.return_value = 0 - setattr(ctypes, 'windll', windll) - with environ('LANG', 'LC_ALL', 'LC_CTYPE', LANGUAGE="en_CA"): - assert AppriseLocale.AppriseLocale.detect_language() == 'en' + # 0 = IndexError + ui_lang.return_value = 0 + with environ('LANG', 'LC_ALL', 'LC_CTYPE', LANGUAGE="en_CA"): + assert AppriseLocale.AppriseLocale.detect_language() == 'en' @pytest.mark.skipif(sys.platform == "win32", reason="Unique Nux test cases")