Skip to content

Commit b3a7376

Browse files
committed
docs: enhance docstrings and add test coverage
- Update docstrings in __main__.py and prompt.py to clarify usage of 'previous_commit_message' parameter - Add new test file test_prompt.py to cover basic, template, previous message, and instruction scenarios These changes improve the clarity of the documentation and ensure that the commit message generation process is thoroughly tested.
1 parent d31ac87 commit b3a7376

File tree

3 files changed

+72
-4
lines changed

3 files changed

+72
-4
lines changed

gcop/__main__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ def generate_commit_message(
6565
Args:
6666
diff(str): git diff
6767
instruction(Optional[str]): additional instruction. Defaults to None.
68-
previous_commit_message(Optional[str]): previous commit message. Defaults to
69-
None.
68+
previous_commit_message(Optional[str]): previous commit message. At the first
69+
time, it's usually empty. It always uses when you are improving the
70+
commit message or providing feedback. Defaults to None.
7071
7172
Returns:
7273
str: git commit message with ai generated.

gcop/prompt.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ def get_commit_instrcution(
9191
diff (str): git diff
9292
commit_template (Optional[str], optional): commit template. Defaults to None.
9393
instruction (Optional[str], optional): additional instruction. Defaults to None.
94-
previous_commit_message (Optional[str], optional): previous commit message.
95-
Defaults to None.
94+
previous_commit_message (Optional[str], optional): previous commit message. At
95+
the first time, it's usually empty. It always uses when you are
96+
improving the commit message or providing feedback.
9697
9798
Returns:
9899
str: system prompt for generating commit messages

tests/test_prompt.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import pytest
2+
3+
from gcop.prompt import get_commit_instrcution
4+
5+
6+
def test_get_commit_instruction_basic():
7+
"""Test basic commit instruction generation."""
8+
diff = "test diff content"
9+
result = get_commit_instrcution(diff)
10+
assert isinstance(result, str)
11+
assert "test diff content" in result
12+
13+
14+
def test_get_commit_instruction_with_template():
15+
"""Test commit instruction with custom template."""
16+
diff = "test diff"
17+
template = """
18+
<example>
19+
feat: custom template
20+
</example>
21+
"""
22+
result = get_commit_instrcution(diff, commit_template=template)
23+
assert isinstance(result, str)
24+
assert "custom template" in result
25+
assert "test diff" in result
26+
27+
28+
def test_get_commit_instruction_with_previous():
29+
"""Test commit instruction with previous commit message."""
30+
diff = "test diff"
31+
prev_msg = "fix: previous commit"
32+
result = get_commit_instrcution(diff, previous_commit_message=prev_msg)
33+
assert isinstance(result, str)
34+
assert "previous commit" in result
35+
assert "test diff" in result
36+
37+
38+
def test_get_commit_instruction_with_instruction():
39+
"""Test commit instruction with additional instruction."""
40+
diff = "test diff"
41+
instruction = "Please make it more detailed"
42+
result = get_commit_instrcution(diff, instruction=instruction)
43+
assert isinstance(result, str)
44+
assert "Please make it more detailed" in result
45+
assert "test diff" in result
46+
47+
48+
def test_get_commit_instruction_all_params():
49+
"""Test commit instruction with all parameters."""
50+
diff = "test diff"
51+
template = "<example>template</example>"
52+
prev_msg = "previous message"
53+
instruction = "make it better"
54+
55+
result = get_commit_instrcution(
56+
diff,
57+
commit_template=template,
58+
previous_commit_message=prev_msg,
59+
instruction=instruction,
60+
)
61+
62+
assert isinstance(result, str)
63+
assert "test diff" in result
64+
assert "template" in result
65+
assert "previous message" in result
66+
assert "make it better" in result

0 commit comments

Comments
 (0)