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.7
|
||||||
- 3.8
|
- 3.8
|
||||||
- nightly
|
- nightly
|
||||||
|
env:
|
||||||
|
- REMOVE_LOCALES=false
|
||||||
|
- REMOVE_LOCALES=true
|
||||||
install:
|
install:
|
||||||
- pip install pyyaml coveralls flake8 flake8-import-order doc8
|
- pip install pyyaml coveralls flake8 flake8-import-order doc8
|
||||||
- if [[ $TRAVIS_PYTHON_VERSION != 2* ]]; then pip install sphinx; fi
|
- if [[ $TRAVIS_PYTHON_VERSION != 2* ]]; then pip install sphinx; fi
|
||||||
- pip install .
|
- pip install .
|
||||||
|
- if [[ $REMOVE_LOCALES = "true" ]]; then sudo rm -rf /usr/lib/locale/*; fi
|
||||||
script:
|
script:
|
||||||
- if [[ $TRAVIS_PYTHON_VERSION != nightly ]]; then flake8 .; fi
|
- if [[ $TRAVIS_PYTHON_VERSION != nightly ]]; then flake8 .; fi
|
||||||
- if [[ $TRAVIS_PYTHON_VERSION != 2* ]]; then doc8 $(git ls-files '*.rst'); 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-')
|
tempdir = tempfile.mkdtemp(prefix='yamllint-tests-')
|
||||||
|
|
||||||
for path, content in files.items():
|
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)):
|
if not os.path.exists(os.path.dirname(path)):
|
||||||
os.makedirs(os.path.dirname(path))
|
os.makedirs(os.path.dirname(path))
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,16 @@ class RunContext(object):
|
|||||||
return self._raises_ctx.exception.code
|
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):
|
class CommandLineTestCase(unittest.TestCase):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
@@ -86,7 +96,7 @@ class CommandLineTestCase(unittest.TestCase):
|
|||||||
'no-yaml.json': '---\n'
|
'no-yaml.json': '---\n'
|
||||||
'key: value\n',
|
'key: value\n',
|
||||||
# non-ASCII chars
|
# non-ASCII chars
|
||||||
'non-ascii/éçäγλνπ¥/utf-8': (
|
u'non-ascii/éçäγλνπ¥/utf-8': (
|
||||||
u'---\n'
|
u'---\n'
|
||||||
u'- hétérogénéité\n'
|
u'- hétérogénéité\n'
|
||||||
u'# 19.99 €\n'
|
u'# 19.99 €\n'
|
||||||
@@ -110,6 +120,8 @@ class CommandLineTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
shutil.rmtree(cls.wd)
|
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):
|
def test_find_files_recursively(self):
|
||||||
conf = config.YamlLintConfig('extends: default')
|
conf = config.YamlLintConfig('extends: default')
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
@@ -425,17 +437,12 @@ class CommandLineTestCase(unittest.TestCase):
|
|||||||
cli.run(('-f', 'parsable', path))
|
cli.run(('-f', 'parsable', path))
|
||||||
self.assertEqual((ctx.returncode, ctx.stdout, ctx.stderr), (0, '', ''))
|
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):
|
def test_run_non_ascii_file(self):
|
||||||
path = os.path.join(self.wd, 'non-ascii', 'éçäγλνπ¥', 'utf-8')
|
locale.setlocale(locale.LC_ALL, 'C.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')
|
|
||||||
self.addCleanup(locale.setlocale, locale.LC_ALL, (None, None))
|
self.addCleanup(locale.setlocale, locale.LC_ALL, (None, None))
|
||||||
|
|
||||||
|
path = os.path.join(self.wd, 'non-ascii', 'éçäγλνπ¥', 'utf-8')
|
||||||
with RunContext(self) as ctx:
|
with RunContext(self) as ctx:
|
||||||
cli.run(('-f', 'parsable', path))
|
cli.run(('-f', 'parsable', path))
|
||||||
self.assertEqual((ctx.returncode, ctx.stdout, ctx.stderr), (0, '', ''))
|
self.assertEqual((ctx.returncode, ctx.stdout, ctx.stderr), (0, '', ''))
|
||||||
|
|||||||
Reference in New Issue
Block a user