diff --git a/tabcmd/execution/localize.py b/tabcmd/execution/localize.py index f38995cc..0d6a4b04 100644 --- a/tabcmd/execution/localize.py +++ b/tabcmd/execution/localize.py @@ -82,7 +82,13 @@ def _load_language(current_locale, domain, logger): def _get_default_locale(): + # c:\dev\tabcmd\tabcmd\execution\localize.py:85: DeprecationWarning 'locale.getdefaultlocale' is deprecated + # see test_localize for details + import logging + + logging.captureWarnings(True) current_locale, encoding = locale.getdefaultlocale() + logging.captureWarnings(False) current_locale = _validate_lang(current_locale) return current_locale diff --git a/tests/commands/test_localize.py b/tests/commands/test_localize.py index 90bb4851..2ae38ba2 100644 --- a/tests/commands/test_localize.py +++ b/tests/commands/test_localize.py @@ -1,6 +1,8 @@ import gettext +import locale +import sys import unittest -from tabcmd.execution.localize import set_client_locale +from tabcmd.execution.localize import set_client_locale, _get_default_locale class LocaleTests(unittest.TestCase): @@ -44,3 +46,19 @@ def test_en_smoke_line_processed(self): assert translations is not None assert translations("importcsvsummary.line.processed") == "Lines processed: {0}" + + # https://docs.python.org/3/library/locale.html + # c:\dev\tabcmd\tabcmd\execution\localize.py:85: DeprecationWarning: + # 'locale.getdefaultlocale' is deprecated and slated for removal in Python 3.15. Use setlocale(), getencoding() and getlocale() instead + def test_get_default_locale(self): + # Our method in localize.py that needs to change. An eventual unit test should call this method. + # loc = _get_default_locale() # doesn't return anything: need to mock _validate_lang + + # This bug on pytest explains why the proposed replacements aren't directly equivalent. + # Some people online have solved this with manual string mangling. I like the pytest decision + # to wait until we hit 3.15 and hope someone has implemented a better option by then. + # current call that is deprecated -->loc = locale.getdefaultlocale() # returns ('en_US', 'cp1252') + # sys.getdefaultencoding() # returns utf-8 + # locale.getlocale() # returns ('English_United States', '1252') + new_locale = locale.setlocale(locale.LC_CTYPE, None) # returns English_United States.125 + # assert loc == new_locale