From 187bd7d0e7fffa432bf5be544ec94b880db91e06 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Sun, 1 Feb 2026 23:46:55 +0000 Subject: [PATCH] Add utils and tests --- tests/test_integration.py | 90 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 tests/test_integration.py diff --git a/tests/test_integration.py b/tests/test_integration.py new file mode 100644 index 0000000..a42ada7 --- /dev/null +++ b/tests/test_integration.py @@ -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