From f647d408d5f135aaa4612351c85be0c2f7947f9f Mon Sep 17 00:00:00 2001 From: "abuzarmahmood (aider)" Date: Tue, 6 May 2025 08:27:55 +0000 Subject: [PATCH 1/5] test: Add unit tests for functions in git_utils.py --- tests/test_git_utils.py | 51 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 tests/test_git_utils.py diff --git a/tests/test_git_utils.py b/tests/test_git_utils.py new file mode 100644 index 0000000..56974d5 --- /dev/null +++ b/tests/test_git_utils.py @@ -0,0 +1,51 @@ +import unittest +from src.git_utils import ( + clean_response, + add_signature_to_comment, + get_github_client, + get_repository, + get_open_issues, + get_issue_comments, + create_issue_comment, + get_issue_details, + search_issues, + write_issue_response, + clone_repository, + update_repository, + get_pr_branch, + get_development_branch, + create_pull_request, + create_pull_request_from_issue, + push_changes_with_authentication, + is_pull_request, + update_self_repo, + perform_github_search, + has_linked_pr, + get_linked_pr +) +from github import Github +from unittest.mock import patch, MagicMock + +class TestGitUtils(unittest.TestCase): + + @patch('src.git_utils.get_github_client') + def test_get_github_client(self, mock_get_github_client): + mock_get_github_client.return_value = MagicMock(spec=Github) + client = get_github_client() + self.assertIsInstance(client, Github) + + def test_clean_response(self): + response = "This is a test response. " + cleaned_response = clean_response(response) + self.assertNotIn("", cleaned_response) + + def test_add_signature_to_comment(self): + comment_text = "This is a comment." + model = "test-model" + signed_comment = add_signature_to_comment(comment_text, model) + self.assertIn("test-model", signed_comment) + + # Add more tests for other functions... + +if __name__ == '__main__': + unittest.main() From 5716fc91e5a9d20a23f4401b879c2fb044a01015 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 6 May 2025 08:28:04 +0000 Subject: [PATCH 2/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_git_utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_git_utils.py b/tests/test_git_utils.py index 56974d5..add878e 100644 --- a/tests/test_git_utils.py +++ b/tests/test_git_utils.py @@ -26,6 +26,7 @@ from github import Github from unittest.mock import patch, MagicMock + class TestGitUtils(unittest.TestCase): @patch('src.git_utils.get_github_client') @@ -47,5 +48,6 @@ def test_add_signature_to_comment(self): # Add more tests for other functions... + if __name__ == '__main__': unittest.main() From 43634699ab6070d0ea1379f87270032798f39cac Mon Sep 17 00:00:00 2001 From: "abuzarmahmood (aider)" Date: Tue, 6 May 2025 08:37:25 +0000 Subject: [PATCH 3/5] refactor: convert test suite for git_utils.py from unittest to pytest --- tests/test_git_utils.py | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/tests/test_git_utils.py b/tests/test_git_utils.py index add878e..f1c6d0e 100644 --- a/tests/test_git_utils.py +++ b/tests/test_git_utils.py @@ -1,4 +1,4 @@ -import unittest +import pytest from src.git_utils import ( clean_response, add_signature_to_comment, @@ -27,27 +27,21 @@ from unittest.mock import patch, MagicMock -class TestGitUtils(unittest.TestCase): +@patch('src.git_utils.get_github_client') +def test_get_github_client(mock_get_github_client): + mock_get_github_client.return_value = MagicMock(spec=Github) + client = get_github_client() + assert isinstance(client, Github) - @patch('src.git_utils.get_github_client') - def test_get_github_client(self, mock_get_github_client): - mock_get_github_client.return_value = MagicMock(spec=Github) - client = get_github_client() - self.assertIsInstance(client, Github) +def test_clean_response(): + response = "This is a test response. " + cleaned_response = clean_response(response) + assert "" not in cleaned_response - def test_clean_response(self): - response = "This is a test response. " - cleaned_response = clean_response(response) - self.assertNotIn("", cleaned_response) +def test_add_signature_to_comment(): + comment_text = "This is a comment." + model = "test-model" + signed_comment = add_signature_to_comment(comment_text, model) + assert "test-model" in signed_comment - def test_add_signature_to_comment(self): - comment_text = "This is a comment." - model = "test-model" - signed_comment = add_signature_to_comment(comment_text, model) - self.assertIn("test-model", signed_comment) - - # Add more tests for other functions... - - -if __name__ == '__main__': - unittest.main() +# Add more tests for other functions... From 983feb29501e684e6761726b28b4bd5e68a353eb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 6 May 2025 08:37:32 +0000 Subject: [PATCH 4/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_git_utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_git_utils.py b/tests/test_git_utils.py index f1c6d0e..0952b81 100644 --- a/tests/test_git_utils.py +++ b/tests/test_git_utils.py @@ -33,11 +33,13 @@ def test_get_github_client(mock_get_github_client): client = get_github_client() assert isinstance(client, Github) + def test_clean_response(): response = "This is a test response. " cleaned_response = clean_response(response) assert "" not in cleaned_response + def test_add_signature_to_comment(): comment_text = "This is a comment." model = "test-model" From d7643ab2d1619fedc16935649fb5672197a2d086 Mon Sep 17 00:00:00 2001 From: "abuzarmahmood (aider)" Date: Tue, 6 May 2025 08:51:58 +0000 Subject: [PATCH 5/5] ci: update GitHub Actions to run tests for git_utils.py in workflow --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8b03e50..6c821cb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,7 +23,7 @@ jobs: - name: Run tests with coverage run: | - pytest tests/test_triggers.py -v --cov --cov-branch --cov-report=xml + pytest tests/test_triggers.py tests/test_git_utils.py -v --cov --cov-branch --cov-report=xml - name: Upload coverage to Codecov uses: codecov/codecov-action@v5