mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Merge pull request #674 from pre-commit/simpler_cross_version_tests
Simplify cross version tests
This commit is contained in:
commit
097bba63b8
7 changed files with 27 additions and 11 deletions
|
|
@ -16,8 +16,6 @@ matrix:
|
||||||
install: pip install coveralls tox
|
install: pip install coveralls tox
|
||||||
script: tox
|
script: tox
|
||||||
before_install:
|
before_install:
|
||||||
# work around https://github.com/travis-ci/travis-ci/issues/8363
|
|
||||||
- which python3.5 || (pyenv install 3.5.4 && pyenv global system 3.5.4)
|
|
||||||
- git --version
|
- git --version
|
||||||
- |
|
- |
|
||||||
if [ "$LATEST_GIT" = "1" ]; then
|
if [ "$LATEST_GIT" = "1" ]; then
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,8 @@
|
||||||
- The complete test suite depends on having at least the following installed (possibly not
|
- The complete test suite depends on having at least the following installed (possibly not
|
||||||
a complete list)
|
a complete list)
|
||||||
- git (A sufficiently newer version is required to run pre-push tests)
|
- git (A sufficiently newer version is required to run pre-push tests)
|
||||||
- python
|
- python2 (Required by a test which checks different python versions)
|
||||||
- python3.4 (Required by a test which checks different python versions)
|
- python3 (Required by a test which checks different python versions)
|
||||||
- python3.5 (Required by a test which checks different python versions)
|
|
||||||
- tox (or virtualenv)
|
- tox (or virtualenv)
|
||||||
- ruby + gem
|
- ruby + gem
|
||||||
- docker
|
- docker
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ from pre_commit.envcontext import UNSET
|
||||||
from pre_commit.envcontext import Var
|
from pre_commit.envcontext import Var
|
||||||
from pre_commit.languages import helpers
|
from pre_commit.languages import helpers
|
||||||
from pre_commit.parse_shebang import find_executable
|
from pre_commit.parse_shebang import find_executable
|
||||||
|
from pre_commit.util import CalledProcessError
|
||||||
from pre_commit.util import clean_path_on_failure
|
from pre_commit.util import clean_path_on_failure
|
||||||
from pre_commit.util import cmd_output
|
from pre_commit.util import cmd_output
|
||||||
from pre_commit.xargs import xargs
|
from pre_commit.xargs import xargs
|
||||||
|
|
@ -40,6 +41,17 @@ def in_env(repo_cmd_runner, language_version):
|
||||||
yield
|
yield
|
||||||
|
|
||||||
|
|
||||||
|
def _find_by_py_launcher(version): # pragma: no cover (windows only)
|
||||||
|
if version.startswith('python'):
|
||||||
|
try:
|
||||||
|
return cmd_output(
|
||||||
|
'py', '-{}'.format(version[len('python'):]),
|
||||||
|
'-c', 'import sys; print(sys.executable)',
|
||||||
|
)[1].strip()
|
||||||
|
except CalledProcessError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def _get_default_version(): # pragma: no cover (platform dependent)
|
def _get_default_version(): # pragma: no cover (platform dependent)
|
||||||
def _norm(path):
|
def _norm(path):
|
||||||
_, exe = os.path.split(path.lower())
|
_, exe = os.path.split(path.lower())
|
||||||
|
|
@ -66,6 +78,9 @@ def _get_default_version(): # pragma: no cover (platform dependent)
|
||||||
if find_executable(exe):
|
if find_executable(exe):
|
||||||
return exe
|
return exe
|
||||||
|
|
||||||
|
if _find_by_py_launcher(exe):
|
||||||
|
return exe
|
||||||
|
|
||||||
# Give a best-effort try for windows
|
# Give a best-effort try for windows
|
||||||
if os.path.exists(r'C:\{}\python.exe'.format(exe.replace('.', ''))):
|
if os.path.exists(r'C:\{}\python.exe'.format(exe.replace('.', ''))):
|
||||||
return exe
|
return exe
|
||||||
|
|
@ -99,6 +114,10 @@ def norm_version(version):
|
||||||
if version_exec and version_exec != version:
|
if version_exec and version_exec != version:
|
||||||
return version_exec
|
return version_exec
|
||||||
|
|
||||||
|
version_exec = _find_by_py_launcher(version)
|
||||||
|
if version_exec:
|
||||||
|
return version_exec
|
||||||
|
|
||||||
# If it is in the form pythonx.x search in the default
|
# If it is in the form pythonx.x search in the default
|
||||||
# place on windows
|
# place on windows
|
||||||
if version.startswith('python'):
|
if version.startswith('python'):
|
||||||
|
|
|
||||||
|
|
@ -2,5 +2,5 @@
|
||||||
name: Python 3 Hook
|
name: Python 3 Hook
|
||||||
entry: python3-hook
|
entry: python3-hook
|
||||||
language: python
|
language: python
|
||||||
language_version: python3.5
|
language_version: python3
|
||||||
files: \.py$
|
files: \.py$
|
||||||
|
|
|
||||||
|
|
@ -2,5 +2,5 @@
|
||||||
name: Python 3 Hook
|
name: Python 3 Hook
|
||||||
entry: python3-hook
|
entry: python3-hook
|
||||||
language: python
|
language: python
|
||||||
language_version: python3.5
|
language_version: python3
|
||||||
files: \.py$
|
files: \.py$
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import sys
|
||||||
|
|
||||||
|
|
||||||
def func():
|
def func():
|
||||||
print('{}.{}'.format(*sys.version_info[:2]))
|
print(sys.version_info[0])
|
||||||
print(repr(sys.argv[1:]))
|
print(repr(sys.argv[1:]))
|
||||||
print('Hello World')
|
print('Hello World')
|
||||||
return 0
|
return 0
|
||||||
|
|
|
||||||
|
|
@ -130,8 +130,8 @@ def test_switch_language_versions_doesnt_clobber(tempdir_factory, store):
|
||||||
assert ret[0] == 0
|
assert ret[0] == 0
|
||||||
assert _norm_out(ret[1]) == expected_output
|
assert _norm_out(ret[1]) == expected_output
|
||||||
|
|
||||||
run_on_version('python3.4', b'3.4\n[]\nHello World\n')
|
run_on_version('python2', b'2\n[]\nHello World\n')
|
||||||
run_on_version('python3.5', b'3.5\n[]\nHello World\n')
|
run_on_version('python3', b'3\n[]\nHello World\n')
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
|
|
@ -140,7 +140,7 @@ def test_versioned_python_hook(tempdir_factory, store):
|
||||||
tempdir_factory, store, 'python3_hooks_repo',
|
tempdir_factory, store, 'python3_hooks_repo',
|
||||||
'python3-hook',
|
'python3-hook',
|
||||||
[os.devnull],
|
[os.devnull],
|
||||||
b"3.5\n['" + five.to_bytes(os.devnull) + b"']\nHello World\n",
|
b"3\n['" + five.to_bytes(os.devnull) + b"']\nHello World\n",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue