Skip to content

Commit

Permalink
Merge pull request #3366 from candlepin/mhorky/locale
Browse files Browse the repository at this point in the history
Remove deprecated `locale.*()` functions
  • Loading branch information
ptoscano authored Jan 11, 2024
2 parents 4b4ebfb + 8ef41ce commit e04e263
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
7 changes: 2 additions & 5 deletions src/rhsmlib/facts/host_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,11 @@ def get_all(self) -> Dict[str, Union[str, int, bool, None]]:

locale_info = {}
effective_locale = "Unknown"
# When there is no locale set (system variable LANG is unset),
# then this is value returned by locale.getdefaultlocale()
# Tuple contains: (language[_territory], encoding identifier)
default_locale = (None, None)
try:
default_locale = locale.getdefaultlocale()
default_locale = locale.getlocale(category=locale.LC_MESSAGES)
except ValueError as err:
log.warning("Unable to get default locale (bad environment variable?): %s" % err)
default_locale = (None, None)
if default_locale[0] is not None:
effective_locale = ".".join([_f for _f in default_locale if _f])
locale_info["system.default_locale"] = effective_locale
Expand Down
2 changes: 1 addition & 1 deletion test/rhsm/unit/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ def setUp(self):
self.cp = UEPConnection(username="dummy", password="dummy", handler="/Test/", insecure=True)

def tearDown(self):
locale.resetlocale()
locale.setlocale(category=locale.LC_ALL, locale="")

@patch("subscription_manager.cache.open", MOCK_OPEN_CACHE)
def test_date_formatted_properly_with_japanese_locale(self):
Expand Down
6 changes: 3 additions & 3 deletions test/rhsmlib/facts/test_host_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


class HostCollectorTest(unittest.TestCase):
@mock.patch("locale.getdefaultlocale")
@mock.patch("locale.getlocale")
def test_unknown_locale(self, mock_locale):
collector = host_collector.HostCollector()
mock_locale.return_value = (None, None)
Expand All @@ -28,7 +28,7 @@ def test_unknown_locale(self, mock_locale):
self.assertTrue(isinstance(facts, dict))
self.assertEqual(facts["system.default_locale"], "Unknown")

@mock.patch("locale.getdefaultlocale")
@mock.patch("locale.getlocale")
def test_en_us_utf8_locale(self, mock_locale):
collector = host_collector.HostCollector()
mock_locale.return_value = ("en_US", "UTF-8")
Expand All @@ -37,7 +37,7 @@ def test_en_us_utf8_locale(self, mock_locale):
self.assertTrue(isinstance(facts, dict))
self.assertEqual(facts["system.default_locale"], "en_US.UTF-8")

@mock.patch("locale.getdefaultlocale")
@mock.patch("locale.getlocale")
def test_en_us_no_encoding_locale(self, mock_locale):
collector = host_collector.HostCollector()
mock_locale.return_value = ("en_US", None)
Expand Down

0 comments on commit e04e263

Please sign in to comment.