mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Add test for python_venv language
This commit is contained in:
parent
e8954e2bf3
commit
b5af5a5b27
12 changed files with 55 additions and 15 deletions
|
|
@ -16,7 +16,6 @@ from pre_commit.xargs import xargs
|
|||
|
||||
|
||||
ENVIRONMENT_DIR = 'py_env'
|
||||
HEALTH_MODS = ('datetime', 'io', 'os', 'ssl', 'weakref')
|
||||
|
||||
|
||||
def bin_dir(venv):
|
||||
|
|
@ -120,7 +119,8 @@ def py_interface(_dir, _make_venv):
|
|||
def healthy(prefix, language_version):
|
||||
with in_env(prefix, language_version):
|
||||
retcode, _, _ = cmd_output(
|
||||
'python', '-c', 'import {}'.format(','.join(HEALTH_MODS)),
|
||||
'python', '-c',
|
||||
'import ctypes, datetime, io, os, ssl, weakref',
|
||||
retcode=None,
|
||||
)
|
||||
return retcode == 0
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from __future__ import print_function
|
|||
import sys
|
||||
|
||||
|
||||
def func():
|
||||
def main():
|
||||
print(sys.version_info[0])
|
||||
print(repr(sys.argv[1:]))
|
||||
print('Hello World')
|
||||
|
|
@ -1,11 +1,8 @@
|
|||
from setuptools import find_packages
|
||||
from setuptools import setup
|
||||
|
||||
setup(
|
||||
name='python3_hook',
|
||||
version='0.0.0',
|
||||
packages=find_packages('.'),
|
||||
entry_points={
|
||||
'console_scripts': ['python3-hook = python3_hook.main:func'],
|
||||
},
|
||||
py_modules=['py3_hook'],
|
||||
entry_points={'console_scripts': ['python3-hook = py3_hook:main']},
|
||||
)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from __future__ import print_function
|
|||
import sys
|
||||
|
||||
|
||||
def func():
|
||||
def main():
|
||||
print(repr(sys.argv[1:]))
|
||||
print('Hello World')
|
||||
return 0
|
||||
|
|
@ -1,11 +1,8 @@
|
|||
from setuptools import find_packages
|
||||
from setuptools import setup
|
||||
|
||||
setup(
|
||||
name='Foo',
|
||||
name='foo',
|
||||
version='0.0.0',
|
||||
packages=find_packages('.'),
|
||||
entry_points={
|
||||
'console_scripts': ['foo = foo.main:func'],
|
||||
},
|
||||
py_modules=['foo'],
|
||||
entry_points={'console_scripts': ['foo = foo:main']},
|
||||
)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
- id: foo
|
||||
name: Foo
|
||||
entry: foo
|
||||
language: python_venv
|
||||
files: \.py$
|
||||
9
testing/resources/python_venv_hooks_repo/foo.py
Normal file
9
testing/resources/python_venv_hooks_repo/foo.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
from __future__ import print_function
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
print(repr(sys.argv[1:]))
|
||||
print('Hello World')
|
||||
return 0
|
||||
8
testing/resources/python_venv_hooks_repo/setup.py
Normal file
8
testing/resources/python_venv_hooks_repo/setup.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
from setuptools import setup
|
||||
|
||||
setup(
|
||||
name='foo',
|
||||
version='0.0.0',
|
||||
py_modules=['foo'],
|
||||
entry_points={'console_scripts': ['foo = foo:main']},
|
||||
)
|
||||
|
|
@ -78,6 +78,20 @@ xfailif_no_symlink = pytest.mark.xfail(
|
|||
)
|
||||
|
||||
|
||||
def supports_venv(): # pragma: no cover (platform specific)
|
||||
try:
|
||||
__import__('ensurepip')
|
||||
__import__('venv')
|
||||
return True
|
||||
except ImportError:
|
||||
return False
|
||||
|
||||
|
||||
xfailif_no_venv = pytest.mark.xfail(
|
||||
not supports_venv(), reason='Does not support venv module',
|
||||
)
|
||||
|
||||
|
||||
def run_opts(
|
||||
all_files=False,
|
||||
files=(),
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ from testing.util import skipif_cant_run_docker
|
|||
from testing.util import skipif_cant_run_swift
|
||||
from testing.util import xfailif_broken_deep_listdir
|
||||
from testing.util import xfailif_no_pcre_support
|
||||
from testing.util import xfailif_no_venv
|
||||
from testing.util import xfailif_windows_no_ruby
|
||||
|
||||
|
||||
|
|
@ -111,6 +112,15 @@ def test_python_hook_weird_setup_cfg(tempdir_factory, store):
|
|||
)
|
||||
|
||||
|
||||
@xfailif_no_venv
|
||||
def test_python_venv(tempdir_factory, store): # pragma: no cover (no venv)
|
||||
_test_hook_repo(
|
||||
tempdir_factory, store, 'python_venv_hooks_repo',
|
||||
'foo', [os.devnull],
|
||||
b"['" + five.to_bytes(os.devnull) + b"']\nHello World\n",
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_switch_language_versions_doesnt_clobber(tempdir_factory, store):
|
||||
# We're using the python3 repo because it prints the python version
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue