Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
63 changes: 63 additions & 0 deletions tests/test_bot_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import pytest
from src.bot_tools import (
get_local_repo_path,
search_for_pattern,
search_for_file,
estimate_tokens,
readfile,
readlines
)


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
Loading