Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated locale.*() functions #3366

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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