Add test fixtures and unit tests for CLI, models, and formatters
This commit is contained in:
@@ -1,53 +1,32 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
from src.models.data_structures import Author, Commit
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from unittest.mock import MagicMock, patch
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_commit():
|
def sample_commit():
|
||||||
"""Create a mock commit object."""
|
"""Create a sample commit for testing."""
|
||||||
commit = MagicMock()
|
return Commit(
|
||||||
commit.sha = "abc123"
|
sha="abc123def456",
|
||||||
commit.message = "Test commit"
|
message="Add new feature",
|
||||||
commit.author_name = "John Doe"
|
author="Test User",
|
||||||
commit.author_email = "john@test.com"
|
author_email="test@example.com",
|
||||||
commit.committed_datetime = datetime(2024, 1, 15, 10, 30, 0)
|
timestamp=datetime(2024, 1, 15, 10, 30, 0),
|
||||||
commit.author_datetime = datetime(2024, 1, 15, 10, 30, 0)
|
lines_added=50,
|
||||||
commit.additions = 50
|
lines_deleted=10,
|
||||||
commit.deletions = 10
|
files_changed=["src/new_feature.py"],
|
||||||
commit.files_changed = ["src/main.py", "tests/test.py"]
|
is_merge=False,
|
||||||
commit.parents = []
|
is_revert=False,
|
||||||
commit.is_merge = False
|
)
|
||||||
commit.is_revert = False
|
|
||||||
commit.lines_changed_count = 60
|
|
||||||
return commit
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_repo():
|
def sample_author():
|
||||||
"""Create a mock git repository."""
|
"""Create a sample author for testing."""
|
||||||
repo = MagicMock()
|
return Author(
|
||||||
return repo
|
name="Test User",
|
||||||
|
email="test@example.com",
|
||||||
|
commit_count=42,
|
||||||
@pytest.fixture
|
lines_added=5000,
|
||||||
def sample_commits():
|
lines_deleted=1000,
|
||||||
"""Create a list of sample commits."""
|
)
|
||||||
commits = []
|
|
||||||
for i in range(10):
|
|
||||||
commit = MagicMock()
|
|
||||||
commit.sha = f"sha{i}"
|
|
||||||
commit.message = f"Commit {i}"
|
|
||||||
commit.author_name = "John Doe"
|
|
||||||
commit.author_email = "john@test.com"
|
|
||||||
commit.committed_datetime = datetime(2024, 1, i + 1, 10, 0, 0)
|
|
||||||
commit.author_datetime = datetime(2024, 1, i + 1, 10, 0, 0)
|
|
||||||
commit.additions = 10 * i
|
|
||||||
commit.deletions = 5 * i
|
|
||||||
commit.files_changed = [f"src/file{i}.py"]
|
|
||||||
commit.parents = []
|
|
||||||
commit.is_merge = False
|
|
||||||
commit.is_revert = False
|
|
||||||
commit.lines_changed_count = 15 * i
|
|
||||||
commits.append(commit)
|
|
||||||
return commits
|
|
||||||
|
|||||||
Reference in New Issue
Block a user