From 9d7f0c3162a32843bd875d8af60a45a109ed7548 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Thu, 5 Feb 2026 08:48:52 +0000 Subject: [PATCH] Add test suite with fixtures and tests for all modules --- tests/test_cli.py | 136 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 tests/test_cli.py diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 0000000..4b28992 --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,136 @@ +"""Tests for CLI commands.""" + +from pathlib import Path + +import pytest +from click.testing import CliRunner + +from src.auto_readme.cli import generate, preview, analyze, init_config + + +class TestGenerateCommand: + """Tests for the generate command.""" + + def test_generate_basic_python(self, create_python_project, tmp_path): + """Test basic README generation for Python project.""" + from src.auto_readme.cli import generate + + runner = CliRunner() + result = runner.invoke(generate, ["--input", str(create_python_project), "--output", str(tmp_path / "README.md")]) + + assert result.exit_code == 0 + + readme_content = (tmp_path / "README.md").read_text() + assert "# test-project" in readme_content + + def test_generate_dry_run(self, create_python_project): + """Test README generation with dry-run option.""" + runner = CliRunner() + + result = runner.invoke(generate, ["--input", str(create_python_project), "--dry-run"]) + + assert result.exit_code == 0 + assert "# test-project" in result.output + + def test_generate_force_overwrite(self, create_python_project, tmp_path): + """Test forced README overwrite.""" + readme_file = tmp_path / "README.md" + readme_file.write_text("# Existing README") + + runner = CliRunner() + result = runner.invoke(generate, ["--input", str(create_python_project), "--output", str(readme_file), "--force"]) + + assert result.exit_code == 0 + assert readme_file.read_text() != "# Existing README" + + def test_generate_with_template(self, create_python_project): + """Test README generation with specific template.""" + runner = CliRunner() + + result = runner.invoke(generate, ["--input", str(create_python_project), "--template", "base", "--dry-run"]) + + assert result.exit_code == 0 + + +class TestPreviewCommand: + """Tests for the preview command.""" + + def test_preview_python_project(self, create_python_project): + """Test previewing README for Python project.""" + runner = CliRunner() + + result = runner.invoke(preview, ["--input", str(create_python_project)]) + + assert result.exit_code == 0 + assert "# test-project" in result.output + + +class TestAnalyzeCommand: + """Tests for the analyze command.""" + + def test_analyze_python_project(self, create_python_project): + """Test analyzing Python project.""" + runner = CliRunner() + + result = runner.invoke(analyze, [str(create_python_project)]) + + assert result.exit_code == 0 + assert "test-project" in result.output + assert "Type: python" in result.output + + def test_analyze_js_project(self, create_javascript_project): + """Test analyzing JavaScript project.""" + runner = CliRunner() + + result = runner.invoke(analyze, [str(create_javascript_project)]) + + assert result.exit_code == 0 + assert "Type: javascript" in result.output + + def test_analyze_go_project(self, create_go_project): + """Test analyzing Go project.""" + runner = CliRunner() + + result = runner.invoke(analyze, [str(create_go_project)]) + + assert result.exit_code == 0 + assert "Type: go" in result.output + + def test_analyze_rust_project(self, create_rust_project): + """Test analyzing Rust project.""" + runner = CliRunner() + + result = runner.invoke(analyze, [str(create_rust_project)]) + + assert result.exit_code == 0 + assert "Type: rust" in result.output + + +class TestInitConfigCommand: + """Tests for the init-config command.""" + + def test_init_config(self, tmp_path): + """Test generating configuration template.""" + runner = CliRunner() + + result = runner.invoke(init_config, ["--output", str(tmp_path / ".readmerc")]) + + assert result.exit_code == 0 + + config_content = (tmp_path / ".readmerc").read_text() + assert "project_name:" in config_content + assert "description:" in config_content + + def test_init_config_default_path(self, tmp_path): + """Test generating configuration at default path.""" + import os + original_dir = os.getcwd() + try: + os.chdir(tmp_path) + runner = CliRunner() + result = runner.invoke(init_config, ["--output", ".readmerc"]) + + assert result.exit_code == 0 + assert (tmp_path / ".readmerc").exists() + finally: + os.chdir(original_dir)