Initial commit: CodeMap v0.1.0 - CLI tool for code analysis and diagram generation
This commit is contained in:
70
tests/test_full_analysis.py
Normal file
70
tests/test_full_analysis.py
Normal file
@@ -0,0 +1,70 @@
|
||||
import tempfile
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typer.testing import CliRunner
|
||||
from codemap.cli.app import app
|
||||
|
||||
|
||||
def test_analyze_command():
|
||||
runner = CliRunner()
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
Path(tmpdir, "test.py").write_text("import os\nimport sys\n")
|
||||
Path(tmpdir, "test.js").write_text("const fs = require('fs');\n")
|
||||
|
||||
result = runner.invoke(app, ["analyze", tmpdir])
|
||||
|
||||
assert result.exit_code == 0 or "Error" not in result.output
|
||||
|
||||
|
||||
def test_analyze_nonexistent_path():
|
||||
runner = CliRunner()
|
||||
|
||||
result = runner.invoke(app, ["analyze", "/nonexistent/path"])
|
||||
|
||||
assert result.exit_code != 0
|
||||
assert "does not exist" in result.output
|
||||
|
||||
|
||||
def test_analyze_single_file():
|
||||
runner = CliRunner()
|
||||
|
||||
with tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False) as f:
|
||||
f.write("import os\n")
|
||||
temp_path = f.name
|
||||
|
||||
try:
|
||||
result = runner.invoke(app, ["analyze", temp_path])
|
||||
|
||||
assert result.exit_code == 0 or "Error" not in result.output
|
||||
finally:
|
||||
os.unlink(temp_path)
|
||||
|
||||
|
||||
def test_analyze_with_output():
|
||||
runner = CliRunner()
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
Path(tmpdir, "test.py").write_text("import os\n")
|
||||
|
||||
output_file = Path(tmpdir, "output.mmd")
|
||||
result = runner.invoke(app, ["analyze", tmpdir, "--output", str(output_file), "--format", "mermaid"])
|
||||
|
||||
if result.exit_code == 0 and output_file.exists():
|
||||
content = output_file.read_text()
|
||||
assert "graph TD" in content
|
||||
|
||||
|
||||
def test_analyze_with_html_format():
|
||||
runner = CliRunner()
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
Path(tmpdir, "test.py").write_text("import os\n")
|
||||
|
||||
output_file = Path(tmpdir, "output.html")
|
||||
result = runner.invoke(app, ["analyze", tmpdir, "--output", str(output_file), "--format", "html"])
|
||||
|
||||
if result.exit_code == 0 and output_file.exists():
|
||||
content = output_file.read_text()
|
||||
assert "<!DOCTYPE html>" in content
|
||||
assert "mermaid" in content.lower()
|
||||
Reference in New Issue
Block a user