From 89bfc657fb75f8d2db0e7f277c2082cf6f134d37 Mon Sep 17 00:00:00 2001 From: "abuzarmahmood (aider)" Date: Tue, 6 May 2025 08:30:30 +0000 Subject: [PATCH 1/5] test: add unit tests for functions in agents.py --- tests/test_agents.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/test_agents.py diff --git a/tests/test_agents.py b/tests/test_agents.py new file mode 100644 index 0000000..74b976b --- /dev/null +++ b/tests/test_agents.py @@ -0,0 +1,44 @@ +import unittest +from src.agents import register_functions, create_user_agent, create_agent, parse_comments, generate_prompt +from autogen import ConversableAgent, AssistantAgent, UserProxyAgent +from github.Issue import Issue +from unittest.mock import MagicMock + +class TestAgents(unittest.TestCase): + + def test_register_functions(self): + agent = MagicMock(spec=ConversableAgent) + registered_agent = register_functions(agent) + self.assertIsInstance(registered_agent, ConversableAgent) + + def test_create_user_agent(self): + user_agent = create_user_agent() + self.assertIsInstance(user_agent, UserProxyAgent) + + def test_create_agent(self): + agent_name = "edit_assistant" + llm_config = {"key": "value"} + agent = create_agent(agent_name, llm_config) + self.assertIsInstance(agent, AssistantAgent) + + def test_parse_comments(self): + repo_name = "test_repo" + repo_path = "/path/to/repo" + details = {} + issue = MagicMock(spec=Issue) + last_comment_str, comments_str, all_comments = parse_comments(repo_name, repo_path, details, issue) + self.assertIsInstance(last_comment_str, str) + self.assertIsInstance(comments_str, str) + self.assertIsInstance(all_comments, list) + + def test_generate_prompt(self): + agent_name = "edit_assistant" + repo_name = "test_repo" + repo_path = "/path/to/repo" + details = {"title": "Test Title", "body": "Test Body"} + issue = MagicMock(spec=Issue) + prompt = generate_prompt(agent_name, repo_name, repo_path, details, issue) + self.assertIsInstance(prompt, str) + +if __name__ == '__main__': + unittest.main() From 53932fc6f921056c4bc9d2aa891a3508c1c5138d 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:30:38 +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_agents.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/test_agents.py b/tests/test_agents.py index 74b976b..0b21c28 100644 --- a/tests/test_agents.py +++ b/tests/test_agents.py @@ -4,6 +4,7 @@ from github.Issue import Issue from unittest.mock import MagicMock + class TestAgents(unittest.TestCase): def test_register_functions(self): @@ -26,7 +27,8 @@ def test_parse_comments(self): repo_path = "/path/to/repo" details = {} issue = MagicMock(spec=Issue) - last_comment_str, comments_str, all_comments = parse_comments(repo_name, repo_path, details, issue) + last_comment_str, comments_str, all_comments = parse_comments( + repo_name, repo_path, details, issue) self.assertIsInstance(last_comment_str, str) self.assertIsInstance(comments_str, str) self.assertIsInstance(all_comments, list) @@ -37,8 +39,10 @@ def test_generate_prompt(self): repo_path = "/path/to/repo" details = {"title": "Test Title", "body": "Test Body"} issue = MagicMock(spec=Issue) - prompt = generate_prompt(agent_name, repo_name, repo_path, details, issue) + prompt = generate_prompt( + agent_name, repo_name, repo_path, details, issue) self.assertIsInstance(prompt, str) + if __name__ == '__main__': unittest.main() From f18899062df8f3036ceed28b3532e851341baf48 Mon Sep 17 00:00:00 2001 From: "abuzarmahmood (aider)" Date: Tue, 6 May 2025 08:40:26 +0000 Subject: [PATCH 3/5] refactor: convert tests in test_agents.py from unittest to pytest --- tests/test_agents.py | 78 ++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 42 deletions(-) diff --git a/tests/test_agents.py b/tests/test_agents.py index 0b21c28..55d1f25 100644 --- a/tests/test_agents.py +++ b/tests/test_agents.py @@ -1,48 +1,42 @@ -import unittest +import pytest from src.agents import register_functions, create_user_agent, create_agent, parse_comments, generate_prompt from autogen import ConversableAgent, AssistantAgent, UserProxyAgent from github.Issue import Issue from unittest.mock import MagicMock -class TestAgents(unittest.TestCase): - - def test_register_functions(self): - agent = MagicMock(spec=ConversableAgent) - registered_agent = register_functions(agent) - self.assertIsInstance(registered_agent, ConversableAgent) - - def test_create_user_agent(self): - user_agent = create_user_agent() - self.assertIsInstance(user_agent, UserProxyAgent) - - def test_create_agent(self): - agent_name = "edit_assistant" - llm_config = {"key": "value"} - agent = create_agent(agent_name, llm_config) - self.assertIsInstance(agent, AssistantAgent) - - def test_parse_comments(self): - repo_name = "test_repo" - repo_path = "/path/to/repo" - details = {} - issue = MagicMock(spec=Issue) - last_comment_str, comments_str, all_comments = parse_comments( - repo_name, repo_path, details, issue) - self.assertIsInstance(last_comment_str, str) - self.assertIsInstance(comments_str, str) - self.assertIsInstance(all_comments, list) - - def test_generate_prompt(self): - agent_name = "edit_assistant" - repo_name = "test_repo" - repo_path = "/path/to/repo" - details = {"title": "Test Title", "body": "Test Body"} - issue = MagicMock(spec=Issue) - prompt = generate_prompt( - agent_name, repo_name, repo_path, details, issue) - self.assertIsInstance(prompt, str) - - -if __name__ == '__main__': - unittest.main() +def test_register_functions(): + agent = MagicMock(spec=ConversableAgent) + registered_agent = register_functions(agent) + assert isinstance(registered_agent, ConversableAgent) + +def test_create_user_agent(): + user_agent = create_user_agent() + assert isinstance(user_agent, UserProxyAgent) + +def test_create_agent(): + agent_name = "edit_assistant" + llm_config = {"key": "value"} + agent = create_agent(agent_name, llm_config) + assert isinstance(agent, AssistantAgent) + +def test_parse_comments(): + repo_name = "test_repo" + repo_path = "/path/to/repo" + details = {} + issue = MagicMock(spec=Issue) + last_comment_str, comments_str, all_comments = parse_comments( + repo_name, repo_path, details, issue) + assert isinstance(last_comment_str, str) + assert isinstance(comments_str, str) + assert isinstance(all_comments, list) + +def test_generate_prompt(): + agent_name = "edit_assistant" + repo_name = "test_repo" + repo_path = "/path/to/repo" + details = {"title": "Test Title", "body": "Test Body"} + issue = MagicMock(spec=Issue) + prompt = generate_prompt( + agent_name, repo_name, repo_path, details, issue) + assert isinstance(prompt, str) From dc53b936ba7d3e2554d22b818d9faad7b8ad7c58 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:40:34 +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_agents.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_agents.py b/tests/test_agents.py index 55d1f25..46c4970 100644 --- a/tests/test_agents.py +++ b/tests/test_agents.py @@ -10,16 +10,19 @@ def test_register_functions(): registered_agent = register_functions(agent) assert isinstance(registered_agent, ConversableAgent) + def test_create_user_agent(): user_agent = create_user_agent() assert isinstance(user_agent, UserProxyAgent) + def test_create_agent(): agent_name = "edit_assistant" llm_config = {"key": "value"} agent = create_agent(agent_name, llm_config) assert isinstance(agent, AssistantAgent) + def test_parse_comments(): repo_name = "test_repo" repo_path = "/path/to/repo" @@ -31,6 +34,7 @@ def test_parse_comments(): assert isinstance(comments_str, str) assert isinstance(all_comments, list) + def test_generate_prompt(): agent_name = "edit_assistant" repo_name = "test_repo" From 2d85b25c206b2d8b5c960438326924d51a633933 Mon Sep 17 00:00:00 2001 From: "abuzarmahmood (aider)" Date: Tue, 6 May 2025 08:54:34 +0000 Subject: [PATCH 5/5] ci: update workflow to include new tests for agents.py --- .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..b9009b8 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_agents.py -v --cov --cov-branch --cov-report=xml - name: Upload coverage to Codecov uses: codecov/codecov-action@v5