mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-15 01:51:46 +04:00
Adds failing test for cwd problem.
This commit is contained in:
parent
d4c9f9075e
commit
aa9c77abe8
6 changed files with 69 additions and 28 deletions
4
testing/resources/prints_cwd_repo/manifest.yaml
Normal file
4
testing/resources/prints_cwd_repo/manifest.yaml
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
- id: prints_cwd
|
||||||
|
name: Prints Cwd
|
||||||
|
entry: prints_cwd
|
||||||
|
language: python
|
||||||
0
testing/resources/prints_cwd_repo/prints_cwd/__init__.py
Normal file
0
testing/resources/prints_cwd_repo/prints_cwd/__init__.py
Normal file
5
testing/resources/prints_cwd_repo/prints_cwd/main.py
Normal file
5
testing/resources/prints_cwd_repo/prints_cwd/main.py
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
import os
|
||||||
|
|
||||||
|
def func():
|
||||||
|
print os.getcwd()
|
||||||
|
return 0
|
||||||
11
testing/resources/prints_cwd_repo/setup.py
Normal file
11
testing/resources/prints_cwd_repo/setup.py
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
from setuptools import find_packages
|
||||||
|
from setuptools import setup
|
||||||
|
|
||||||
|
setup(
|
||||||
|
name='prints_cwd',
|
||||||
|
version='0.0.0',
|
||||||
|
packages=find_packages('.'),
|
||||||
|
entry_points={
|
||||||
|
'console_scripts': ['prints_cwd = prints_cwd.main:func'],
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
@ -32,37 +32,33 @@ def dummy_git_repo(empty_git_dir):
|
||||||
yield empty_git_dir
|
yield empty_git_dir
|
||||||
|
|
||||||
|
|
||||||
|
def _make_repo(repo_path, repo_source):
|
||||||
|
copy_tree_to_path(get_resource_path(repo_source), repo_path)
|
||||||
|
add_and_commit()
|
||||||
|
return repo_path
|
||||||
|
|
||||||
|
|
||||||
@pytest.yield_fixture
|
@pytest.yield_fixture
|
||||||
def python_hooks_repo(dummy_git_repo):
|
def python_hooks_repo(dummy_git_repo):
|
||||||
copy_tree_to_path(
|
yield _make_repo(dummy_git_repo, 'python_hooks_repo')
|
||||||
get_resource_path('python_hooks_repo'),
|
|
||||||
dummy_git_repo,
|
|
||||||
)
|
|
||||||
add_and_commit()
|
|
||||||
yield dummy_git_repo
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.yield_fixture
|
@pytest.yield_fixture
|
||||||
def node_hooks_repo(dummy_git_repo):
|
def node_hooks_repo(dummy_git_repo):
|
||||||
copy_tree_to_path(
|
yield _make_repo(dummy_git_repo, 'node_hooks_repo')
|
||||||
get_resource_path('node_hooks_repo'),
|
|
||||||
dummy_git_repo,
|
|
||||||
)
|
|
||||||
add_and_commit()
|
|
||||||
yield dummy_git_repo
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.yield_fixture
|
@pytest.yield_fixture
|
||||||
def consumer_repo(dummy_git_repo):
|
def consumer_repo(dummy_git_repo):
|
||||||
copy_tree_to_path(
|
yield _make_repo(dummy_git_repo, 'consumer_repo')
|
||||||
get_resource_path('consumer_repo'),
|
|
||||||
dummy_git_repo,
|
|
||||||
)
|
|
||||||
add_and_commit()
|
|
||||||
yield dummy_git_repo
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.yield_fixture
|
||||||
|
def prints_cwd_repo(dummy_git_repo):
|
||||||
|
yield _make_repo(dummy_git_repo, 'prints_cwd_repo')
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.yield_fixture
|
||||||
def config_for_node_hooks_repo(node_hooks_repo):
|
def config_for_node_hooks_repo(node_hooks_repo):
|
||||||
config = {
|
config = {
|
||||||
'repo': node_hooks_repo,
|
'repo': node_hooks_repo,
|
||||||
|
|
@ -74,11 +70,10 @@ def config_for_node_hooks_repo(node_hooks_repo):
|
||||||
}
|
}
|
||||||
jsonschema.validate([config], CONFIG_JSON_SCHEMA)
|
jsonschema.validate([config], CONFIG_JSON_SCHEMA)
|
||||||
validate_config_extra([config])
|
validate_config_extra([config])
|
||||||
|
yield config
|
||||||
return config
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.yield_fixture
|
||||||
def config_for_python_hooks_repo(python_hooks_repo):
|
def config_for_python_hooks_repo(python_hooks_repo):
|
||||||
config = {
|
config = {
|
||||||
'repo': python_hooks_repo,
|
'repo': python_hooks_repo,
|
||||||
|
|
@ -90,5 +85,19 @@ def config_for_python_hooks_repo(python_hooks_repo):
|
||||||
}
|
}
|
||||||
jsonschema.validate([config], CONFIG_JSON_SCHEMA)
|
jsonschema.validate([config], CONFIG_JSON_SCHEMA)
|
||||||
validate_config_extra([config])
|
validate_config_extra([config])
|
||||||
|
yield config
|
||||||
|
|
||||||
return config
|
|
||||||
|
@pytest.yield_fixture
|
||||||
|
def config_for_prints_cwd_repo(prints_cwd_repo):
|
||||||
|
config = {
|
||||||
|
'repo': prints_cwd_repo,
|
||||||
|
'sha': git.get_head_sha(prints_cwd_repo),
|
||||||
|
'hooks': [{
|
||||||
|
'id': 'prints_cwd',
|
||||||
|
'files': '\.py$',
|
||||||
|
}],
|
||||||
|
}
|
||||||
|
jsonschema.validate([config], CONFIG_JSON_SCHEMA)
|
||||||
|
validate_config_extra([config])
|
||||||
|
yield config
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import pytest
|
||||||
import pre_commit.constants as C
|
import pre_commit.constants as C
|
||||||
from pre_commit import git
|
from pre_commit import git
|
||||||
from pre_commit.clientlib.validate_config import CONFIG_JSON_SCHEMA
|
from pre_commit.clientlib.validate_config import CONFIG_JSON_SCHEMA
|
||||||
|
from pre_commit.clientlib.validate_config import validate_config_extra
|
||||||
from pre_commit.repository import Repository
|
from pre_commit.repository import Repository
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -28,13 +29,13 @@ def test_create_repo_in_env(dummy_repo_config, dummy_git_repo):
|
||||||
)
|
)
|
||||||
|
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
def test_install_python_repo_in_env(python_hooks_repo, config_for_python_hooks_repo):
|
def test_install_python_repo_in_env(config_for_python_hooks_repo):
|
||||||
repo = Repository(config_for_python_hooks_repo)
|
repo = Repository(config_for_python_hooks_repo)
|
||||||
repo.install()
|
repo.install()
|
||||||
|
|
||||||
assert os.path.exists(
|
assert os.path.exists(
|
||||||
os.path.join(
|
os.path.join(
|
||||||
python_hooks_repo,
|
repo.repo_url,
|
||||||
C.HOOKS_WORKSPACE,
|
C.HOOKS_WORKSPACE,
|
||||||
repo.sha,
|
repo.sha,
|
||||||
'py_env',
|
'py_env',
|
||||||
|
|
@ -61,6 +62,17 @@ def test_run_a_hook_lots_of_files(config_for_python_hooks_repo):
|
||||||
assert ret[0] == 0
|
assert ret[0] == 0
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.xfail
|
||||||
|
@pytest.mark.integration
|
||||||
|
def test_cwd_of_hook(config_for_prints_cwd_repo):
|
||||||
|
repo = Repository(config_for_prints_cwd_repo)
|
||||||
|
repo.install()
|
||||||
|
ret = repo.run_hook('prints_cwd', [])
|
||||||
|
|
||||||
|
assert ret[0] == 0
|
||||||
|
assert ret[1] == '{0}\n'.format(repo.repo_url)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(
|
@pytest.mark.skipif(
|
||||||
os.environ.get('slowtests', None) == 'false',
|
os.environ.get('slowtests', None) == 'false',
|
||||||
reason="TODO: make this test not super slow",
|
reason="TODO: make this test not super slow",
|
||||||
|
|
@ -74,6 +86,7 @@ def test_run_a_node_hook(config_for_node_hooks_repo):
|
||||||
assert ret[0] == 0
|
assert ret[0] == 0
|
||||||
assert ret[1] == 'Hello World\n'
|
assert ret[1] == 'Hello World\n'
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_repo_config():
|
def mock_repo_config():
|
||||||
config = {
|
config = {
|
||||||
|
|
@ -81,12 +94,11 @@ def mock_repo_config():
|
||||||
'sha': '5e713f8878b7d100c0e059f8cc34be4fc2e8f897',
|
'sha': '5e713f8878b7d100c0e059f8cc34be4fc2e8f897',
|
||||||
'hooks': [{
|
'hooks': [{
|
||||||
'id': 'pyflakes',
|
'id': 'pyflakes',
|
||||||
'files': '*.py',
|
'files': '\.py$',
|
||||||
}],
|
}],
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonschema.validate([config], CONFIG_JSON_SCHEMA)
|
jsonschema.validate([config], CONFIG_JSON_SCHEMA)
|
||||||
|
validate_config_extra([config])
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue