Use a more intelligent default language version

This commit is contained in:
Anthony Sottile 2017-07-08 20:22:36 -07:00
parent 853cbecd4e
commit d876661345
15 changed files with 109 additions and 54 deletions

View file

@ -12,9 +12,7 @@ from pre_commit.languages.all import languages
def test_install_environment_argspec(language):
expected_argspec = inspect.ArgSpec(
args=['repo_cmd_runner', 'version', 'additional_dependencies'],
varargs=None,
keywords=None,
defaults=('default', ()),
varargs=None, keywords=None, defaults=None,
)
argspec = inspect.getargspec(languages[language].install_environment)
assert argspec == expected_argspec
@ -33,3 +31,12 @@ def test_run_hook_argpsec(language):
)
argspec = inspect.getargspec(languages[language].run_hook)
assert argspec == expected_argspec
@pytest.mark.parametrize('language', all_languages)
def test_get_default_version_argspec(language):
expected_argspec = inspect.ArgSpec(
args=[], varargs=None, keywords=None, defaults=None,
)
argspec = inspect.getargspec(languages[language].get_default_version)
assert argspec == expected_argspec

View file

@ -11,8 +11,7 @@ from testing.util import get_head_sha
@pytest.yield_fixture
def manifest(store, tempdir_factory):
path = make_repo(tempdir_factory, 'script_hooks_repo')
head_sha = get_head_sha(path)
repo_path = store.clone(path, head_sha)
repo_path = store.clone(path, get_head_sha(path))
yield Manifest(repo_path, path)
@ -76,3 +75,13 @@ def test_legacy_manifest_warn(store, tempdir_factory, log_warning_mock):
'If `pre-commit autoupdate` does not silence this warning consider '
'making an issue / pull request.'.format(path)
)
def test_default_python_language_version(store, tempdir_factory):
path = make_repo(tempdir_factory, 'python_hooks_repo')
repo_path = store.clone(path, get_head_sha(path))
manifest = Manifest(repo_path, path)
# This assertion is difficult as it is version dependent, just assert
# that it is *something*
assert manifest.hooks['foo']['language_version'] != 'default'

View file

@ -442,7 +442,7 @@ def test_venvs(tempdir_factory, store):
config = make_config_from_repo(path)
repo = Repository.create(config, store)
venv, = repo._venvs
assert venv == (mock.ANY, 'python', 'default', [])
assert venv == (mock.ANY, 'python', python.get_default_version(), [])
@pytest.mark.integration
@ -452,7 +452,7 @@ def test_additional_dependencies(tempdir_factory, store):
config['hooks'][0]['additional_dependencies'] = ['pep8']
repo = Repository.create(config, store)
venv, = repo._venvs
assert venv == (mock.ANY, 'python', 'default', ['pep8'])
assert venv == (mock.ANY, 'python', python.get_default_version(), ['pep8'])
@pytest.mark.integration
@ -591,7 +591,8 @@ def test_control_c_control_c_on_install(tempdir_factory, store):
repo.run_hook(hook, [])
# Should have made an environment, however this environment is broken!
assert os.path.exists(repo._cmd_runner.path('py_env-default'))
envdir = 'py_env-{}'.format(python.get_default_version())
assert repo._cmd_runner.exists(envdir)
# However, it should be perfectly runnable (reinstall after botched
# install)