Skip to content

Commit

Permalink
Patch the returned locale if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
vasole committed Oct 11, 2023
1 parent 71ecacf commit 2ab843c
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions PyMca5/tests/SpecfileTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,17 @@
else:
other_locale = l
break
try:
locale.setlocale(locale.LC_ALL, current_locale)
except Exception:
other_locale = False

# cleanup python 3.12 issue on same machines
if isinstance(current_locale, tuple):
# if the returned tuple is (None, 'UTF-8') it cannot restore the locale
current_as_list = list(current_locale)
for i in range(len(current_as_list)):
if current_as_list[i] is None:
current_as_list[i] = ''
current_locale = tuple(current_as_list)

locale.setlocale(locale.LC_ALL, current_locale)

class testSpecfile(unittest.TestCase):
def setUp(self):
Expand Down Expand Up @@ -93,11 +100,7 @@ def tearDown(self):
# this should free the handle
gc.collect()
# restore saved locale
try:
locale.setlocale(locale.LC_ALL, current_locale)
except locale.Error:
# this should not happen
print(f"Error trying to restore locale <{current_locale}>")
locale.setlocale(locale.LC_ALL, current_locale)

if self.specfileClass is not None:
if os.path.exists(self.fname):
Expand Down

0 comments on commit 2ab843c

Please sign in to comment.