1
- import os
2
1
from pathlib import Path
3
- import pytest
4
2
import subprocess
5
3
6
4
7
- # Fixture to run test in current tmp_path
8
- @pytest .fixture
9
- def run_in_tmp_path (tmp_path ):
10
- original_cwd = os .getcwd ()
11
- os .chdir (tmp_path )
12
- yield
13
- os .chdir (original_cwd )
14
-
15
-
16
- def test_init_in_directory (tmp_path ):
5
+ def test_init_in_directory (git2cpp_path , tmp_path ):
17
6
# tmp_path exists and is empty.
18
7
assert list (tmp_path .iterdir ()) == []
19
8
20
- cmd = ['/Users/iant/github/git2cpp/build/git2cpp' , 'init' , '--bare' , str (tmp_path )]
9
+ cmd = [git2cpp_path , 'init' , '--bare' , str (tmp_path )]
21
10
p = subprocess .run (cmd , capture_output = True )
22
11
assert p .returncode == 0
23
12
assert p .stdout == b''
@@ -30,12 +19,12 @@ def test_init_in_directory(tmp_path):
30
19
# TODO: check this is a valid git repo
31
20
32
21
33
- def test_init_in_cwd (tmp_path , run_in_tmp_path ):
22
+ def test_init_in_cwd (git2cpp_path , tmp_path , run_in_tmp_path ):
34
23
# tmp_path exists and is empty.
35
24
assert list (tmp_path .iterdir ()) == []
36
25
assert Path .cwd () == tmp_path
37
26
38
- cmd = ['/Users/iant/github/git2cpp/build/git2cpp' , 'init' , '--bare' ]
27
+ cmd = [git2cpp_path , 'init' , '--bare' ]
39
28
p = subprocess .run (cmd , capture_output = True )
40
29
assert p .returncode == 0
41
30
assert p .stdout == b''
@@ -51,16 +40,16 @@ def test_init_in_cwd(tmp_path, run_in_tmp_path):
51
40
# TODO: Test without bare flag.
52
41
53
42
54
- def test_error_on_unknown_option ():
55
- cmd = ['build/git2cpp' , 'init' , '--unknown' ]
43
+ def test_error_on_unknown_option (git2cpp_path ):
44
+ cmd = [git2cpp_path , 'init' , '--unknown' ]
56
45
p = subprocess .run (cmd , capture_output = True )
57
46
assert p .returncode == 1
58
47
assert p .stdout == b''
59
48
assert p .stderr .startswith (b"The following argument was not expected: --unknown" )
60
49
61
50
62
- def test_error_on_repeated_directory ():
63
- cmd = ['build/git2cpp' , 'init' , 'abc' , 'def' ]
51
+ def test_error_on_repeated_directory (git2cpp_path ):
52
+ cmd = [git2cpp_path , 'init' , 'abc' , 'def' ]
64
53
p = subprocess .run (cmd , capture_output = True )
65
54
assert p .returncode == 1
66
55
assert p .stdout == b''
0 commit comments