forked from QuantStack/git2cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_branch.py
More file actions
53 lines (36 loc) · 1.74 KB
/
test_branch.py
File metadata and controls
53 lines (36 loc) · 1.74 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
import subprocess
import pytest
def test_branch_list(repo_init_with_commit, git2cpp_path, tmp_path):
assert (tmp_path / "initial.txt").exists()
cmd = [git2cpp_path, "branch"]
p = subprocess.run(cmd, capture_output=True, cwd=tmp_path, text=True)
assert p.returncode == 0
assert "* ma" in p.stdout
def test_branch_create_delete(repo_init_with_commit, git2cpp_path, tmp_path):
assert (tmp_path / "initial.txt").exists()
create_cmd = [git2cpp_path, "branch", "foregone"]
p_create = subprocess.run(create_cmd, capture_output=True, cwd=tmp_path, text=True)
assert p_create.returncode == 0
list_cmd = [git2cpp_path, "branch"]
p_list = subprocess.run(list_cmd, capture_output=True, cwd=tmp_path, text=True)
assert p_list.returncode == 0
assert " foregone\n* ma" in p_list.stdout
del_cmd = [git2cpp_path, "branch", "-d", "foregone"]
p_del = subprocess.run(del_cmd, capture_output=True, cwd=tmp_path, text=True)
assert p_del.returncode == 0
p_list2 = subprocess.run(list_cmd, capture_output=True, cwd=tmp_path, text=True)
assert p_list2.returncode == 0
assert "* ma" in p_list2.stdout
def test_branch_nogit(git2cpp_path, tmp_path):
cmd = [git2cpp_path, "branch"]
p = subprocess.run(cmd, capture_output=True, cwd=tmp_path, text=True)
assert p.returncode != 0
assert "error: could not find repository at" in p.stderr
def test_branch_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"]
subprocess.run(cmd, cwd=tmp_path, check=True)
branch_cmd = [git2cpp_path, "branch"]
p_branch = subprocess.run(branch_cmd, cwd=tmp_path)
assert p_branch.returncode == 0