99from pre_commit import git
1010from pre_commit .error_handler import FatalError
1111from 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
5342def 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
157142def test_all_files_non_ascii (non_ascii_repo ):
0 commit comments