Merge pull request #896 from pre-commit/cleanup · precommit/pre-commit@7afb294 · GitHub
Skip to content

Commit 7afb294

Browse files
authored
Merge pull request pre-commit#896 from pre-commit/cleanup
misc cleanup
2 parents 8c550d0 + d46bbc4 commit 7afb294

11 files changed

Lines changed: 99 additions & 158 deletions

File tree

pre_commit/file_lock.py

Lines changed: 2 additions & 2 deletions

pre_commit/languages/node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def get_env_patch(venv):
2828
install_prefix = r'{}\bin'.format(win_venv.strip())
2929
elif sys.platform == 'win32': # pragma: no cover
3030
install_prefix = bin_dir(venv)
31-
else:
31+
else: # pragma: windows no cover
3232
install_prefix = venv
3333
return (
3434
('NODE_VIRTUAL_ENV', venv),

tests/commands/install_uninstall_test.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def test_install_refuses_core_hookspath(in_git_dir, store):
8484
assert install(C.CONFIG_FILE, store)
8585

8686

87-
@xfailif_no_symlink # pragma: no cover (non-windows)
87+
@xfailif_no_symlink # pragma: windows no cover
8888
def test_install_hooks_dead_symlink(in_git_dir, store):
8989
hook = in_git_dir.join('.git/hooks').ensure_dir().join('pre-commit')
9090
os.symlink('/fake/baz', hook.strpath)
@@ -421,17 +421,14 @@ def test_replace_old_commit_script(tempdir_factory, store):
421421
assert NORMAL_PRE_COMMIT_RUN.match(output)
422422

423423

424-
def test_uninstall_doesnt_remove_not_our_hooks(tempdir_factory):
425-
path = git_dir(tempdir_factory)
426-
with cwd(path):
427-
mkdirp(os.path.join(path, '.git/hooks'))
428-
with io.open(os.path.join(path, '.git/hooks/pre-commit'), 'w') as f:
429-
f.write('#!/usr/bin/env bash\necho 1\n')
430-
make_executable(f.name)
424+
def test_uninstall_doesnt_remove_not_our_hooks(in_git_dir):
425+
pre_commit = in_git_dir.join('.git/hooks').ensure_dir().join('pre-commit')
426+
pre_commit.write('#!/usr/bin/env bash\necho 1\n')
427+
make_executable(pre_commit.strpath)
431428

432-
assert uninstall() == 0
429+
assert uninstall() == 0
433430

434-
assert os.path.exists(os.path.join(path, '.git/hooks/pre-commit'))
431+
assert pre_commit.exists()
435432

436433

437434
PRE_INSTALLED = re.compile(

tests/commands/run_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,8 +781,8 @@ def test_include_exclude_base_case(some_filenames):
781781
]
782782

783783

784-
@xfailif_no_symlink
785-
def test_matches_broken_symlink(tmpdir): # pragma: no cover (non-windows)
784+
@xfailif_no_symlink # pragma: windows no cover
785+
def test_matches_broken_symlink(tmpdir):
786786
with tmpdir.as_cwd():
787787
os.symlink('does-not-exist', 'link')
788788
ret = _filter_by_include_exclude({'link'}, '', '^$')

tests/conftest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ def in_tmpdir(tempdir_factory):
6565

6666
@pytest.fixture
6767
def in_git_dir(tmpdir):
68-
with tmpdir.as_cwd():
68+
repo = tmpdir.join('repo').ensure_dir()
69+
with repo.as_cwd():
6970
cmd_output('git', 'init')
70-
yield tmpdir
71+
yield repo
7172

7273

7374
def _make_conflict():

tests/git_test.py

Lines changed: 27 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,45 +9,34 @@
99
from pre_commit import git
1010
from pre_commit.error_handler import FatalError
1111
from pre_commit.util import cmd_output
12-
from testing.fixtures import git_dir
13-
from testing.util import cwd
1412

1513

16-
def test_get_root_at_root(tempdir_factory):
17-
path = git_dir(tempdir_factory)
18-
with cwd(path):
19-
assert os.path.normcase(git.get_root()) == os.path.normcase(path)
14+
def test_get_root_at_root(in_git_dir):
15+
expected = os.path.normcase(in_git_dir.strpath)
16+
assert os.path.normcase(git.get_root()) == expected
2017

2118

22-
def test_get_root_deeper(tempdir_factory):
23-
path = git_dir(tempdir_factory)
19+
def test_get_root_deeper(in_git_dir):
20+
expected = os.path.normcase(in_git_dir.strpath)
21+
with in_git_dir.join('foo').ensure_dir().as_cwd():
22+
assert os.path.normcase(git.get_root()) == expected
2423

25-
foo_path = os.path.join(path, 'foo')
26-
os.mkdir(foo_path)
27-
with cwd(foo_path):
28-
assert os.path.normcase(git.get_root()) == os.path.normcase(path)
2924

25+
def test_get_root_not_git_dir(in_tmpdir):
26+
with pytest.raises(FatalError):
27+
git.get_root()
3028

31-
def test_get_root_not_git_dir(tempdir_factory):
32-
with cwd(tempdir_factory.get()):
33-
with pytest.raises(FatalError):
34-
git.get_root()
3529

30+
def test_get_staged_files_deleted(in_git_dir):
31+
in_git_dir.join('test').ensure()
32+
cmd_output('git', 'add', 'test')
33+
cmd_output('git', 'commit', '-m', 'foo', '--allow-empty')
34+
cmd_output('git', 'rm', '--cached', 'test')
35+
assert git.get_staged_files() == []
3636

37-
def test_get_staged_files_deleted(tempdir_factory):
38-
path = git_dir(tempdir_factory)
39-
with cwd(path):
40-
open('test', 'a').close()
41-
cmd_output('git', 'add', 'test')
42-
cmd_output('git', 'commit', '-m', 'foo', '--allow-empty')
43-
cmd_output('git', 'rm', '--cached', 'test')
44-
assert git.get_staged_files() == []
4537

46-
47-
def test_is_not_in_merge_conflict(tempdir_factory):
48-
path = git_dir(tempdir_factory)
49-
with cwd(path):
50-
assert git.is_in_merge_conflict() is False
38+
def test_is_not_in_merge_conflict(in_git_dir):
39+
assert git.is_in_merge_conflict() is False
5140

5241

5342
def test_is_in_merge_conflict(in_merge_conflict):
@@ -114,11 +103,10 @@ def test_parse_merge_msg_for_conflicts(input, expected_output):
114103
assert ret == expected_output
115104

116105

117-
def test_get_changed_files(in_tmpdir):
118-
cmd_output('git', 'init', '.')
106+
def test_get_changed_files(in_git_dir):
119107
cmd_output('git', 'commit', '--allow-empty', '-m', 'initial commit')
120-
open('a.txt', 'a').close()
121-
open('b.txt', 'a').close()
108+
in_git_dir.join('a.txt').ensure()
109+
in_git_dir.join('b.txt').ensure()
122110
cmd_output('git', 'add', '.')
123111
cmd_output('git', 'commit', '-m', 'add some files')
124112
files = git.get_changed_files('HEAD', 'HEAD^')
@@ -143,15 +131,12 @@ def test_zsplit(s, expected):
143131

144132

145133
@pytest.fixture
146-
def non_ascii_repo(tmpdir):
147-
repo = tmpdir.join('repo').ensure_dir()
148-
with repo.as_cwd():
149-
cmd_output('git', 'init', '.')
150-
cmd_output('git', 'commit', '--allow-empty', '-m', 'initial commit')
151-
repo.join('интервью').ensure()
152-
cmd_output('git', 'add', '.')
153-
cmd_output('git', 'commit', '--allow-empty', '-m', 'initial commit')
154-
yield repo
134+
def non_ascii_repo(in_git_dir):
135+
cmd_output('git', 'commit', '--allow-empty', '-m', 'initial commit')
136+
in_git_dir.join('интервью').ensure()
137+
cmd_output('git', 'add', '.')
138+
cmd_output('git', 'commit', '--allow-empty', '-m', 'initial commit')
139+
yield in_git_dir
155140

156141

157142
def test_all_files_non_ascii(non_ascii_repo):

tests/languages/python_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def test_norm_version_expanduser():
1111
if os.name == 'nt': # pragma: no cover (nt)
1212
path = r'~\python343'
1313
expected_path = r'{}\python343'.format(home)
14-
else: # pragma: no cover (non-nt)
14+
else: # pragma: windows no cover
1515
path = '~/.pyenv/versions/3.4.3/bin/python'
1616
expected_path = home + '/.pyenv/versions/3.4.3/bin/python'
1717
result = python.norm_version(path)

tests/meta_hooks/check_hooks_apply_test.py

Lines changed: 15 additions & 29 deletions

0 commit comments

Comments
 (0)