Skip to content

Commit

Permalink
more windows edge case testing
Browse files Browse the repository at this point in the history
  • Loading branch information
caronc committed Aug 21, 2023
1 parent f159dc6 commit 96b6a0b
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions test/test_apprise_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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")
Expand Down

0 comments on commit 96b6a0b

Please sign in to comment.