Skip to content

Commit e579513

Browse files
committed
Enable tests also locally
1 parent 2c646bd commit e579513

9 files changed

Lines changed: 92 additions & 10 deletions

File tree

CLAUDE.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,25 @@ Pearbot is an AI-powered code review tool that analyzes Pull Requests on GitHub
3838
# Install dependencies
3939
pip install .
4040

41+
# Install test dependencies
42+
pip install .[test]
43+
4144
# Install Ollama model (default: llama3.1)
4245
ollama pull llama3.1
4346
```
4447

48+
### Testing
49+
```bash
50+
# Run tests locally
51+
pytest
52+
53+
# Run tests with verbose output
54+
pytest -v
55+
56+
# Run specific test file
57+
pytest tests/test_basic.py
58+
```
59+
4560
### Running the Application
4661

4762
```bash

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ dependencies = [
1616
"pyyaml==6.0.1",
1717
]
1818

19+
[project.optional-dependencies]
20+
test = [
21+
"pytest>=7.0.0",
22+
]
23+
1924
[project.urls]
2025
repository = "https://github.com/rbx/pearbot"
2126

pytest.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[tool:pytest]
2+
testpaths = tests
3+
python_files = test_*.py
4+
python_classes = Test*
5+
python_functions = test_*
6+
addopts = -v

src/agents.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import ollama
22
import yaml
33

4-
from model import post_request_generate
4+
from .model import post_request_generate
55

66
class Agent:
77
def __init__(self, role="code_reviewer", use_post_request=False, prompt_style="default"):

src/pearbot.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
load_dotenv()
77

8-
from storage import get_or_create_session
9-
from agents import Agent
10-
from review_github import GitHubReviewer
11-
from review_local import analyze_diff
12-
from ollama_utils import get_available_models
8+
from .storage import get_or_create_session
9+
from .agents import Agent
10+
from .review_github import GitHubReviewer
11+
from .review_local import analyze_diff
12+
from .ollama_utils import get_available_models
1313

1414
def main():
1515
parser = argparse.ArgumentParser(description="Pearbot Code Review")

src/review_github.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
from github import Github, GithubException
1111
from flask import Flask, request, abort
1212

13-
from ollama_utils import validate_models
14-
from utils import remove_reasoning
13+
from .ollama_utils import validate_models
14+
from .utils import remove_reasoning
1515

1616
class GitHubReviewer:
1717
def __init__(self, code_review_agent, feedback_improver_agent, initial_review_models, final_review_model, skip_reasoning: bool):

src/review_local.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
from colorama import Fore, Style
66

7-
from ollama_utils import validate_models
8-
from utils import remove_reasoning
7+
from .ollama_utils import validate_models
8+
from .utils import remove_reasoning
99

1010
def extract_commit_info(diff_content):
1111
commit_range = None

tests/__init__.py

Whitespace-only changes.

tests/test_basic.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import os
2+
import subprocess
3+
import sys
4+
import pytest
5+
from unittest.mock import patch
6+
7+
def test_module_import():
8+
"""Test that pearbot module can be imported successfully."""
9+
try:
10+
from src import pearbot
11+
assert True, "pearbot module imported successfully"
12+
except ImportError as e:
13+
pytest.fail(f"Failed to import pearbot module: {e}")
14+
15+
def test_help_command():
16+
"""Test that --help command works."""
17+
# Set dummy environment variables like in CI
18+
env = os.environ.copy()
19+
env.update({
20+
'GITHUB_APP_ID': 'dummy_id',
21+
'GITHUB_PRIVATE_KEY': 'dummy_key',
22+
'GITHUB_APP_WEBHOOK_SECRET': 'dummy_secret'
23+
})
24+
25+
result = subprocess.run(
26+
[sys.executable, '-m', 'src.pearbot', '--help'],
27+
capture_output=True,
28+
text=True,
29+
env=env
30+
)
31+
32+
assert result.returncode == 0, f"Help command failed with: {result.stderr}"
33+
assert "Pearbot Code Review" in result.stdout, "Help text should contain 'Pearbot Code Review'"
34+
assert "--server" in result.stdout, "Help should show --server option"
35+
assert "--diff" in result.stdout, "Help should show --diff option"
36+
37+
def test_server_startup():
38+
"""Test that server can start (with timeout like in CI)."""
39+
# Set dummy environment variables like in CI
40+
env = os.environ.copy()
41+
env.update({
42+
'GITHUB_APP_ID': 'dummy_id',
43+
'GITHUB_PRIVATE_KEY': 'dummy_key',
44+
'GITHUB_APP_WEBHOOK_SECRET': 'dummy_secret'
45+
})
46+
47+
# Use timeout like in CI - expect it to timeout (exit code 124) or succeed (exit code 0)
48+
result = subprocess.run(
49+
['timeout', '5s', sys.executable, '-m', 'src.pearbot', '--server'],
50+
capture_output=True,
51+
text=True,
52+
env=env
53+
)
54+
55+
# Exit code 124 means timeout (expected), 0 means success, anything else is failure
56+
assert result.returncode in [0, 124], f"Server startup failed with exit code {result.returncode}: {result.stderr}"

0 commit comments

Comments
 (0)