feat(context): Implement directory grouping and file stats in context composition panel
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
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
|
||||
Reference in New Issue
Block a user