diff --git a/.travis.yml b/.travis.yml index 44ea648..2f6b3ba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,10 +8,14 @@ python: - 3.7 - 3.8 - nightly +env: + - REMOVE_LOCALES=false + - REMOVE_LOCALES=true install: - pip install pyyaml coveralls flake8 flake8-import-order doc8 - if [[ $TRAVIS_PYTHON_VERSION != 2* ]]; then pip install sphinx; fi - pip install . + - if [[ $REMOVE_LOCALES = "true" ]]; then sudo rm -rf /usr/lib/locale/*; fi script: - if [[ $TRAVIS_PYTHON_VERSION != nightly ]]; then flake8 .; fi - if [[ $TRAVIS_PYTHON_VERSION != 2* ]]; then doc8 $(git ls-files '*.rst'); fi 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 90cf8c1..9b7801d 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -56,6 +56,16 @@ class RunContext(object): return self._raises_ctx.exception.code +# Check system's UTF-8 availability +def utf8_available(): + try: + locale.setlocale(locale.LC_ALL, 'C.UTF-8') + locale.setlocale(locale.LC_ALL, (None, None)) + return True + except locale.Error: + return False + + class CommandLineTestCase(unittest.TestCase): @classmethod def setUpClass(cls): @@ -86,7 +96,7 @@ class CommandLineTestCase(unittest.TestCase): 'no-yaml.json': '---\n' 'key: value\n', # non-ASCII chars - 'non-ascii/éçäγλνπ¥/utf-8': ( + u'non-ascii/éçäγλνπ¥/utf-8': ( u'---\n' u'- hétérogénéité\n' u'# 19.99 €\n' @@ -110,6 +120,8 @@ class CommandLineTestCase(unittest.TestCase): shutil.rmtree(cls.wd) + @unittest.skipIf(not utf8_available() and sys.version_info < (3, 7), + 'UTF-8 paths not supported') def test_find_files_recursively(self): conf = config.YamlLintConfig('extends: default') self.assertEqual( @@ -425,17 +437,12 @@ class CommandLineTestCase(unittest.TestCase): cli.run(('-f', 'parsable', path)) self.assertEqual((ctx.returncode, ctx.stdout, ctx.stderr), (0, '', '')) + @unittest.skipIf(not utf8_available(), 'C.UTF-8 not available') def test_run_non_ascii_file(self): - path = os.path.join(self.wd, 'non-ascii', 'éçäγλνπ¥', 'utf-8') - - # Make sure the default localization conditions on this "system" - # support UTF-8 encoding. - try: - locale.setlocale(locale.LC_ALL, (None, 'UTF-8')) - except locale.Error: - self.skipTest('no UTF-8 locale available') + 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: cli.run(('-f', 'parsable', path)) self.assertEqual((ctx.returncode, ctx.stdout, ctx.stderr), (0, '', ''))