Skip to content

Commit f0ea04f

Browse files
committed
Use correct run-time path to git2cpp binary
1 parent f42361e commit f0ea04f

File tree

3 files changed

+29
-23
lines changed

3 files changed

+29
-23
lines changed

test/conftest.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import os
2+
from pathlib import Path
3+
import pytest
4+
5+
6+
# Fixture to run test in current tmp_path
7+
@pytest.fixture
8+
def run_in_tmp_path(tmp_path):
9+
original_cwd = os.getcwd()
10+
os.chdir(tmp_path)
11+
yield
12+
os.chdir(original_cwd)
13+
14+
15+
@pytest.fixture(scope='session')
16+
def git2cpp_path():
17+
return Path(__file__).parent.parent / 'build' / 'git2cpp'

test/test_git.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33

44

55
@pytest.mark.parametrize("arg", ['-v', '--version'])
6-
def test_version(arg):
7-
cmd = ['build/git2cpp', arg]
6+
def test_version(git2cpp_path, arg):
7+
cmd = [git2cpp_path, arg]
88
p = subprocess.run(cmd, capture_output=True)
99
assert p.returncode == 0
1010
assert p.stderr == b''
1111
assert p.stdout.startswith(b'git2cpp ')
1212

1313

14-
def test_error_on_unknown_option():
15-
cmd = ['build/git2cpp', '--unknown']
14+
def test_error_on_unknown_option(git2cpp_path):
15+
cmd = [git2cpp_path, '--unknown']
1616
p = subprocess.run(cmd, capture_output=True)
1717
assert p.returncode == 1
1818
assert p.stdout == b''

test/test_init.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
1-
import os
21
from pathlib import Path
3-
import pytest
42
import subprocess
53

64

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):
176
# tmp_path exists and is empty.
187
assert list(tmp_path.iterdir()) == []
198

20-
cmd = ['/Users/iant/github/git2cpp/build/git2cpp', 'init', '--bare', str(tmp_path)]
9+
cmd = [git2cpp_path, 'init', '--bare', str(tmp_path)]
2110
p = subprocess.run(cmd, capture_output=True)
2211
assert p.returncode == 0
2312
assert p.stdout == b''
@@ -30,12 +19,12 @@ def test_init_in_directory(tmp_path):
3019
# TODO: check this is a valid git repo
3120

3221

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):
3423
# tmp_path exists and is empty.
3524
assert list(tmp_path.iterdir()) == []
3625
assert Path.cwd() == tmp_path
3726

38-
cmd = ['/Users/iant/github/git2cpp/build/git2cpp', 'init', '--bare']
27+
cmd = [git2cpp_path, 'init', '--bare']
3928
p = subprocess.run(cmd, capture_output=True)
4029
assert p.returncode == 0
4130
assert p.stdout == b''
@@ -51,16 +40,16 @@ def test_init_in_cwd(tmp_path, run_in_tmp_path):
5140
# TODO: Test without bare flag.
5241

5342

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']
5645
p = subprocess.run(cmd, capture_output=True)
5746
assert p.returncode == 1
5847
assert p.stdout == b''
5948
assert p.stderr.startswith(b"The following argument was not expected: --unknown")
6049

6150

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']
6453
p = subprocess.run(cmd, capture_output=True)
6554
assert p.returncode == 1
6655
assert p.stdout == b''

0 commit comments

Comments
 (0)