- Fixed undefined 'tool' variable in display_history function - Changed '[tool]' markup tag usage to proper Rich syntax - All tests now pass (38/38 unit tests) - Type checking passes with mypy --strict
118 lines
4.2 KiB
Python
118 lines
4.2 KiB
Python
from codesnap.output.markdown_formatter import MarkdownFormatter
|
|
|
|
|
|
class TestMarkdownFormatter:
|
|
def setup_method(self) -> None:
|
|
self.formatter = MarkdownFormatter()
|
|
|
|
def test_format_valid_result(self) -> None:
|
|
result = {
|
|
"files": [
|
|
{
|
|
"file": "test.py",
|
|
"language": "python",
|
|
"lines": 50,
|
|
"functions": [{"name": "test_func", "start_line": 1, "end_line": 10, "parameters": [], "return_type": "str"}],
|
|
"classes": [],
|
|
"complexity": {"score": 5, "rating": "low"}
|
|
}
|
|
],
|
|
"dependency_graph": {
|
|
"total_dependencies": 0,
|
|
"orphaned_files": 0,
|
|
"cycles_detected": 0,
|
|
"cycle_details": [],
|
|
"orphaned_details": [],
|
|
"edges": [],
|
|
"statistics": {}
|
|
}
|
|
}
|
|
output = self.formatter.format(result)
|
|
assert "# CodeSnap Analysis Report" in output
|
|
assert "## Overview" in output
|
|
assert "## File Structure" in output
|
|
assert "## Key Functions" in output
|
|
assert "## Dependencies" in output
|
|
assert "## Complexity Metrics" in output
|
|
|
|
def test_format_empty_result(self) -> None:
|
|
result = {
|
|
"files": [],
|
|
"dependency_graph": {
|
|
"total_dependencies": 0,
|
|
"orphaned_files": 0,
|
|
"cycles_detected": 0,
|
|
"cycle_details": [],
|
|
"orphaned_details": [],
|
|
"edges": [],
|
|
"statistics": {}
|
|
}
|
|
}
|
|
output = self.formatter.format(result)
|
|
assert "Total Files" in output
|
|
|
|
def test_includes_language_breakdown(self) -> None:
|
|
result = {
|
|
"files": [
|
|
{"file": "a.py", "language": "python", "lines": 10, "functions": [], "classes": [], "complexity": {}},
|
|
{"file": "b.js", "language": "javascript", "lines": 20, "functions": [], "classes": [], "complexity": {}}
|
|
],
|
|
"dependency_graph": {
|
|
"total_dependencies": 0,
|
|
"orphaned_files": 0,
|
|
"cycles_detected": 0,
|
|
"cycle_details": [],
|
|
"orphaned_details": [],
|
|
"edges": [],
|
|
"statistics": {}
|
|
}
|
|
}
|
|
output = self.formatter.format(result)
|
|
assert "python: 1" in output or "python: 2" in output
|
|
assert "javascript:" in output
|
|
|
|
def test_shows_circular_dependencies(self) -> None:
|
|
result = {
|
|
"files": [
|
|
{"file": "a.py", "language": "python", "lines": 10, "functions": [], "classes": [], "complexity": {}},
|
|
{"file": "b.py", "language": "python", "lines": 10, "functions": [], "classes": [], "complexity": {}}
|
|
],
|
|
"dependency_graph": {
|
|
"total_dependencies": 2,
|
|
"orphaned_files": 0,
|
|
"cycles_detected": 1,
|
|
"cycle_details": [["a.py", "b.py", "a.py"]],
|
|
"orphaned_details": [],
|
|
"edges": [{"from": "a.py", "to": "b.py"}, {"from": "b.py", "to": "a.py"}],
|
|
"statistics": {}
|
|
}
|
|
}
|
|
output = self.formatter.format(result)
|
|
assert "Circular Dependencies Detected" in output
|
|
|
|
def test_shows_high_complexity_files(self) -> None:
|
|
result = {
|
|
"files": [
|
|
{
|
|
"file": "complex.py",
|
|
"language": "python",
|
|
"lines": 100,
|
|
"functions": [],
|
|
"classes": [],
|
|
"complexity": {"score": 55, "rating": "high"}
|
|
}
|
|
],
|
|
"dependency_graph": {
|
|
"total_dependencies": 0,
|
|
"orphaned_files": 0,
|
|
"cycles_detected": 0,
|
|
"cycle_details": [],
|
|
"orphaned_details": [],
|
|
"edges": [],
|
|
"statistics": {}
|
|
}
|
|
}
|
|
output = self.formatter.format(result)
|
|
assert "High Complexity Files" in output
|
|
assert "complex.py" in output
|