From 788277c4657ace0b74c9be3ea0cb2045c74ff40d Mon Sep 17 00:00:00 2001 From: "abuzarmahmood (aider)" Date: Tue, 6 May 2025 08:29:22 +0000 Subject: [PATCH 1/5] test: add unit tests for functions in bot_tools.py --- tests/test_bot_tools.py | 60 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 tests/test_bot_tools.py diff --git a/tests/test_bot_tools.py b/tests/test_bot_tools.py new file mode 100644 index 0000000..fe31e32 --- /dev/null +++ b/tests/test_bot_tools.py @@ -0,0 +1,60 @@ +import unittest +from src.bot_tools import ( + get_local_repo_path, + search_for_pattern, + search_for_file, + estimate_tokens, + readfile, + readlines +) + +class TestBotTools(unittest.TestCase): + + def test_get_local_repo_path_exists(self): + # Assuming a known repo path for testing + repo_name = "known_owner/known_repo" + expected_path = "/home/exouser/Desktop/blech_github_bot/src/repos/known_owner/known_repo" + self.assertEqual(get_local_repo_path(repo_name), expected_path) + + def test_get_local_repo_path_not_exists(self): + repo_name = "unknown_owner/unknown_repo" + expected_message = "Repository unknown_owner/unknown_repo not found @ /home/exouser/Desktop/blech_github_bot/src/repos/unknown_owner/unknown_repo" + self.assertEqual(get_local_repo_path(repo_name), expected_message) + + def test_search_for_pattern(self): + search_dir = "/home/exouser/Desktop/blech_github_bot/src" + pattern = "def " + result = search_for_pattern(search_dir, pattern) + self.assertIn("bot_tools.py", result) + + def test_search_for_file_exists(self): + directory = "/home/exouser/Desktop/blech_github_bot/src" + filename = "bot_tools.py" + result = search_for_file(directory, filename) + self.assertIn("bot_tools.py", result) + + def test_search_for_file_not_exists(self): + directory = "/home/exouser/Desktop/blech_github_bot/src" + filename = "non_existent_file.py" + result = search_for_file(directory, filename) + self.assertEqual(result, "File not found") + + def test_estimate_tokens(self): + text = "This is a test sentence." + self.assertEqual(estimate_tokens(text), 5) + + empty_text = "" + self.assertEqual(estimate_tokens(empty_text), 0) + + def test_readfile(self): + filepath = "/home/exouser/Desktop/blech_github_bot/src/bot_tools.py" + content = readfile(filepath) + self.assertIn("def get_local_repo_path", content) + + def test_readlines(self): + filepath = "/home/exouser/Desktop/blech_github_bot/src/bot_tools.py" + content = readlines(filepath, 0, 10) + self.assertIn("def get_local_repo_path", content) + +if __name__ == '__main__': + unittest.main() From 5e84c1ef5d255e672ea86e400d92274d4061e549 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:29:31 +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_bot_tools.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_bot_tools.py b/tests/test_bot_tools.py index fe31e32..d208e62 100644 --- a/tests/test_bot_tools.py +++ b/tests/test_bot_tools.py @@ -8,6 +8,7 @@ readlines ) + class TestBotTools(unittest.TestCase): def test_get_local_repo_path_exists(self): @@ -56,5 +57,6 @@ def test_readlines(self): content = readlines(filepath, 0, 10) self.assertIn("def get_local_repo_path", content) + if __name__ == '__main__': unittest.main() From cb92f510b7f8d0019e70e06168f7569f492f4861 Mon Sep 17 00:00:00 2001 From: "abuzarmahmood (aider)" Date: Tue, 6 May 2025 08:39:15 +0000 Subject: [PATCH 3/5] refactor: convert tests in test_bot_tools.py from unittest to pytest --- tests/test_bot_tools.py | 98 +++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 52 deletions(-) diff --git a/tests/test_bot_tools.py b/tests/test_bot_tools.py index d208e62..8a8bb10 100644 --- a/tests/test_bot_tools.py +++ b/tests/test_bot_tools.py @@ -1,4 +1,4 @@ -import unittest +import pytest from src.bot_tools import ( get_local_repo_path, search_for_pattern, @@ -9,54 +9,48 @@ ) -class TestBotTools(unittest.TestCase): - - def test_get_local_repo_path_exists(self): - # Assuming a known repo path for testing - repo_name = "known_owner/known_repo" - expected_path = "/home/exouser/Desktop/blech_github_bot/src/repos/known_owner/known_repo" - self.assertEqual(get_local_repo_path(repo_name), expected_path) - - def test_get_local_repo_path_not_exists(self): - repo_name = "unknown_owner/unknown_repo" - expected_message = "Repository unknown_owner/unknown_repo not found @ /home/exouser/Desktop/blech_github_bot/src/repos/unknown_owner/unknown_repo" - self.assertEqual(get_local_repo_path(repo_name), expected_message) - - def test_search_for_pattern(self): - search_dir = "/home/exouser/Desktop/blech_github_bot/src" - pattern = "def " - result = search_for_pattern(search_dir, pattern) - self.assertIn("bot_tools.py", result) - - def test_search_for_file_exists(self): - directory = "/home/exouser/Desktop/blech_github_bot/src" - filename = "bot_tools.py" - result = search_for_file(directory, filename) - self.assertIn("bot_tools.py", result) - - def test_search_for_file_not_exists(self): - directory = "/home/exouser/Desktop/blech_github_bot/src" - filename = "non_existent_file.py" - result = search_for_file(directory, filename) - self.assertEqual(result, "File not found") - - def test_estimate_tokens(self): - text = "This is a test sentence." - self.assertEqual(estimate_tokens(text), 5) - - empty_text = "" - self.assertEqual(estimate_tokens(empty_text), 0) - - def test_readfile(self): - filepath = "/home/exouser/Desktop/blech_github_bot/src/bot_tools.py" - content = readfile(filepath) - self.assertIn("def get_local_repo_path", content) - - def test_readlines(self): - filepath = "/home/exouser/Desktop/blech_github_bot/src/bot_tools.py" - content = readlines(filepath, 0, 10) - self.assertIn("def get_local_repo_path", content) - - -if __name__ == '__main__': - unittest.main() +def test_get_local_repo_path_exists(): + # Assuming a known repo path for testing + repo_name = "known_owner/known_repo" + expected_path = "/home/exouser/Desktop/blech_github_bot/src/repos/known_owner/known_repo" + assert get_local_repo_path(repo_name) == expected_path + +def test_get_local_repo_path_not_exists(): + repo_name = "unknown_owner/unknown_repo" + expected_message = "Repository unknown_owner/unknown_repo not found @ /home/exouser/Desktop/blech_github_bot/src/repos/unknown_owner/unknown_repo" + assert get_local_repo_path(repo_name) == expected_message + +def test_search_for_pattern(): + search_dir = "/home/exouser/Desktop/blech_github_bot/src" + pattern = "def " + result = search_for_pattern(search_dir, pattern) + assert "bot_tools.py" in result + +def test_search_for_file_exists(): + directory = "/home/exouser/Desktop/blech_github_bot/src" + filename = "bot_tools.py" + result = search_for_file(directory, filename) + assert "bot_tools.py" in result + +def test_search_for_file_not_exists(): + directory = "/home/exouser/Desktop/blech_github_bot/src" + filename = "non_existent_file.py" + result = search_for_file(directory, filename) + assert result == "File not found" + +def test_estimate_tokens(): + text = "This is a test sentence." + assert estimate_tokens(text) == 5 + + empty_text = "" + assert estimate_tokens(empty_text) == 0 + +def test_readfile(): + filepath = "/home/exouser/Desktop/blech_github_bot/src/bot_tools.py" + content = readfile(filepath) + assert "def get_local_repo_path" in content + +def test_readlines(): + filepath = "/home/exouser/Desktop/blech_github_bot/src/bot_tools.py" + content = readlines(filepath, 0, 10) + assert "def get_local_repo_path" in content From 64762f492513fe6c1edd69f2deab719accef85ea 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:39:22 +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_bot_tools.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_bot_tools.py b/tests/test_bot_tools.py index 8a8bb10..7042644 100644 --- a/tests/test_bot_tools.py +++ b/tests/test_bot_tools.py @@ -15,29 +15,34 @@ def test_get_local_repo_path_exists(): expected_path = "/home/exouser/Desktop/blech_github_bot/src/repos/known_owner/known_repo" assert get_local_repo_path(repo_name) == expected_path + def test_get_local_repo_path_not_exists(): repo_name = "unknown_owner/unknown_repo" expected_message = "Repository unknown_owner/unknown_repo not found @ /home/exouser/Desktop/blech_github_bot/src/repos/unknown_owner/unknown_repo" assert get_local_repo_path(repo_name) == expected_message + def test_search_for_pattern(): search_dir = "/home/exouser/Desktop/blech_github_bot/src" pattern = "def " result = search_for_pattern(search_dir, pattern) assert "bot_tools.py" in result + def test_search_for_file_exists(): directory = "/home/exouser/Desktop/blech_github_bot/src" filename = "bot_tools.py" result = search_for_file(directory, filename) assert "bot_tools.py" in result + def test_search_for_file_not_exists(): directory = "/home/exouser/Desktop/blech_github_bot/src" filename = "non_existent_file.py" result = search_for_file(directory, filename) assert result == "File not found" + def test_estimate_tokens(): text = "This is a test sentence." assert estimate_tokens(text) == 5 @@ -45,11 +50,13 @@ def test_estimate_tokens(): empty_text = "" assert estimate_tokens(empty_text) == 0 + def test_readfile(): filepath = "/home/exouser/Desktop/blech_github_bot/src/bot_tools.py" content = readfile(filepath) assert "def get_local_repo_path" in content + def test_readlines(): filepath = "/home/exouser/Desktop/blech_github_bot/src/bot_tools.py" content = readlines(filepath, 0, 10) From 9982767028a22fbbaa3f16f7e217a4d11f078222 Mon Sep 17 00:00:00 2001 From: "abuzarmahmood (aider)" Date: Tue, 6 May 2025 08:53:47 +0000 Subject: [PATCH 5/5] ci: update GitHub workflow to include tests for bot_tools.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..299c631 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_bot_tools.py -v --cov --cov-branch --cov-report=xml - name: Upload coverage to Codecov uses: codecov/codecov-action@v5