Merge pull request #674 from pre-commit/simpler_cross_version_tests

Simplify cross version tests
This commit is contained in:
Anthony Sottile
2018-01-02 22:29:22 -05:00
committed by GitHub
7 changed files with 27 additions and 11 deletions

View File

@@ -16,8 +16,6 @@ matrix:
install: pip install coveralls tox
script: tox
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
- |
if [ "$LATEST_GIT" = "1" ]; then

View File

@@ -5,9 +5,8 @@
- The complete test suite depends on having at least the following installed (possibly not
a complete list)
- git (A sufficiently newer version is required to run pre-push tests)
- python
- python3.4 (Required by a test which checks different python versions)
- python3.5 (Required by a test which checks different python versions)
- python2 (Required by a test which checks different python versions)
- python3 (Required by a test which checks different python versions)
- tox (or virtualenv)
- ruby + gem
- docker

View File

@@ -9,6 +9,7 @@ from pre_commit.envcontext import UNSET
from pre_commit.envcontext import Var
from pre_commit.languages import helpers
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 cmd_output
from pre_commit.xargs import xargs
@@ -40,6 +41,17 @@ def in_env(repo_cmd_runner, language_version):
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 _norm(path):
_, exe = os.path.split(path.lower())
@@ -66,6 +78,9 @@ def _get_default_version(): # pragma: no cover (platform dependent)
if find_executable(exe):
return exe
if _find_by_py_launcher(exe):
return exe
# Give a best-effort try for windows
if os.path.exists(r'C:\{}\python.exe'.format(exe.replace('.', ''))):
return exe
@@ -99,6 +114,10 @@ def norm_version(version):
if version_exec and version_exec != version:
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
# place on windows
if version.startswith('python'):

View File

@@ -2,5 +2,5 @@
name: Python 3 Hook
entry: python3-hook
language: python
language_version: python3.5
language_version: python3
files: \.py$

View File

@@ -2,5 +2,5 @@
name: Python 3 Hook
entry: python3-hook
language: python
language_version: python3.5
language_version: python3
files: \.py$

View File

@@ -4,7 +4,7 @@ import sys
def func():
print('{}.{}'.format(*sys.version_info[:2]))
print(sys.version_info[0])
print(repr(sys.argv[1:]))
print('Hello World')
return 0

View File

@@ -130,8 +130,8 @@ def test_switch_language_versions_doesnt_clobber(tempdir_factory, store):
assert ret[0] == 0
assert _norm_out(ret[1]) == expected_output
run_on_version('python3.4', b'3.4\n[]\nHello World\n')
run_on_version('python3.5', b'3.5\n[]\nHello World\n')
run_on_version('python2', b'2\n[]\nHello World\n')
run_on_version('python3', b'3\n[]\nHello World\n')
@pytest.mark.integration
@@ -140,7 +140,7 @@ def test_versioned_python_hook(tempdir_factory, store):
tempdir_factory, store, 'python3_hooks_repo',
'python3-hook',
[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",
)