Tests: Set proper LC_ALL when decoding UTF-8 is needed

Make sure the default localization conditions on the "test system"
support UTF-8 encoding.
pull/12/head
Adrien Vergé 9 years ago
parent f4cebdc054
commit 92ff315fb4

@ -18,6 +18,7 @@ try:
from cStringIO import StringIO
except ImportError:
from io import StringIO
import locale
import os
import shutil
import tempfile
@ -273,10 +274,17 @@ class CommandLineTestCase(unittest.TestCase):
def test_run_non_ascii_file(self):
file = os.path.join(self.wd, 'non-ascii', 'utf-8')
# Make sure the default localization conditions on this "system"
# support UTF-8 encoding.
loc = locale.getlocale()
locale.setlocale(locale.LC_ALL, 'C.UTF-8')
sys.stdout, sys.stderr = StringIO(), StringIO()
with self.assertRaises(SystemExit) as ctx:
cli.run(('-f', 'parsable', file))
locale.setlocale(locale.LC_ALL, loc)
self.assertEqual(ctx.exception.code, 0)
out, err = sys.stdout.getvalue(), sys.stderr.getvalue()

Loading…
Cancel
Save