Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add build environment without UTF-8 locales to travis-ci #289

Merged
merged 11 commits into from
Jul 20, 2020
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
wolfgangwalther marked this conversation as resolved.
Show resolved Hide resolved
script:
- if [[ $TRAVIS_PYTHON_VERSION != nightly ]]; then flake8 .; fi
- if [[ $TRAVIS_PYTHON_VERSION != 2* ]]; then doc8 $(git ls-files '*.rst'); fi
Expand Down
101 changes: 61 additions & 40 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,16 @@ class CommandLineTestCase(unittest.TestCase):
def setUpClass(cls):
super(CommandLineTestCase, cls).setUpClass()

cls.wd = build_temp_workspace({
# Check system's UTF-8 availability, because without it
# using UTF-8 paths will break
adrienverge marked this conversation as resolved.
Show resolved Hide resolved
try:
locale.setlocale(locale.LC_ALL, 'C.UTF-8')
cls.utf8_missing = False
locale.setlocale(locale.LC_ALL, (None, None))
except locale.Error:
cls.utf8_missing = True

workspace_def = {
# .yaml file at root
'a.yaml': '---\n'
'- 1 \n'
Expand All @@ -85,13 +94,6 @@ def setUpClass(cls):
# 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',
Expand All @@ -102,7 +104,18 @@ def setUpClass(cls):
'en.yaml': '---\n'
'a: true\n'
'A: true'
})
}

if not cls.utf8_missing:
# non-ASCII chars
workspace_def['non-ascii/éçäγλνπ¥/utf-8'] = (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still kept this part in, because this way we only need to disable two out of ~25 tests

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):
Expand Down Expand Up @@ -185,18 +198,23 @@ def test_find_files_recursively(self):
' - \'*\'\n')
self.assertEqual(
sorted(cli.find_files_recursively([self.wd], conf)),
[os.path.join(self.wd, 'a.yaml'),
os.path.join(self.wd, 'c.yaml'),
os.path.join(self.wd, 'dos.yml'),
os.path.join(self.wd, 'empty.yml'),
os.path.join(self.wd, 'en.yaml'),
os.path.join(self.wd, 'no-yaml.json'),
os.path.join(self.wd, 'non-ascii/éçäγλνπ¥/utf-8'),
os.path.join(self.wd, 's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml'),
os.path.join(self.wd, 'sub/directory.yaml/empty.yml'),
os.path.join(self.wd, 'sub/directory.yaml/not-yaml.txt'),
os.path.join(self.wd, 'sub/ok.yaml'),
os.path.join(self.wd, 'warn.yaml')]
sorted(
[os.path.join(self.wd, 'a.yaml'),
os.path.join(self.wd, 'c.yaml'),
os.path.join(self.wd, 'dos.yml'),
os.path.join(self.wd, 'empty.yml'),
os.path.join(self.wd, 'en.yaml'),
os.path.join(self.wd, 'no-yaml.json'),
os.path.join(self.wd,
's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml'),
os.path.join(self.wd, 'sub/directory.yaml/empty.yml'),
os.path.join(self.wd, 'sub/directory.yaml/not-yaml.txt'),
os.path.join(self.wd, 'sub/ok.yaml'),
os.path.join(self.wd, 'warn.yaml')]
+
([] if self.utf8_missing else
wolfgangwalther marked this conversation as resolved.
Show resolved Hide resolved
[os.path.join(self.wd, 'non-ascii/éçäγλνπ¥/utf-8')])
)
)

conf = config.YamlLintConfig('extends: default\n'
Expand All @@ -206,18 +224,23 @@ def test_find_files_recursively(self):
' - \'**\'\n')
self.assertEqual(
sorted(cli.find_files_recursively([self.wd], conf)),
[os.path.join(self.wd, 'a.yaml'),
os.path.join(self.wd, 'c.yaml'),
os.path.join(self.wd, 'dos.yml'),
os.path.join(self.wd, 'empty.yml'),
os.path.join(self.wd, 'en.yaml'),
os.path.join(self.wd, 'no-yaml.json'),
os.path.join(self.wd, 'non-ascii/éçäγλνπ¥/utf-8'),
os.path.join(self.wd, 's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml'),
os.path.join(self.wd, 'sub/directory.yaml/empty.yml'),
os.path.join(self.wd, 'sub/directory.yaml/not-yaml.txt'),
os.path.join(self.wd, 'sub/ok.yaml'),
os.path.join(self.wd, 'warn.yaml')]
sorted(
[os.path.join(self.wd, 'a.yaml'),
os.path.join(self.wd, 'c.yaml'),
os.path.join(self.wd, 'dos.yml'),
os.path.join(self.wd, 'empty.yml'),
os.path.join(self.wd, 'en.yaml'),
os.path.join(self.wd, 'no-yaml.json'),
os.path.join(self.wd,
's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml'),
os.path.join(self.wd, 'sub/directory.yaml/empty.yml'),
os.path.join(self.wd, 'sub/directory.yaml/not-yaml.txt'),
os.path.join(self.wd, 'sub/ok.yaml'),
os.path.join(self.wd, 'warn.yaml')]
+
([] if self.utf8_missing else
[os.path.join(self.wd, 'non-ascii/éçäγλνπ¥/utf-8')])
)
)

conf = config.YamlLintConfig('extends: default\n'
Expand All @@ -226,6 +249,7 @@ def test_find_files_recursively(self):
' - \'**/utf-8\'\n')
self.assertEqual(
sorted(cli.find_files_recursively([self.wd], conf)),
[] if self.utf8_missing else
[os.path.join(self.wd, 'non-ascii/éçäγλνπ¥/utf-8')]
)

Expand Down Expand Up @@ -426,16 +450,13 @@ def test_run_empty_file(self):
self.assertEqual((ctx.returncode, ctx.stdout, ctx.stderr), (0, '', ''))

def test_run_non_ascii_file(self):
path = os.path.join(self.wd, 'non-ascii', 'éçäγλνπ¥', 'utf-8')
if self.utf8_missing:
self.skipTest('C.UTF-8 locale not available')

# 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, '', ''))
Expand Down