mirror of
https://github.com/adrienverge/yamllint.git
synced 2025-02-20 11:38:24 -06:00
tests: Use sys.executable
instead of hard-coded 'python'
To test yamllint as a module, tests run commands like `python -m yamllint`. But some environments (like continuous integration of Debian or CentOS) don't always include the `python` executable (they use `python3` instead). Let's dynamically detect the Python executable path.
This commit is contained in:
parent
ed5d319df8
commit
501def327d
@ -26,6 +26,9 @@ except AssertionError:
|
||||
import unittest2 as unittest
|
||||
|
||||
|
||||
PYTHON = sys.executable or 'python'
|
||||
|
||||
|
||||
@unittest.skipIf(sys.version_info < (2, 7), 'Python 2.6 not supported')
|
||||
class ModuleTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
@ -46,7 +49,7 @@ class ModuleTestCase(unittest.TestCase):
|
||||
|
||||
def test_run_module_no_args(self):
|
||||
with self.assertRaises(subprocess.CalledProcessError) as ctx:
|
||||
subprocess.check_output(['python', '-m', 'yamllint'],
|
||||
subprocess.check_output([PYTHON, '-m', 'yamllint'],
|
||||
stderr=subprocess.STDOUT)
|
||||
self.assertEqual(ctx.exception.returncode, 2)
|
||||
self.assertRegexpMatches(ctx.exception.output.decode(),
|
||||
@ -54,7 +57,7 @@ class ModuleTestCase(unittest.TestCase):
|
||||
|
||||
def test_run_module_on_bad_dir(self):
|
||||
with self.assertRaises(subprocess.CalledProcessError) as ctx:
|
||||
subprocess.check_output(['python', '-m', 'yamllint',
|
||||
subprocess.check_output([PYTHON, '-m', 'yamllint',
|
||||
'/does/not/exist'],
|
||||
stderr=subprocess.STDOUT)
|
||||
self.assertRegexpMatches(ctx.exception.output.decode(),
|
||||
@ -62,7 +65,7 @@ class ModuleTestCase(unittest.TestCase):
|
||||
|
||||
def test_run_module_on_file(self):
|
||||
out = subprocess.check_output(
|
||||
['python', '-m', 'yamllint', os.path.join(self.wd, 'warn.yaml')])
|
||||
[PYTHON, '-m', 'yamllint', os.path.join(self.wd, 'warn.yaml')])
|
||||
lines = out.decode().splitlines()
|
||||
self.assertIn('/warn.yaml', lines[0])
|
||||
self.assertEqual('\n'.join(lines[1:]),
|
||||
@ -71,7 +74,7 @@ class ModuleTestCase(unittest.TestCase):
|
||||
|
||||
def test_run_module_on_dir(self):
|
||||
with self.assertRaises(subprocess.CalledProcessError) as ctx:
|
||||
subprocess.check_output(['python', '-m', 'yamllint', self.wd])
|
||||
subprocess.check_output([PYTHON, '-m', 'yamllint', self.wd])
|
||||
self.assertEqual(ctx.exception.returncode, 1)
|
||||
|
||||
files = ctx.exception.output.decode().split('\n\n')
|
||||
|
Loading…
Reference in New Issue
Block a user