"""Tests for CLI commands.""" 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)