[master 17/30] Handle latin-1 strings in locale -a output (#1014220)

M4rtinK installerbot-noreply at redhat.com
Mon Jun 1 14:04:34 UTC 2015


From: Martin Kolman <mkolman at redhat.com>

---
 tests/pyanaconda_tests/localization_test.py | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/tests/pyanaconda_tests/localization_test.py b/tests/pyanaconda_tests/localization_test.py
index 34672b2..0d546e4 100644
--- a/tests/pyanaconda_tests/localization_test.py
+++ b/tests/pyanaconda_tests/localization_test.py
@@ -19,7 +19,7 @@
 #
 
 from pyanaconda import localization
-from pyanaconda.iutil import execReadlines
+from pyanaconda.iutil import execWithCaptureBinary
 import locale as locale_mod
 import unittest
 
@@ -145,10 +145,19 @@ def find_best_locale_match_test(self):
     def resolve_date_format_test(self):
         """All locales' date formats should be properly resolved."""
 
-        locales = (line.strip() for line in execReadlines("locale", ["-a"]))
+        locales = (line.strip() for line in execWithCaptureBinary("locale", ["-a"]).splitlines())
         for locale in locales:
+            # "locale -a" might return latin-1 encoded local identifiers:
+            # https://bugzilla.redhat.com/show_bug.cgi?id=1184168
+            # once that bug is fixed we should be able to remove the latin-1 decoding
+            # fallback
             try:
-                locale_mod.setlocale(locale_mod.LC_ALL, locale)
+                decoded_locale = locale.decode("utf-8")
+            except UnicodeDecodeError:
+                decoded_locale = locale.decode("latin-1")
+
+            try:
+                locale_mod.setlocale(locale_mod.LC_ALL, decoded_locale)
             except locale_mod.Error:
                 # cannot set locale (a bug in the locale module?)
                 continue


-- 
To view this commit on github, visit https://github.com/rhinstaller/anaconda/commit/365920e22ccfcbf3346b63738432af2a9216bef7


More information about the anaconda-patches mailing list