Skip to content

Commit d089efc

Browse files
committed
Reduce use of xtl_clone in tests
1 parent 1ba9701 commit d089efc

16 files changed

+1318
-960
lines changed

test/conftest.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44

55
import pytest
66

7-
GIT2CPP_TEST_WASM = os.getenv('GIT2CPP_TEST_WASM') == "1"
7+
GIT2CPP_TEST_WASM = os.getenv("GIT2CPP_TEST_WASM") == "1"
88

99
if GIT2CPP_TEST_WASM:
1010
from .conftest_wasm import *
1111

12+
1213
# Fixture to run test in current tmp_path
1314
@pytest.fixture
1415
def run_in_tmp_path(tmp_path):
@@ -21,9 +22,10 @@ def run_in_tmp_path(tmp_path):
2122
@pytest.fixture(scope="session")
2223
def git2cpp_path():
2324
if GIT2CPP_TEST_WASM:
24-
return 'git2cpp'
25+
return "git2cpp"
2526
else:
26-
return Path(__file__).parent.parent / 'build' / 'git2cpp'
27+
return Path(__file__).parent.parent / "build" / "git2cpp"
28+
2729

2830
@pytest.fixture
2931
def xtl_clone(git2cpp_path, tmp_path, run_in_tmp_path):
@@ -39,10 +41,28 @@ def commit_env_config(monkeypatch):
3941
"GIT_AUTHOR_NAME": "Jane Doe",
4042
"GIT_AUTHOR_EMAIL": "jane.doe@blabla.com",
4143
"GIT_COMMITTER_NAME": "Jane Doe",
42-
"GIT_COMMITTER_EMAIL": "jane.doe@blabla.com"
44+
"GIT_COMMITTER_EMAIL": "jane.doe@blabla.com",
4345
}
4446
for key, value in config.items():
4547
if GIT2CPP_TEST_WASM:
4648
subprocess.run(["export", f"{key}='{value}'"], check=True)
4749
else:
4850
monkeypatch.setenv(key, value)
51+
52+
53+
@pytest.fixture
54+
def repo_init_with_commit(commit_env_config, git2cpp_path, tmp_path, run_in_tmp_path):
55+
cmd_init = [git2cpp_path, "init", "."]
56+
p_init = subprocess.run(cmd_init, capture_output=True, cwd=tmp_path, text=True)
57+
assert p_init.returncode == 0
58+
59+
p = tmp_path / "initial.txt"
60+
p.write_text("initial")
61+
62+
cmd_add = [git2cpp_path, "add", "initial.txt"]
63+
p_add = subprocess.run(cmd_add, capture_output=True, cwd=tmp_path, text=True)
64+
assert p_add.returncode == 0
65+
66+
cmd_commit = [git2cpp_path, "commit", "-m", "Initial commit"]
67+
p_commit = subprocess.run(cmd_commit, capture_output=True, cwd=tmp_path, text=True)
68+
assert p_commit.returncode == 0

test/test_add.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,27 @@
44

55

66
@pytest.mark.parametrize("all_flag", ["", "-A", "--all", "--no-ignore-removal"])
7-
def test_add(xtl_clone, git2cpp_path, tmp_path, all_flag):
8-
assert (tmp_path / "xtl").exists()
9-
xtl_path = tmp_path / "xtl"
7+
def test_add(git2cpp_path, tmp_path, all_flag):
8+
cmd_init = [git2cpp_path, "init", "."]
9+
p_init = subprocess.run(cmd_init, capture_output=True, cwd=tmp_path)
10+
assert p_init.returncode == 0
1011

11-
p = xtl_path / "mook_file.txt"
12-
p.write_text('')
12+
p = tmp_path / "mook_file.txt"
13+
p.write_text("")
1314

14-
p2 = xtl_path / "mook_file_2.txt"
15-
p2.write_text('')
15+
p2 = tmp_path / "mook_file_2.txt"
16+
p2.write_text("")
1617

17-
cmd_add = [git2cpp_path, 'add']
18+
cmd_add = [git2cpp_path, "add"]
1819
if all_flag != "":
1920
cmd_add.append(all_flag)
2021
else:
2122
cmd_add.append("mook_file.txt")
22-
p_add = subprocess.run(cmd_add, cwd=xtl_path, text=True)
23+
p_add = subprocess.run(cmd_add, cwd=tmp_path, text=True)
2324
assert p_add.returncode == 0
2425

25-
cmd_status = [git2cpp_path, 'status', "--long"]
26-
p_status = subprocess.run(cmd_status, cwd=xtl_path, capture_output=True, text=True)
26+
cmd_status = [git2cpp_path, "status", "--long"]
27+
p_status = subprocess.run(cmd_status, cwd=tmp_path, capture_output=True, text=True)
2728
assert p_status.returncode == 0
2829

