diff --git a/tests/common.py b/tests/common.py index b5ba469..50fd3df 100644 --- a/tests/common.py +++ b/tests/common.py @@ -57,7 +57,7 @@ def build_temp_workspace(files): tempdir = tempfile.mkdtemp(prefix='yamllint-tests-') for path, content in files.items(): - path = os.path.join(tempdir, path) + path = os.path.join(tempdir, path).encode('utf-8') if not os.path.exists(os.path.dirname(path)): os.makedirs(os.path.dirname(path)) diff --git a/tests/test_cli.py b/tests/test_cli.py index ac33de2..2ad440e 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -74,7 +74,7 @@ class CommandLineTestCase(unittest.TestCase): def setUpClass(cls): super(CommandLineTestCase, cls).setUpClass() - workspace_def = { + cls.wd = build_temp_workspace({ # .yaml file at root 'a.yaml': '---\n' '- 1 \n' @@ -98,6 +98,13 @@ class CommandLineTestCase(unittest.TestCase): # non-YAML file 'no-yaml.json': '---\n' 'key: value\n', + # non-ASCII chars + 'non-ascii/éçäγλνπ¥/utf-8': ( + u'---\n' + u'- hétérogénéité\n' + u'# 19.99 €\n' + u'- お早う御座います。\n' + u'# الأَبْجَدِيَّة العَرَبِيَّة\n').encode('utf-8'), # dos line endings yaml 'dos.yml': '---\r\n' 'dos: true', @@ -108,18 +115,7 @@ class CommandLineTestCase(unittest.TestCase): 'en.yaml': '---\n' 'a: true\n' 'A: true' - } - - if utf8_paths_supported(): - # non-ASCII chars - workspace_def['non-ascii/éçäγλνπ¥/utf-8'] = ( - u'---\n' - u'- hétérogénéité\n' - u'# 19.99 €\n' - u'- お早う御座います。\n' - u'# الأَبْجَدِيَّة العَرَبِيَّة\n').encode('utf-8') - - cls.wd = build_temp_workspace(workspace_def) + }) @classmethod def tearDownClass(cls): @@ -445,9 +441,8 @@ class CommandLineTestCase(unittest.TestCase): @unittest.skipIf(not utf8_paths_supported(), 'UTF-8 paths not supported') def test_run_non_ascii_file(self): - if sys.version_info < (3, 7): - locale.setlocale(locale.LC_ALL, 'C.UTF-8') - self.addCleanup(locale.setlocale, locale.LC_ALL, (None, None)) + locale.setlocale(locale.LC_ALL, 'C.UTF-8') + self.addCleanup(locale.setlocale, locale.LC_ALL, (None, None)) path = os.path.join(self.wd, 'non-ascii', 'éçäγλνπ¥', 'utf-8') with RunContext(self) as ctx: