|
|
@ -24,9 +24,11 @@ |
|
|
|
# THE SOFTWARE. |
|
|
|
# THE SOFTWARE. |
|
|
|
|
|
|
|
|
|
|
|
import os |
|
|
|
import os |
|
|
|
|
|
|
|
import sys |
|
|
|
from unittest import mock |
|
|
|
from unittest import mock |
|
|
|
|
|
|
|
|
|
|
|
import ctypes |
|
|
|
import ctypes |
|
|
|
|
|
|
|
import pytest |
|
|
|
|
|
|
|
|
|
|
|
from apprise import AppriseLocale |
|
|
|
from apprise import AppriseLocale |
|
|
|
from apprise.utils import environ |
|
|
|
from apprise.utils import environ |
|
|
@ -133,7 +135,9 @@ def test_detect_language_windows_users(): |
|
|
|
|
|
|
|
|
|
|
|
""" |
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
if not hasattr(ctypes, 'windll'): |
|
|
|
if hasattr(ctypes, 'windll'): |
|
|
|
|
|
|
|
from ctypes import windll |
|
|
|
|
|
|
|
else: |
|
|
|
windll = mock.Mock() |
|
|
|
windll = mock.Mock() |
|
|
|
# 4105 = en_CA |
|
|
|
# 4105 = en_CA |
|
|
|
windll.kernel32.GetUserDefaultUILanguage.return_value = 4105 |
|
|
|
windll.kernel32.GetUserDefaultUILanguage.return_value = 4105 |
|
|
@ -152,14 +156,22 @@ def test_detect_language_windows_users(): |
|
|
|
with environ('LANG', 'LC_ALL', 'LC_CTYPE', LANGUAGE="en_CA"): |
|
|
|
with environ('LANG', 'LC_ALL', 'LC_CTYPE', LANGUAGE="en_CA"): |
|
|
|
assert AppriseLocale.AppriseLocale.detect_language() == 'en' |
|
|
|
assert AppriseLocale.AppriseLocale.detect_language() == 'en' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skipif(sys.platform == "win32", reason="Does not work on Windows") |
|
|
|
|
|
|
|
def test_detect_language_windows_users_croaks_please_review(): |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
When enabling CI testing on Windows, those tests did not produce the |
|
|
|
|
|
|
|
correct results. They may want to be reviewed. |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
# The below accesses the windows fallback code and fail |
|
|
|
# The below accesses the windows fallback code and fail |
|
|
|
# then it will resort to the environment variables |
|
|
|
# then it will resort to the environment variables. |
|
|
|
with environ('LANG', 'LANGUAGE', 'LC_ALL', 'LC_CTYPE'): |
|
|
|
with environ('LANG', 'LANGUAGE', 'LC_ALL', 'LC_CTYPE'): |
|
|
|
# Language can't be detected |
|
|
|
# Language can't be detected |
|
|
|
assert AppriseLocale.AppriseLocale.detect_language() is None |
|
|
|
assert AppriseLocale.AppriseLocale.detect_language() is None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Detect French language. |
|
|
|
with environ('LANGUAGE', 'LC_ALL', 'LC_CTYPE', LANG="fr_CA"): |
|
|
|
with environ('LANGUAGE', 'LC_ALL', 'LC_CTYPE', LANG="fr_CA"): |
|
|
|
# Detect french language |
|
|
|
|
|
|
|
assert AppriseLocale.AppriseLocale.detect_language() == 'fr' |
|
|
|
assert AppriseLocale.AppriseLocale.detect_language() == 'fr' |
|
|
|
|
|
|
|
|
|
|
|
# The following unsets all environment variables and sets LC_CTYPE |
|
|
|
# The following unsets all environment variables and sets LC_CTYPE |
|
|
@ -174,10 +186,8 @@ def test_detect_language_windows_users(): |
|
|
|
with environ(*list(os.environ.keys())): |
|
|
|
with environ(*list(os.environ.keys())): |
|
|
|
assert AppriseLocale.AppriseLocale.detect_language() is None |
|
|
|
assert AppriseLocale.AppriseLocale.detect_language() is None |
|
|
|
|
|
|
|
|
|
|
|
# Tidy |
|
|
|
|
|
|
|
delattr(ctypes, 'windll') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skipif(sys.platform == "win32", reason="Does not work on Windows") |
|
|
|
@mock.patch('locale.getdefaultlocale') |
|
|
|
@mock.patch('locale.getdefaultlocale') |
|
|
|
def test_detect_language_defaultlocale(mock_getlocale): |
|
|
|
def test_detect_language_defaultlocale(mock_getlocale): |
|
|
|
""" |
|
|
|
""" |
|
|
|