Add utils and tests
This commit is contained in:
90
tests/test_integration.py
Normal file
90
tests/test_integration.py
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
import pytest
|
||||||
|
from click.testing import CliRunner
|
||||||
|
from pathlib import Path
|
||||||
|
from codechunk.cli import main
|
||||||
|
|
||||||
|
|
||||||
|
class TestCLICommands:
|
||||||
|
"""Tests for CLI commands."""
|
||||||
|
|
||||||
|
def test_cli_version(self):
|
||||||
|
"""Test version command."""
|
||||||
|
runner = CliRunner()
|
||||||
|
result = runner.invoke(main, ["version"])
|
||||||
|
|
||||||
|
assert result.exit_code == 0
|
||||||
|
assert "CodeChunk" in result.output or "0.1" in result.output
|
||||||
|
|
||||||
|
def test_cli_help(self):
|
||||||
|
"""Test help command."""
|
||||||
|
runner = CliRunner()
|
||||||
|
result = runner.invoke(main, ["--help"])
|
||||||
|
|
||||||
|
assert result.exit_code == 0
|
||||||
|
assert "generate" in result.output
|
||||||
|
assert "analyze" in result.output
|
||||||
|
|
||||||
|
def test_generate_command_help(self):
|
||||||
|
"""Test generate command help."""
|
||||||
|
runner = CliRunner()
|
||||||
|
result = runner.invoke(main, ["generate", "--help"])
|
||||||
|
|
||||||
|
assert result.exit_code == 0
|
||||||
|
assert "--output" in result.output
|
||||||
|
assert "--format" in result.output
|
||||||
|
|
||||||
|
def test_analyze_command_help(self):
|
||||||
|
"""Test analyze command help."""
|
||||||
|
runner = CliRunner()
|
||||||
|
result = runner.invoke(main, ["analyze", "--help"])
|
||||||
|
|
||||||
|
assert result.exit_code == 0
|
||||||
|
assert "--json" in result.output
|
||||||
|
|
||||||
|
def test_generate_nonexistent_path(self):
|
||||||
|
"""Test generate with non-existent path."""
|
||||||
|
runner = CliRunner()
|
||||||
|
result = runner.invoke(main, ["generate", "/nonexistent/path"])
|
||||||
|
|
||||||
|
assert result.exit_code != 0
|
||||||
|
|
||||||
|
|
||||||
|
class TestIntegration:
|
||||||
|
"""Integration tests for full pipeline."""
|
||||||
|
|
||||||
|
def test_full_pipeline_python(self, tmp_path, sample_python_code):
|
||||||
|
"""Test full analysis pipeline with Python code."""
|
||||||
|
(tmp_path / "main.py").write_text(sample_python_code)
|
||||||
|
|
||||||
|
runner = CliRunner()
|
||||||
|
result = runner.invoke(main, ["analyze", str(tmp_path)])
|
||||||
|
|
||||||
|
assert result.exit_code == 0
|
||||||
|
|
||||||
|
def test_full_pipeline_multiple_files(self, tmp_path):
|
||||||
|
"""Test full pipeline with multiple files."""
|
||||||
|
(tmp_path / "main.py").write_text('''
|
||||||
|
"""Main module."""
|
||||||
|
def main():
|
||||||
|
pass
|
||||||
|
''')
|
||||||
|
(tmp_path / "utils.py").write_text('''
|
||||||
|
"""Utils module."""
|
||||||
|
def helper():
|
||||||
|
pass
|
||||||
|
''')
|
||||||
|
|
||||||
|
runner = CliRunner()
|
||||||
|
result = runner.invoke(main, ["analyze", str(tmp_path)])
|
||||||
|
|
||||||
|
assert result.exit_code == 0
|
||||||
|
|
||||||
|
def test_generate_preserves_code_structure(self, tmp_path, sample_python_code):
|
||||||
|
"""Test that generated output preserves code structure."""
|
||||||
|
(tmp_path / "test.py").write_text(sample_python_code)
|
||||||
|
|
||||||
|
runner = CliRunner()
|
||||||
|
result = runner.invoke(main, ["generate", str(tmp_path), "--format", "markdown"])
|
||||||
|
|
||||||
|
assert result.exit_code == 0
|
||||||
|
assert "DataProcessor" in result.output
|
||||||
Reference in New Issue
Block a user