Skip to content

Add pytest test suite for commit-ai#47

Open
hanu-14 wants to merge 1 commit into
josharsh:mainfrom
hanu-14:main
Open

Add pytest test suite for commit-ai#47
hanu-14 wants to merge 1 commit into
josharsh:mainfrom
hanu-14:main

Conversation

@hanu-14

@hanu-14 hanu-14 commented Jul 16, 2026

Copy link
Copy Markdown

Changes

Add comprehensive test suite for commit-ai with mocked external calls (no API key needed to run tests).

What's covered (13 tests)

  • get_diff: staged/unstaged modes, empty diffs, whitespace stripping
  • get_branch: branch name retrieval
  • get_recent_commits: commit history parsing
  • generate_commit_message: mocked Anthropic API, large diff truncation (4000 chars), conventional vs simple format
  • generate: empty diff error, full pipeline, auto-commit subprocess mock

Files

  • commit-ai/test_commit.py - 133 lines, 13 test cases across 6 test classes
  • commit-ai/pytest.ini - test discovery config
  • commit-ai/README.md - add Testing section

Run: cd commit-ai && pip install pytest anthropic && pytest

Closes #20

Add comprehensive pytest test suite for commit-ai covering:
- Git diff parsing (staged/unstaged, empty diffs)
- Branch name retrieval
- Recent commit history parsing
- Message generation with mocked Anthropic API
- Large diff truncation (4000 char limit)
- Conventional vs simple format prompts
- Auto-commit flow (mock subprocess)
- Empty diff error handling

Also add pytest.ini for test discovery and update README with
testing instructions.

Closes josharsh#20
@hanu-14 hanu-14 closed this Jul 22, 2026
@hanu-14 hanu-14 reopened this Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🧪 Add pytest test suite for commit-ai

1 participant