-
-
Notifications
You must be signed in to change notification settings - Fork 8
feat: support GPG signature check #261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,6 +1,6 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import pytest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from commit_check import PASS, FAIL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from commit_check.commit import check_commit_msg, get_default_commit_msg_file, read_commit_msg, check_commit_signoff, check_imperative | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from commit_check.commit import check_commit_msg, get_default_commit_msg_file, read_commit_msg, check_commit_signoff, check_commit_gpg_signature, check_imperative | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# used by get_commit_info mock | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
FAKE_BRANCH_NAME = "fake_commits_info" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -398,3 +398,168 @@ def test_is_imperative_invalid_cases(): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
for case in invalid_cases: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assert not _is_imperative(case), f"'{case}' should not be imperative mood" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# GPG Signature tests | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@pytest.mark.benchmark | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def test_check_commit_gpg_signature_valid(mocker): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"""Test GPG signature check passes for good signature.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
checks = [{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"check": "gpg_signature", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"regex": "", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"error": "Commit does not have a valid GPG signature", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"suggest": "Use git commit -S to sign commits" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mocker.patch("commit_check.util.cmd_output", return_value="G") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mocker.patch("commit_check.util.get_commit_info", return_value="abc123") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
retval = check_commit_gpg_signature(checks) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assert retval == PASS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@pytest.mark.benchmark | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def test_check_commit_gpg_signature_valid_unknown(mocker): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"""Test GPG signature check passes for good signature with unknown validity.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
checks = [{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"check": "gpg_signature", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"regex": "", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"error": "Commit does not have a valid GPG signature", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"suggest": "Use git commit -S to sign commits" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mocker.patch("commit_check.util.cmd_output", return_value="U") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mocker.patch("commit_check.util.get_commit_info", return_value="abc123") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
retval = check_commit_gpg_signature(checks) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assert retval == PASS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+422
to
+435
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix missing mock for has_commits function. Same issue as the previous test - missing Add the missing mock: mocker.patch("commit_check.util.cmd_output", return_value="U")
mocker.patch("commit_check.util.get_commit_info", return_value="abc123")
+ mocker.patch("commit_check.commit.has_commits", return_value=True) 📝 Committable suggestion
Suggested change
🧰 Tools🪛 GitHub Actions: main[error] 435-435: AssertionError: test_check_commit_gpg_signature_valid_unknown failed. Expected PASS but got failure indicating GPG signature check did not pass for unknown validity. 🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@pytest.mark.benchmark | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def test_check_commit_gpg_signature_no_signature(mocker): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"""Test GPG signature check fails for unsigned commit.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
checks = [{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"check": "gpg_signature", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"regex": "", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"error": "Commit does not have a valid GPG signature", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"suggest": "Use git commit -S to sign commits" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mocker.patch("commit_check.util.cmd_output", return_value="N") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mocker.patch("commit_check.util.get_commit_info", return_value="abc123") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
m_print_error_message = mocker.patch(f"{LOCATION}.print_error_message") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
m_print_suggestion = mocker.patch(f"{LOCATION}.print_suggestion") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
retval = check_commit_gpg_signature(checks) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assert retval == FAIL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assert m_print_error_message.call_count == 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assert m_print_suggestion.call_count == 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+439
to
+457
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add missing has_commits mock for consistency. These tests should also mock Add the missing mock to all GPG signature tests: + mocker.patch("commit_check.commit.has_commits", return_value=True) Also applies to: 460-478, 481-499, 502-520 🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@pytest.mark.benchmark | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def test_check_commit_gpg_signature_bad_signature(mocker): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"""Test GPG signature check fails for bad signature.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
checks = [{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"check": "gpg_signature", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"regex": "", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"error": "Commit does not have a valid GPG signature", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"suggest": "Use git commit -S to sign commits" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mocker.patch("commit_check.util.cmd_output", return_value="B") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mocker.patch("commit_check.util.get_commit_info", return_value="abc123") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
m_print_error_message = mocker.patch(f"{LOCATION}.print_error_message") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
m_print_suggestion = mocker.patch(f"{LOCATION}.print_suggestion") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
retval = check_commit_gpg_signature(checks) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assert retval == FAIL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assert m_print_error_message.call_count == 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assert m_print_suggestion.call_count == 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@pytest.mark.benchmark | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def test_check_commit_gpg_signature_expired(mocker): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"""Test GPG signature check fails for expired signature.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
checks = [{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"check": "gpg_signature", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"regex": "", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"error": "Commit does not have a valid GPG signature", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"suggest": "Use git commit -S to sign commits" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mocker.patch("commit_check.util.cmd_output", return_value="X") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mocker.patch("commit_check.util.get_commit_info", return_value="abc123") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
m_print_error_message = mocker.patch(f"{LOCATION}.print_error_message") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
m_print_suggestion = mocker.patch(f"{LOCATION}.print_suggestion") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
retval = check_commit_gpg_signature(checks) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assert retval == FAIL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assert m_print_error_message.call_count == 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assert m_print_suggestion.call_count == 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@pytest.mark.benchmark | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def test_check_commit_gpg_signature_cannot_check(mocker): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"""Test GPG signature check fails when signature cannot be verified.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
checks = [{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"check": "gpg_signature", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"regex": "", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"error": "Commit does not have a valid GPG signature", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"suggest": "Use git commit -S to sign commits" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mocker.patch("commit_check.util.cmd_output", return_value="E") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mocker.patch("commit_check.util.get_commit_info", return_value="abc123") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
m_print_error_message = mocker.patch(f"{LOCATION}.print_error_message") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
m_print_suggestion = mocker.patch(f"{LOCATION}.print_suggestion") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
retval = check_commit_gpg_signature(checks) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assert retval == FAIL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assert m_print_error_message.call_count == 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assert m_print_suggestion.call_count == 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@pytest.mark.benchmark | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def test_check_commit_gpg_signature_exception(mocker): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"""Test GPG signature check fails when git command throws exception.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
checks = [{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"check": "gpg_signature", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"regex": "", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"error": "Commit does not have a valid GPG signature", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"suggest": "Use git commit -S to sign commits" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mocker.patch("commit_check.util.cmd_output", side_effect=Exception("Git command failed")) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mocker.patch("commit_check.util.get_commit_info", return_value="abc123") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
m_print_error_message = mocker.patch(f"{LOCATION}.print_error_message") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
m_print_suggestion = mocker.patch(f"{LOCATION}.print_suggestion") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
retval = check_commit_gpg_signature(checks) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assert retval == FAIL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assert m_print_error_message.call_count == 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assert m_print_suggestion.call_count == 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+523
to
+541
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix exception test setup and add missing mock. The exception test needs proper mocking and should handle the case where both mocker.patch("commit_check.util.cmd_output", side_effect=Exception("Git command failed"))
- mocker.patch("commit_check.util.get_commit_info", return_value="abc123")
+ mocker.patch("commit_check.util.get_commit_info", return_value="abc123")
+ mocker.patch("commit_check.commit.has_commits", return_value=True) The test should pass with these mocks since the exception handler in the implementation calls 📝 Committable suggestion
Suggested change
🧰 Tools🪛 GitHub Actions: main[error] 537-537: Exception: test_check_commit_gpg_signature_exception failed due to 'Git command failed' exception raised during GPG signature check. 🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@pytest.mark.benchmark | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def test_check_commit_gpg_signature_no_commits(mocker): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"""Test GPG signature check passes when no commits exist.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
checks = [{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"check": "gpg_signature", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"regex": "", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"error": "Commit does not have a valid GPG signature", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"suggest": "Use git commit -S to sign commits" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mocker.patch("commit_check.commit.has_commits", return_value=False) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
retval = check_commit_gpg_signature(checks) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assert retval == PASS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@pytest.mark.benchmark | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def test_check_commit_gpg_signature_empty_checks(mocker): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"""Test GPG signature check with empty checks list.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
checks = [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
retval = check_commit_gpg_signature(checks) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assert retval == PASS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix missing mock for has_commits function.
The test is likely failing because
has_commits()
is not mocked, causing the function to potentially return early with PASS before executing the GPG check logic.Add the missing mock:
mocker.patch("commit_check.util.cmd_output", return_value="G") mocker.patch("commit_check.util.get_commit_info", return_value="abc123") + mocker.patch("commit_check.commit.has_commits", return_value=True)
📝 Committable suggestion
🧰 Tools
🪛 GitHub Actions: main
[error] 418-418: AssertionError: test_check_commit_gpg_signature_valid failed. Expected PASS but got failure indicating GPG signature check did not pass.
🤖 Prompt for AI Agents