Skip to content

Commit

Permalink
docs: enhance docstrings and add test coverage
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
Undertone0809 committed Nov 7, 2024
1 parent d31ac87 commit b3a7376
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 4 deletions.
5 changes: 3 additions & 2 deletions gcop/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ def generate_commit_message(
Args:
diff(str): git diff
instruction(Optional[str]): additional instruction. Defaults to None.
previous_commit_message(Optional[str]): previous commit message. Defaults to
None.
previous_commit_message(Optional[str]): previous commit message. At the first
time, it's usually empty. It always uses when you are improving the
commit message or providing feedback. Defaults to None.
Returns:
str: git commit message with ai generated.
Expand Down
5 changes: 3 additions & 2 deletions gcop/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ def get_commit_instrcution(
diff (str): git diff
commit_template (Optional[str], optional): commit template. Defaults to None.
instruction (Optional[str], optional): additional instruction. Defaults to None.
previous_commit_message (Optional[str], optional): previous commit message.
Defaults to None.
previous_commit_message (Optional[str], optional): previous commit message. At
the first time, it's usually empty. It always uses when you are
improving the commit message or providing feedback.
Returns:
str: system prompt for generating commit messages
Expand Down
66 changes: 66 additions & 0 deletions tests/test_prompt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import pytest

from gcop.prompt import get_commit_instrcution


def test_get_commit_instruction_basic():
"""Test basic commit instruction generation."""
diff = "test diff content"
result = get_commit_instrcution(diff)
assert isinstance(result, str)
assert "test diff content" in result


def test_get_commit_instruction_with_template():
"""Test commit instruction with custom template."""
diff = "test diff"
template = """
<example>
feat: custom template
</example>
"""
result = get_commit_instrcution(diff, commit_template=template)
assert isinstance(result, str)
assert "custom template" in result
assert "test diff" in result


def test_get_commit_instruction_with_previous():
"""Test commit instruction with previous commit message."""
diff = "test diff"
prev_msg = "fix: previous commit"
result = get_commit_instrcution(diff, previous_commit_message=prev_msg)
assert isinstance(result, str)
assert "previous commit" in result
assert "test diff" in result


def test_get_commit_instruction_with_instruction():
"""Test commit instruction with additional instruction."""
diff = "test diff"
instruction = "Please make it more detailed"
result = get_commit_instrcution(diff, instruction=instruction)
assert isinstance(result, str)
assert "Please make it more detailed" in result
assert "test diff" in result


def test_get_commit_instruction_all_params():
"""Test commit instruction with all parameters."""
diff = "test diff"
template = "<example>template</example>"
prev_msg = "previous message"
instruction = "make it better"

result = get_commit_instrcution(
diff,
commit_template=template,
previous_commit_message=prev_msg,
instruction=instruction,
)

assert isinstance(result, str)
assert "test diff" in result
assert "template" in result
assert "previous message" in result
assert "make it better" in result

0 comments on commit b3a7376

Please sign in to comment.