aider-gitea/test/test_init.py
Jon Michael Aanes ab4aef11e6
Some checks failed
Run Python tests (through Pytest) / Test (push) Failing after 24s
Verify Python project can be installed, loaded and have version checked / Test (push) Successful in 25s
Ruff
2025-04-15 00:31:22 +02:00

93 lines
3.0 KiB
Python

import tempfile
from pathlib import Path
from unittest.mock import MagicMock, patch
def test_init():
import aider_gitea # noqa: F401
import aider_gitea.secrets # noqa: F401
def test_get_current_commit_hash():
from aider_gitea import get_current_commit_hash
with tempfile.TemporaryDirectory() as tmpdirname:
with patch('subprocess.run') as mock_run:
mock_result = MagicMock()
mock_result.stdout = 'abcdef1234567890'
mock_run.return_value = mock_result
result = get_current_commit_hash(Path(tmpdirname))
assert result == 'abcdef1234567890'
mock_run.assert_called_once()
def test_has_changes_since_commit():
from aider_gitea import has_changes_since_commit
with tempfile.TemporaryDirectory() as tmpdirname:
# Test with changes
with patch('subprocess.run') as mock_run:
mock_result = MagicMock()
mock_result.stdout = 'file1.py\nfile2.py'
mock_run.return_value = mock_result
result = has_changes_since_commit(Path(tmpdirname), 'abcdef')
assert result is True
mock_run.assert_called_once()
# Test without changes
with patch('subprocess.run') as mock_run:
mock_result = MagicMock()
mock_result.stdout = ''
mock_run.return_value = mock_result
result = has_changes_since_commit(Path(tmpdirname), 'abcdef')
assert result is False
mock_run.assert_called_once()
def test_solve_issue_with_no_aider_changes():
from aider_gitea import solve_issue_in_repository
with tempfile.TemporaryDirectory() as tmpdirname:
args = MagicMock()
args.gitea_url = 'https://gitea.example.com'
args.owner = 'test-owner'
args.repo = 'test-repo'
args.base_branch = 'main'
with (
patch('aider_gitea.run_cmd', return_value=True) as mock_run_cmd,
patch(
'aider_gitea.get_current_commit_hash', return_value='abcdef',
) as mock_get_hash,
patch(
'aider_gitea.has_changes_since_commit', return_value=False,
) as mock_has_changes,
patch(
'aider_gitea.create_aider_command', return_value=['mock_aider_command'],
) as mock_create_aider,
):
result = solve_issue_in_repository(
args,
Path(tmpdirname),
'issue-123-test',
'Test Issue',
'Test Description',
'123',
None,
)
assert result is False
mock_get_hash.assert_called_once()
mock_has_changes.assert_called_once_with(Path(tmpdirname), 'abcdef')
# Verify that the initial ruff pass was run
assert any(
call_args[0][0] == ['bash', '-c', RUFF_FORMAT_AND_AUTO_FIX]
for call_args in mock_run_cmd.call_args_list
)