2930
assert "Changes to be committed" in p_status.stdout
@@ -33,11 +34,12 @@ def test_add(xtl_clone, git2cpp_path, tmp_path, all_flag):
3334
else:
3435
assert "Untracked files" in p_status.stdout
3536

37+
3638
def test_add_nogit(git2cpp_path, tmp_path):
3739
p = tmp_path / "mook_file.txt"
38-
p.write_text('')
40+
p.write_text("")
3941

40-
cmd_add = [git2cpp_path, 'add', 'mook_file.txt']
42+
cmd_add = [git2cpp_path, "add", "mook_file.txt"]
4143
p_add = subprocess.run(cmd_add, cwd=tmp_path, text=True, capture_output=True)
4244
assert p_add.returncode != 0
4345
assert "error: could not find repository at" in p_add.stderr

test/test_branch.py

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,51 @@
33
import pytest
44

55

6-
def test_branch_list(xtl_clone, git2cpp_path, tmp_path):
7-
assert (tmp_path / "xtl").exists()
8-
xtl_path = tmp_path / "xtl"
6+
def test_branch_list(repo_init_with_commit, git2cpp_path, tmp_path):
7+
assert (tmp_path / "initial.txt").exists()
98

10-
cmd = [git2cpp_path, 'branch']
11-
p = subprocess.run(cmd, capture_output=True, cwd=xtl_path, text=True)
9+
cmd = [git2cpp_path, "branch"]
10+
p = subprocess.run(cmd, capture_output=True, cwd=tmp_path, text=True)
1211
assert p.returncode == 0
13-
assert(p.stdout == '* master\n')
12+
assert "* ma" in p.stdout
1413

1514

16-
def test_branch_create_delete(xtl_clone, git2cpp_path, tmp_path):
17-
assert (tmp_path / "xtl").exists()
18-
xtl_path = tmp_path / "xtl"
15+
def test_branch_create_delete(repo_init_with_commit, git2cpp_path, tmp_path):
16+
assert (tmp_path / "initial.txt").exists()
1917

20-
create_cmd = [git2cpp_path, 'branch', 'foregone']
21-
p_create = subprocess.run(create_cmd, capture_output=True, cwd=xtl_path, text=True)
18+
create_cmd = [git2cpp_path, "branch", "foregone"]
19+
p_create = subprocess.run(create_cmd, capture_output=True, cwd=tmp_path, text=True)
2220
assert p_create.returncode == 0
2321

24-
list_cmd = [git2cpp_path, 'branch']
25-
p_list = subprocess.run(list_cmd, capture_output=True, cwd=xtl_path, text=True)
22+
list_cmd = [git2cpp_path, "branch"]
23+
p_list = subprocess.run(list_cmd, capture_output=True, cwd=tmp_path, text=True)
2624
assert p_list.returncode == 0
27-
assert(p_list.stdout == ' foregone\n* master\n')
25+
assert " foregone\n* ma" in p_list.stdout
2826

29-
del_cmd = [git2cpp_path, 'branch', '-d', 'foregone']
30-
p_del = subprocess.run(del_cmd, capture_output=True, cwd=xtl_path, text=True)
27+
del_cmd = [git2cpp_path, "branch", "-d", "foregone"]
28+
p_del = subprocess.run(del_cmd, capture_output=True, cwd=tmp_path, text=True)
3129
assert p_del.returncode == 0
3230

33-
p_list2 = subprocess.run(list_cmd, capture_output=True, cwd=xtl_path, text=True)
31+
p_list2 = subprocess.run(list_cmd, capture_output=True, cwd=tmp_path, text=True)
3432
assert p_list2.returncode == 0
35-
assert(p_list2.stdout == '* master\n')
33+
assert "* ma" in p_list2.stdout
34+
3635

3736
def test_branch_nogit(git2cpp_path, tmp_path):
38-
cmd = [git2cpp_path, 'branch']
37+
cmd = [git2cpp_path, "branch"]
3938
p = subprocess.run(cmd, capture_output=True, cwd=tmp_path, text=True)
4039
assert p.returncode != 0
4140
assert "error: could not find repository at" in p.stderr
4241

4342

4443
def test_branch_new_repo(git2cpp_path, tmp_path, run_in_tmp_path):
45-
# tmp_path exists and is empty.
44+
# tmp_path exists and is empty.
4645
assert list(tmp_path.iterdir()) == []
4746

48-
cmd = [git2cpp_path, 'init']
49-
p = subprocess.run(cmd, cwd = tmp_path)
47+
cmd = [git2cpp_path, "init"]
48+
subprocess.run(cmd, cwd=tmp_path, check=True)
5049

51-
branch_cmd = [git2cpp_path, 'branch']
52-
p_branch = subprocess.run(branch_cmd, cwd = tmp_path)
50+
branch_cmd = [git2cpp_path, "branch"]
51+
p_branch = subprocess.run(branch_cmd, cwd=tmp_path)
5352

5453
assert p_branch.returncode == 0

0 commit comments

Comments
 (0)