-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_status.py
More file actions
93 lines (70 loc) · 3.13 KB
/
test_status.py
File metadata and controls
93 lines (70 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# from pathlib import Path
import os
import subprocess
import pytest
@pytest.mark.parametrize("short_flag", ["", "-s", "--short"])
@pytest.mark.parametrize("long_flag", ["", "--long"])
def test_status_new_file(xtl_clone, git2cpp_path, tmp_path, short_flag, long_flag):
assert (tmp_path / "xtl").exists()
xtl_path = tmp_path / "xtl"
p = xtl_path / "mook_file.txt" # Untracked files
p.write_text("")
pw = xtl_path / "CMakeLists.txt" # Changes not staged for commit / modified
pw.write_text("blablabla")
os.remove(xtl_path / "README.md") # Changes not staged for commit / deleted
cmd = [git2cpp_path, "status"]
if short_flag != "":
cmd.append(short_flag)
if long_flag != "":
cmd.append(long_flag)
p = subprocess.run(cmd, capture_output=True, cwd=xtl_path, text=True)
if (long_flag == "--long") or ((long_flag == "") & (short_flag == "")):
assert "On branch master" in p.stdout
assert "Changes not staged for commit" in p.stdout
assert "Untracked files" in p.stdout
assert "deleted" in p.stdout
assert "modified" in p.stdout
elif short_flag in ["-s", "--short"]:
assert " M " in p.stdout
assert " D " in p.stdout
assert "?? " in p.stdout
def test_status_nogit(git2cpp_path, tmp_path):
cmd = [git2cpp_path, "status"]
p = subprocess.run(cmd, capture_output=True, cwd=tmp_path, text=True)
assert p.returncode != 0
@pytest.mark.parametrize("short_flag", ["", "-s", "--short"])
@pytest.mark.parametrize("long_flag", ["", "--long"])
def test_status_add_file(xtl_clone, git2cpp_path, tmp_path, short_flag, long_flag):
assert (tmp_path / "xtl").exists()
xtl_path = tmp_path / "xtl"
p = xtl_path / "mook_file.txt" # Changes to be committed / new file
p.write_text("")
os.remove(xtl_path / "README.md") # Changes to be committed / deleted
cmd_add = [git2cpp_path, "add", "--all"]
p_add = subprocess.run(cmd_add, cwd=xtl_path, text=True)
assert p_add.returncode == 0
cmd_status = [git2cpp_path, "status"]
if short_flag != "":
cmd_status.append(short_flag)
if long_flag != "":
cmd_status.append(long_flag)
p_status = subprocess.run(cmd_status, capture_output=True, cwd=xtl_path, text=True)
assert p_status.returncode == 0
if (long_flag == "--long") or ((long_flag == "") & (short_flag == "")):
assert "Changes to be committed" in p_status.stdout
assert "Changes not staged for commit" not in p_status.stdout
assert "Untracked files" not in p_status.stdout
assert "new file" in p_status.stdout
assert "deleted" in p_status.stdout
elif short_flag in ["-s", "--short"]:
assert "A " in p_status.stdout
assert "D " in p_status.stdout
def test_status_new_repo(git2cpp_path, tmp_path, run_in_tmp_path):
# tmp_path exists and is empty.
assert list(tmp_path.iterdir()) == []
cmd = [git2cpp_path, "init"]
p = subprocess.run(cmd, cwd=tmp_path)
assert p.returncode == 0
status_cmd = [git2cpp_path, "status"]
p_status = subprocess.run(status_cmd, cwd=tmp_path)
assert p_status.returncode == 0