tests: Use en_US.UTF-8 locale when C.UTF-8 not available

Some operating systems don't have the `C.UTF-8` locale installed yet
(for instance, CentOS 7). In such a case, fallback to `en_US.UTF-8` so
that tests can be run.

This follows commit 92ff315.
pull/89/head
Adrien Vergé 7 years ago
parent 6ec1e7b54a
commit ed5d319df8

@ -299,7 +299,10 @@ class CommandLineTestCase(unittest.TestCase):
# Make sure the default localization conditions on this "system" # Make sure the default localization conditions on this "system"
# support UTF-8 encoding. # support UTF-8 encoding.
loc = locale.getlocale() loc = locale.getlocale()
locale.setlocale(locale.LC_ALL, 'C.UTF-8') try:
locale.setlocale(locale.LC_ALL, 'C.UTF-8')
except locale.Error:
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
sys.stdout, sys.stderr = StringIO(), StringIO() sys.stdout, sys.stderr = StringIO(), StringIO()
with self.assertRaises(SystemExit) as ctx: with self.assertRaises(SystemExit) as ctx:

Loading…
Cancel
Save