From 92ff315fb4b4871ce901896d779e0f52cec425a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Verg=C3=A9?= Date: Tue, 28 Jun 2016 11:03:45 +0200 Subject: [PATCH] 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. --- tests/test_cli.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/test_cli.py b/tests/test_cli.py index ec40a32..ed4e76d 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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()