diff --git a/tests/test_full_analysis.py b/tests/test_full_analysis.py new file mode 100644 index 0000000..69e0942 --- /dev/null +++ b/tests/test_full_analysis.py @@ -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 "" in content + assert "mermaid" in content.lower()