mirror of
https://github.com/adrienverge/yamllint.git
synced 2025-02-25 18:55:20 -06:00
CI: Add build environment without UTF-8 locales to travis-ci
Preventing regressions like #285
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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))
|
||||
|
||||
|
||||
@@ -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, '', ''))
|
||||
|
||||
Reference in New Issue
Block a user