Skip to content

Commit 857a898

Browse files
authored
add returncode check for subprocesses (#34)
1 parent cca4403 commit 857a898

File tree

6 files changed

+47
-26
lines changed

6 files changed

+47
-26
lines changed

test/test_add.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ def test_add(xtl_clone, git2cpp_path, all_flag):
1919
cmd_add.append(all_flag)
2020
else:
2121
cmd_add.append("mook_file.txt")
22-
subprocess.run(cmd_add, cwd=working_dir, text=True)
22+
p_add = subprocess.run(cmd_add, cwd=working_dir, text=True)
23+
assert p_add.returncode == 0
2324

2425
cmd_status = [git2cpp_path, 'status', "--long"]
2526
p_status = subprocess.run(cmd_status, cwd=working_dir, capture_output=True, text=True)
27+
assert p_status.returncode == 0
2628

2729
assert "Changes to be committed" in p_status.stdout
2830
assert "new file" in p_status.stdout

test/test_branch.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,21 @@
99
def test_branch_list(xtl_clone, git2cpp_path):
1010
cmd = [git2cpp_path, 'branch']
1111
p = subprocess.run(cmd, capture_output=True, cwd=working_dir, text=True)
12+
assert p.returncode == 0
1213
assert(p.stdout == '* master\n')
1314

1415

1516
def test_branch_create_delete(xtl_clone, git2cpp_path):
1617
create_cmd = [git2cpp_path, 'branch', 'foregone']
17-
subprocess.run(create_cmd, capture_output=True, cwd=working_dir, text=True)
18+
p_create = subprocess.run(create_cmd, capture_output=True, cwd=working_dir, text=True)
19+
assert p_create.returncode == 0
1820
list_cmd = [git2cpp_path, 'branch']
19-
p = subprocess.run(list_cmd, capture_output=True, cwd=working_dir, text=True)
20-
assert(p.stdout == ' foregone\n* master\n')
21+
p_list = subprocess.run(list_cmd, capture_output=True, cwd=working_dir, text=True)
22+
assert p_list.returncode == 0
23+
assert(p_list.stdout == ' foregone\n* master\n')
2124

2225
del_cmd = [git2cpp_path, 'branch', '-d', 'foregone']
2326
subprocess.run(del_cmd, capture_output=True, cwd=working_dir, text=True)
24-
p2 = subprocess.run(list_cmd, capture_output=True, cwd=working_dir, text=True)
25-
assert(p2.stdout == '* master\n')
27+
p_list2 = subprocess.run(list_cmd, capture_output=True, cwd=working_dir, text=True)
28+
assert p_list2.returncode == 0
29+
assert(p_list2.stdout == '* master\n')

test/test_checkout.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,44 @@
88

99
def test_checkout(xtl_clone, git2cpp_path):
1010
create_cmd = [git2cpp_path, 'branch', 'foregone']
11-
subprocess.run(create_cmd, capture_output=True, cwd=working_dir, text=True)
11+
p_create = subprocess.run(create_cmd, capture_output=True, cwd=working_dir, text=True)
12+
assert p_create.returncode == 0
1213

1314
checkout_cmd = [git2cpp_path, 'checkout', 'foregone']
14-
p = subprocess.run(checkout_cmd, capture_output=True, cwd=working_dir, text=True)
15-
assert(p.stdout == '');
15+
p_checkout = subprocess.run(checkout_cmd, capture_output=True, cwd=working_dir, text=True)
16+
assert p_checkout.returncode == 0
17+
assert(p_checkout.stdout == '');
1618

1719
branch_cmd = [git2cpp_path, 'branch']
18-
p2 = subprocess.run(branch_cmd, capture_output=True, cwd=working_dir, text=True)
19-
assert(p2.stdout == '* foregone\n master\n')
20+
p_branch = subprocess.run(branch_cmd, capture_output=True, cwd=working_dir, text=True)
21+
assert p_branch.returncode == 0
22+
assert(p_branch.stdout == '* foregone\n master\n')
2023

2124
checkout_cmd[2] = 'master'
22-
subprocess.run(checkout_cmd, capture_output=True, cwd=working_dir, text=True)
25+
p_checkout2 = subprocess.run(checkout_cmd, capture_output=True, cwd=working_dir, text=True)
26+
assert p_checkout2.returncode == 0
2327

2428
del_cmd = [git2cpp_path, 'branch', '-d', 'foregone']
25-
subprocess.run(del_cmd, cwd=working_dir, text=True)
29+
p_del = subprocess.run(del_cmd, cwd=working_dir, text=True)
30+
assert p_del.returncode == 0
2631

2732

2833
def test_checkout_b(xtl_clone, git2cpp_path):
2934
checkout_cmd = [git2cpp_path, 'checkout', '-b', 'foregone']
30-
p = subprocess.run(checkout_cmd, capture_output=True, cwd=working_dir, text=True)
31-
assert(p.stdout == '');
35+
p_checkout = subprocess.run(checkout_cmd, capture_output=True, cwd=working_dir, text=True)
36+
assert p_checkout.returncode == 0
37+
assert(p_checkout.stdout == '');
3238

3339
branch_cmd = [git2cpp_path, 'branch']
34-
p2 = subprocess.run(branch_cmd, capture_output=True, cwd=working_dir, text=True)
35-
assert(p2.stdout == '* foregone\n master\n')
40+
p_branch = subprocess.run(branch_cmd, capture_output=True, cwd=working_dir, text=True)
41+
assert p_branch.returncode == 0
42+
assert(p_branch.stdout == '* foregone\n master\n')
3643

3744
checkout_cmd.remove('-b')
3845
checkout_cmd[2] = 'master'
39-
subprocess.run(checkout_cmd, cwd=working_dir, text=True)
46+
p_checkout2 = subprocess.run(checkout_cmd, cwd=working_dir, text=True)
47+
assert p_checkout2.returncode == 0
4048

4149
del_cmd = [git2cpp_path, 'branch', '-d', 'foregone']
42-
subprocess.run(del_cmd, cwd=working_dir, text=True)
50+
p_del = subprocess.run(del_cmd, cwd=working_dir, text=True)
51+
assert p_del.returncode == 0

test/test_clone.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ def test_clone(git2cpp_path):
99
working_dir = 'test/data'
1010

1111
clone_cmd = [git2cpp_path, 'clone', url]
12-
subprocess.run(clone_cmd, capture_output=True, cwd = working_dir, text=True)
12+
p_clone = subprocess.run(clone_cmd, capture_output=True, cwd = working_dir, text=True)
13+
assert p_clone.returncode == 0
1314

1415
assert os.path.exists(working_dir + '/xtl')
1516
assert os.path.exists(working_dir + '/xtl/include')
1617

1718
cleanup_cmd = ['rm', '-rf', 'xtl']
18-
subprocess.run(cleanup_cmd, capture_output=True, cwd = working_dir, text=True)
19+
p_cleanup = subprocess.run(cleanup_cmd, capture_output=True, cwd = working_dir, text=True)
20+
assert p_cleanup.returncode == 0

test/test_commit.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,20 @@ def test_commit(xtl_clone, git_config, git2cpp_path, monkeypatch, all_flag):
1212
pass
1313

1414
cmd_add = [git2cpp_path, 'add', "mook_file.txt"]
15-
subprocess.run(cmd_add, cwd=working_dir, text=True)
15+
p_add = subprocess.run(cmd_add, cwd=working_dir, text=True)
16+
assert p_add.returncode == 0
1617

1718
cmd_status = [git2cpp_path, 'status', "--long"]
1819
p_status = subprocess.run(cmd_status, capture_output=True, cwd=working_dir, text=True)
19-
20+
assert p_status.returncode == 0
2021
assert "Changes to be committed" in p_status.stdout
2122
assert "new file" in p_status.stdout
2223

2324
cmd_commit = [git2cpp_path, 'commit', "-m", "test commit"]
24-
subprocess.run(cmd_commit, cwd=working_dir, text=True)
25+
p_commit = subprocess.run(cmd_commit, cwd=working_dir, text=True)
26+
assert p_commit.returncode == 0
2527

2628
cmd_status_2 = [git2cpp_path, 'status', "--long"]
2729
p_status_2 = subprocess.run(cmd_status_2, capture_output=True, cwd=working_dir, text=True)
28-
30+
assert p_status_2.returncode == 0
2931
assert "mook_file" not in p_status_2.stdout

test/test_status.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def test_status_new_file(xtl_clone, git2cpp_path, short_flag, long_flag):
2424
if long_flag != "":
2525
cmd.append(long_flag)
2626
p = subprocess.run(cmd, capture_output=True, cwd=working_dir, text=True)
27+
assert p.returncode == 0
2728

2829
if (long_flag == "--long") or ((long_flag == "") & (short_flag == "")):
2930
assert "On branch master" in p.stdout
@@ -47,7 +48,8 @@ def test_status_add_file(xtl_clone, git2cpp_path, short_flag, long_flag):
4748
os.remove("./test/data/xtl/README.md") # Changes to be committed / deleted
4849

4950
cmd_add = [git2cpp_path, 'add', "--all"]
50-
subprocess.run(cmd_add, cwd=working_dir, text=True)
51+
p = subprocess.run(cmd_add, cwd=working_dir, text=True)
52+
assert p.returncode == 0
5153

5254
cmd_status = [git2cpp_path, 'status']
5355
if short_flag != "":

0 commit comments

Comments
 (0)