69 lines
2.1 KiB
Python
69 lines
2.1 KiB
Python
"""
|
|
Unit tests for the state management module.
|
|
"""
|
|
import pytest
|
|
from src.pr_reviewer.state import FileInfo, ContextOverrides, PRReviewState
|
|
from datetime import datetime
|
|
|
|
|
|
def test_file_info_creation():
|
|
"""Test creating a FileInfo instance."""
|
|
file_info = FileInfo(
|
|
path="src/main.py",
|
|
content="print('hello')",
|
|
status="modified",
|
|
additions=5,
|
|
deletions=2
|
|
)
|
|
|
|
assert file_info.path == "src/main.py"
|
|
assert file_info.content == "print('hello')"
|
|
assert file_info.status == "modified"
|
|
assert file_info.additions == 5
|
|
assert file_info.deletions == 2
|
|
|
|
|
|
def test_context_overrides_creation():
|
|
"""Test creating a ContextOverrides instance."""
|
|
context_overrides = ContextOverrides(
|
|
code_review="Follow PEP8",
|
|
security_review="Check for SQL injection",
|
|
infra_review="Validate Dockerfile"
|
|
)
|
|
|
|
assert context_overrides.code_review == "Follow PEP8"
|
|
assert context_overrides.security_review == "Check for SQL injection"
|
|
assert context_overrides.infra_review == "Validate Dockerfile"
|
|
|
|
|
|
def test_context_overrides_partial():
|
|
"""Test creating a ContextOverrides instance with partial fields."""
|
|
context_overrides = ContextOverrides(
|
|
code_review="Follow PEP8"
|
|
)
|
|
|
|
assert context_overrides.code_review == "Follow PEP8"
|
|
assert context_overrides.security_review is None
|
|
assert context_overrides.infra_review is None
|
|
|
|
|
|
def test_pr_review_state_creation():
|
|
"""Test creating a PRReviewState instance."""
|
|
state = PRReviewState(
|
|
pr_id="123",
|
|
pr_title="Add feature",
|
|
repo_name="test-repo",
|
|
repo_url="https://github.com/user/test-repo",
|
|
branch="feature",
|
|
base_branch="main"
|
|
)
|
|
|
|
assert state.pr_id == "123"
|
|
assert state.pr_title == "Add feature"
|
|
assert state.repo_name == "test-repo"
|
|
assert state.repo_url == "https://github.com/user/test-repo"
|
|
assert state.branch == "feature"
|
|
assert state.base_branch == "main"
|
|
assert state.files == []
|
|
assert state.started_at is None
|
|
assert state.completed_at is None |