refactor skipped tests

pull/289/head
Wolfgang Walther 5 years ago
parent 0f095d8cb6
commit b657a3e1d6

@ -15,7 +15,7 @@ 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 - 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

@ -56,20 +56,24 @@ class RunContext(object):
return self._raises_ctx.exception.code return self._raises_ctx.exception.code
# Check system's UTF-8 availability, because without it using UTF-8 paths
# like 'éçäγλνπ¥' will break on Python ⩽ 3.6
def utf8_paths_supported():
if sys.version_info >= (3, 7):
return True
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):
super(CommandLineTestCase, cls).setUpClass() super(CommandLineTestCase, cls).setUpClass()
# Check system's UTF-8 availability, because without it
# using UTF-8 paths like 'éçäγλνπ¥' will break on Python ⩽ 3.6
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 = { workspace_def = {
# .yaml file at root # .yaml file at root
'a.yaml': '---\n' 'a.yaml': '---\n'
@ -106,7 +110,7 @@ class CommandLineTestCase(unittest.TestCase):
'A: true' 'A: true'
} }
if not cls.utf8_missing: if utf8_paths_supported():
# non-ASCII chars # non-ASCII chars
workspace_def['non-ascii/éçäγλνπ¥/utf-8'] = ( workspace_def['non-ascii/éçäγλνπ¥/utf-8'] = (
u'---\n' u'---\n'
@ -123,6 +127,7 @@ class CommandLineTestCase(unittest.TestCase):
shutil.rmtree(cls.wd) shutil.rmtree(cls.wd)
@unittest.skipIf(not utf8_paths_supported(), '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(
@ -198,23 +203,18 @@ class CommandLineTestCase(unittest.TestCase):
' - \'*\'\n') ' - \'*\'\n')
self.assertEqual( self.assertEqual(
sorted(cli.find_files_recursively([self.wd], conf)), sorted(cli.find_files_recursively([self.wd], conf)),
sorted( [os.path.join(self.wd, 'a.yaml'),
[os.path.join(self.wd, 'a.yaml'), os.path.join(self.wd, 'c.yaml'),
os.path.join(self.wd, 'c.yaml'), os.path.join(self.wd, 'dos.yml'),
os.path.join(self.wd, 'dos.yml'), os.path.join(self.wd, 'empty.yml'),
os.path.join(self.wd, 'empty.yml'), os.path.join(self.wd, 'en.yaml'),
os.path.join(self.wd, 'en.yaml'), os.path.join(self.wd, 'no-yaml.json'),
os.path.join(self.wd, 'no-yaml.json'), os.path.join(self.wd, 'non-ascii/éçäγλνπ¥/utf-8'),
os.path.join(self.wd, os.path.join(self.wd, 's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml'),
'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/empty.yml'), os.path.join(self.wd, 'sub/directory.yaml/not-yaml.txt'),
os.path.join(self.wd, 'sub/directory.yaml/not-yaml.txt'), os.path.join(self.wd, 'sub/ok.yaml'),
os.path.join(self.wd, 'sub/ok.yaml'), os.path.join(self.wd, 'warn.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' conf = config.YamlLintConfig('extends: default\n'
@ -224,23 +224,18 @@ class CommandLineTestCase(unittest.TestCase):
' - \'**\'\n') ' - \'**\'\n')
self.assertEqual( self.assertEqual(
sorted(cli.find_files_recursively([self.wd], conf)), sorted(cli.find_files_recursively([self.wd], conf)),
sorted( [os.path.join(self.wd, 'a.yaml'),
[os.path.join(self.wd, 'a.yaml'), os.path.join(self.wd, 'c.yaml'),
os.path.join(self.wd, 'c.yaml'), os.path.join(self.wd, 'dos.yml'),
os.path.join(self.wd, 'dos.yml'), os.path.join(self.wd, 'empty.yml'),
os.path.join(self.wd, 'empty.yml'), os.path.join(self.wd, 'en.yaml'),
os.path.join(self.wd, 'en.yaml'), os.path.join(self.wd, 'no-yaml.json'),
os.path.join(self.wd, 'no-yaml.json'), os.path.join(self.wd, 'non-ascii/éçäγλνπ¥/utf-8'),
os.path.join(self.wd, os.path.join(self.wd, 's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml'),
'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/empty.yml'), os.path.join(self.wd, 'sub/directory.yaml/not-yaml.txt'),
os.path.join(self.wd, 'sub/directory.yaml/not-yaml.txt'), os.path.join(self.wd, 'sub/ok.yaml'),
os.path.join(self.wd, 'sub/ok.yaml'), os.path.join(self.wd, 'warn.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' conf = config.YamlLintConfig('extends: default\n'
@ -249,7 +244,6 @@ class CommandLineTestCase(unittest.TestCase):
' - \'**/utf-8\'\n') ' - \'**/utf-8\'\n')
self.assertEqual( self.assertEqual(
sorted(cli.find_files_recursively([self.wd], conf)), sorted(cli.find_files_recursively([self.wd], conf)),
[] if self.utf8_missing else
[os.path.join(self.wd, 'non-ascii/éçäγλνπ¥/utf-8')] [os.path.join(self.wd, 'non-ascii/éçäγλνπ¥/utf-8')]
) )
@ -449,12 +443,11 @@ 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_paths_supported(), 'UTF-8 paths not supported')
def test_run_non_ascii_file(self): def test_run_non_ascii_file(self):
if self.utf8_missing: if sys.version_info < (3, 7):
self.skipTest('C.UTF-8 locale not available') 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') path = os.path.join(self.wd, 'non-ascii', 'éçäγλνπ¥', 'utf-8')
with RunContext(self) as ctx: with RunContext(self) as ctx:

Loading…
Cancel
Save