Skip to content

Commit 194edaf

Browse files
committed
refactor(tests): test main and subprocess.call separately
1 parent 2a4feaf commit 194edaf

File tree

1 file changed

+55
-25
lines changed

1 file changed

+55
-25
lines changed

tests/test_hook.py

Lines changed: 55 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44

5-
from conventional_pre_commit.hook import RESULT_SUCCESS, RESULT_FAIL, main
5+
from conventional_pre_commit.hook import RESULT_FAIL, RESULT_SUCCESS, main
66

77

88
@pytest.fixture
@@ -46,6 +46,54 @@ def test_main_success__custom_conventional(conventional_commit_path):
4646
assert result == RESULT_SUCCESS
4747

4848

49+
def test_main_success__conventional_utf8(conventional_utf8_commit_path):
50+
result = main([conventional_utf8_commit_path])
51+
52+
assert result == RESULT_SUCCESS
53+
54+
55+
def test_main_fail__conventional_gbk(conventional_gbk_commit_path):
56+
result = main([conventional_gbk_commit_path])
57+
58+
assert result == RESULT_FAIL
59+
60+
61+
def test_main_fail__conventional_with_scope(conventional_commit_path):
62+
result = main(["--force-scope", conventional_commit_path])
63+
64+
assert result == RESULT_FAIL
65+
66+
67+
def test_main_success__conventional_with_scope(cmd, conventional_commit_with_scope_path):
68+
result = main(["--force-scope", conventional_commit_with_scope_path])
69+
70+
assert result == RESULT_SUCCESS
71+
72+
73+
def test_main_success__fixup_commit(fixup_commit_path):
74+
result = main([fixup_commit_path])
75+
76+
assert result == RESULT_SUCCESS
77+
78+
79+
def test_main_fail__fixup_commit(fixup_commit_path):
80+
result = main(["--strict", fixup_commit_path])
81+
82+
assert result == RESULT_FAIL
83+
84+
85+
def test_main_success__conventional_commit_multi_line(conventional_commit_multi_line_path):
86+
result = main([conventional_commit_multi_line_path])
87+
88+
assert result == RESULT_SUCCESS
89+
90+
91+
def test_main_fail__conventional_commit_bad_multi_line(conventional_commit_bad_multi_line_path):
92+
result = main([conventional_commit_bad_multi_line_path])
93+
94+
assert result == RESULT_FAIL
95+
96+
4997
def test_subprocess_fail__missing_args(cmd):
5098
result = subprocess.call(cmd)
5199

@@ -82,55 +130,37 @@ def test_subprocess_success__custom_conventional(cmd, conventional_commit_path):
82130
assert result == RESULT_SUCCESS
83131

84132

85-
def test_main_success__conventional_utf8(conventional_utf8_commit_path):
86-
result = main([conventional_utf8_commit_path])
87-
88-
assert result == RESULT_SUCCESS
89-
90-
91-
def test_main_fail__conventional_gbk(conventional_gbk_commit_path):
92-
result = main([conventional_gbk_commit_path])
93-
94-
assert result == RESULT_FAIL
95-
96-
97-
def test_main_fail__conventional_with_scope(cmd, conventional_commit_path):
133+
def test_subprocess_fail__conventional_with_scope(cmd, conventional_commit_path):
98134
result = subprocess.call((cmd, "--force-scope", conventional_commit_path))
99135

100136
assert result == RESULT_FAIL
101137

102138

103-
def test_main_success__conventional_with_scope(cmd, conventional_commit_with_scope_path):
139+
def test_subprocess_success__conventional_with_scope(cmd, conventional_commit_with_scope_path):
104140
result = subprocess.call((cmd, "--force-scope", conventional_commit_with_scope_path))
105141

106142
assert result == RESULT_SUCCESS
107143

108144

109-
def test_main_success__fixup_commit(cmd, fixup_commit_path):
145+
def test_subprocess_success__fixup_commit(cmd, fixup_commit_path):
110146
result = subprocess.call((cmd, fixup_commit_path))
111147

112148
assert result == RESULT_SUCCESS
113149

114150

115-
def test_main_success__fail_commit(cmd, fixup_commit_path):
151+
def test_subprocess_fail__fixup_commit(cmd, fixup_commit_path):
116152
result = subprocess.call((cmd, "--strict", fixup_commit_path))
117153

118154
assert result == RESULT_FAIL
119155

120156

121-
def test_main_success__conventional_commit_multi_line(cmd, conventional_commit_multi_line_path):
157+
def test_subprocess_success__conventional_commit_multi_line(cmd, conventional_commit_multi_line_path):
122158
result = subprocess.call((cmd, conventional_commit_multi_line_path))
123159

124160
assert result == RESULT_SUCCESS
125161

126162

127-
def test_main_success__conventional_commit_bad_multi_line(cmd, conventional_commit_bad_multi_line_path):
163+
def test_subprocess_fail__conventional_commit_bad_multi_line(cmd, conventional_commit_bad_multi_line_path):
128164
result = subprocess.call((cmd, conventional_commit_bad_multi_line_path))
129165

130-
assert result == RESULT_SUCCESS
131-
132-
133-
def test_main_success__conventional_commit_bad_multi_line_strict(cmd, conventional_commit_bad_multi_line_path):
134-
result = subprocess.call((cmd, "--strict", conventional_commit_bad_multi_line_path))
135-
136166
assert result == RESULT_FAIL

0 commit comments

Comments
 (0)