31 lines
1.0 KiB
Python
31 lines
1.0 KiB
Python
import pytest
|
|
from src.aggregate import group_files_by_dir, compute_file_stats
|
|
from src.models import FileItem
|
|
|
|
def test_group_files_by_dir():
|
|
files = [
|
|
FileItem(path="src/main.py"),
|
|
FileItem(path="src/utils/helpers.py"),
|
|
FileItem(path="tests/test_main.py"),
|
|
FileItem(path="README.md")
|
|
]
|
|
grouped = group_files_by_dir(files)
|
|
assert len(grouped) == 4
|
|
assert grouped["src"] == [files[0]]
|
|
assert grouped["src/utils"] == [files[1]]
|
|
assert grouped["tests"] == [files[2]]
|
|
assert grouped["."] == [files[3]]
|
|
|
|
def test_compute_file_stats():
|
|
import tempfile
|
|
import os
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
# Create a dummy python file
|
|
py_path = os.path.join(temp_dir, "test.py")
|
|
with open(py_path, "w") as f:
|
|
f.write("def foo():\n pass\n\nclass Bar:\n pass\n")
|
|
|
|
stats = compute_file_stats(py_path)
|
|
assert stats["lines"] == 5
|
|
assert stats["ast_elements"] == 2 # 1 func, 1 class
|