Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aa9c77a

Browse files
committed
Adds failing test for cwd problem.
1 parent d4c9f90 commit aa9c77a

6 files changed

Lines changed: 69 additions & 28 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- id: prints_cwd
2+
name: Prints Cwd
3+
entry: prints_cwd
4+
language: python

testing/resources/prints_cwd_repo/prints_cwd/__init__.py

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import os
2+
3+
def func():
4+
print os.getcwd()
5+
return 0
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from setuptools import find_packages
2+
from setuptools import setup
3+
4+
setup(
5+
name='prints_cwd',
6+
version='0.0.0',
7+
packages=find_packages('.'),
8+
entry_points={
9+
'console_scripts': ['prints_cwd = prints_cwd.main:func'],
10+
},
11+
)

tests/conftest.py

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,37 +32,33 @@ def dummy_git_repo(empty_git_dir):
3232
yield empty_git_dir
3333

3434

35+
def _make_repo(repo_path, repo_source):
36+
copy_tree_to_path(get_resource_path(repo_source), repo_path)
37+
add_and_commit()
38+
return repo_path
39+
40+
3541
@pytest.yield_fixture
3642
def python_hooks_repo(dummy_git_repo):
37-
copy_tree_to_path(
38-
get_resource_path('python_hooks_repo'),
39-
dummy_git_repo,
40-
)
41-
add_and_commit()
42-
yield dummy_git_repo
43+
yield _make_repo(dummy_git_repo, 'python_hooks_repo')
4344

4445

4546
@pytest.yield_fixture
4647
def node_hooks_repo(dummy_git_repo):
47-
copy_tree_to_path(
48-
get_resource_path('node_hooks_repo'),
49-
dummy_git_repo,
50-
)
51-
add_and_commit()
52-
yield dummy_git_repo
48+
yield _make_repo(dummy_git_repo, 'node_hooks_repo')
5349

5450

5551
@pytest.yield_fixture
5652
def consumer_repo(dummy_git_repo):
57-
copy_tree_to_path(
58-
get_resource_path('consumer_repo'),
59-
dummy_git_repo,
60-
)
61-
add_and_commit()
62-
yield dummy_git_repo
53+
yield _make_repo(dummy_git_repo, 'consumer_repo')
6354

6455

65-
@pytest.fixture
56+
@pytest.yield_fixture
57+
def prints_cwd_repo(dummy_git_repo):
58+
yield _make_repo(dummy_git_repo, 'prints_cwd_repo')
59+
60+
61+
@pytest.yield_fixture
6662
def config_for_node_hooks_repo(node_hooks_repo):
6763
config = {
6864
'repo': node_hooks_repo,
@@ -74,11 +70,10 @@ def config_for_node_hooks_repo(node_hooks_repo):
7470
}
7571
jsonschema.validate([config], CONFIG_JSON_SCHEMA)
7672
validate_config_extra([config])
77-
78-
return config
73+
yield config
7974

8075

81-
@pytest.fixture
76+
@pytest.yield_fixture
8277
def config_for_python_hooks_repo(python_hooks_repo):
8378
config = {
8479
'repo': python_hooks_repo,
@@ -90,5 +85,19 @@ def config_for_python_hooks_repo(python_hooks_repo):
9085
}
9186
jsonschema.validate([config], CONFIG_JSON_SCHEMA)
9287
validate_config_extra([config])
88+
yield config
89+
9390

94-
return config
91+
@pytest.yield_fixture
92+
def config_for_prints_cwd_repo(prints_cwd_repo):
93+
config = {
94+
'repo': prints_cwd_repo,
95+
'sha': git.get_head_sha(prints_cwd_repo),
96+
'hooks': [{
97+
'id': 'prints_cwd',
98+
'files': '\.py$',
99+
}],
100+
}
101+
jsonschema.validate([config], CONFIG_JSON_SCHEMA)
102+
validate_config_extra([config])
103+
yield config

tests/repository_test.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pre_commit.constants as C
66
from pre_commit import git
77
from pre_commit.clientlib.validate_config import CONFIG_JSON_SCHEMA
8+
from pre_commit.clientlib.validate_config import validate_config_extra
89
from pre_commit.repository import Repository
910

1011

@@ -28,13 +29,13 @@ def test_create_repo_in_env(dummy_repo_config, dummy_git_repo):
2829
)
2930

3031
@pytest.mark.integration
31-
def test_install_python_repo_in_env(python_hooks_repo, config_for_python_hooks_repo):
32+
def test_install_python_repo_in_env(config_for_python_hooks_repo):
3233
repo = Repository(config_for_python_hooks_repo)
3334
repo.install()
3435

3536
assert os.path.exists(
3637
os.path.join(
37-
python_hooks_repo,
38+
repo.repo_url,
3839
C.HOOKS_WORKSPACE,
3940
repo.sha,
4041
'py_env',
@@ -61,6 +62,17 @@ def test_run_a_hook_lots_of_files(config_for_python_hooks_repo):
6162
assert ret[0] == 0
6263

6364

65+
@pytest.mark.xfail
66+
@pytest.mark.integration
67+
def test_cwd_of_hook(config_for_prints_cwd_repo):
68+
repo = Repository(config_for_prints_cwd_repo)
69+
repo.install()
70+
ret = repo.run_hook('prints_cwd', [])
71+
72+
assert ret[0] == 0
73+
assert ret[1] == '{0}\n'.format(repo.repo_url)
74+
75+
6476
@pytest.mark.skipif(
6577
os.environ.get('slowtests', None) == 'false',
6678
reason="TODO: make this test not super slow",
@@ -74,19 +86,19 @@ def test_run_a_node_hook(config_for_node_hooks_repo):
7486
assert ret[0] == 0
7587
assert ret[1] == 'Hello World\n'
7688

89+
7790
@pytest.fixture
7891
def mock_repo_config():
7992
config = {
8093
'repo': '[email protected]:pre-commit/pre-commit-hooks',
8194
'sha': '5e713f8878b7d100c0e059f8cc34be4fc2e8f897',
8295
'hooks': [{
8396
'id': 'pyflakes',
84-
'files': '*.py',
97+
'files': '\.py$',
8598
}],
8699
}
87-
88100
jsonschema.validate([config], CONFIG_JSON_SCHEMA)
89-
101+
validate_config_extra([config])
90102
return config
91103

92104

0 commit comments

Comments
 (0)