refactor skipped tests

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

@ -56,19 +56,23 @@ class RunContext(object):
return self._raises_ctx.exception.code return self._raises_ctx.exception.code
class CommandLineTestCase(unittest.TestCase): # Check system's UTF-8 availability, because without it using UTF-8 paths
@classmethod # like 'éçäγλνπ¥' will break on Python ⩽ 3.6
def setUpClass(cls): def utf8_paths_supported():
super(CommandLineTestCase, cls).setUpClass() if sys.version_info >= (3, 7):
return True
# Check system's UTF-8 availability, because without it
# using UTF-8 paths like 'éçäγλνπ¥' will break on Python ⩽ 3.6
try: try:
locale.setlocale(locale.LC_ALL, 'C.UTF-8') locale.setlocale(locale.LC_ALL, 'C.UTF-8')
cls.utf8_missing = False
locale.setlocale(locale.LC_ALL, (None, None)) locale.setlocale(locale.LC_ALL, (None, None))
return True
except locale.Error: except locale.Error:
cls.utf8_missing = True return False
class CommandLineTestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
super(CommandLineTestCase, cls).setUpClass()
workspace_def = { workspace_def = {
# .yaml file at root # .yaml file at root
@ -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, os.path.join(self.wd, 'non-ascii/éçäγλνπ¥/utf-8'),
's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml'), 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/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, os.path.join(self.wd, 'non-ascii/éçäγλνπ¥/utf-8'),
's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml'), 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/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,10 +443,9 @@ 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') locale.setlocale(locale.LC_ALL, 'C.UTF-8')
self.addCleanup(locale.setlocale, locale.LC_ALL, (None, None)) self.addCleanup(locale.setlocale, locale.LC_ALL, (None, None))

Loading…
Cancel
Save