diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 0000000..eaead5c --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,146 @@ +"""Tests for CLI interface.""" + +from pathlib import Path + +from click.testing import CliRunner + +from src.cli import main + + +class TestCLI: + """Tests for CLI functionality.""" + + def test_cli_help(self): + """Test CLI help command.""" + runner = CliRunner() + result = runner.invoke(main, ["--help"]) + assert result.exit_code == 0 + assert "--path" in result.output + assert "--language" in result.output + assert "--framework" in result.output + + def test_cli_dry_run(self): + """Test CLI dry-run option.""" + runner = CliRunner() + result = runner.invoke(main, ["--dry-run", "--language", "python"]) + assert result.exit_code == 0 + assert "__pycache__/" in result.output + + def test_cli_force_overwrite(self, temp_project_dir: Path): + """Test CLI force overwrite option.""" + gitignore = temp_project_dir / ".gitignore" + gitignore.write_text("old content\n") + + runner = CliRunner() + runner.invoke(main, ["--path", str(temp_project_dir), "--force", "--dry-run"]) + + def test_cli_output_file(self, temp_project_dir: Path): + """Test CLI custom output file option.""" + output_file = temp_project_dir / "custom.gitignore" + + runner = CliRunner() + runner.invoke(main, ["--output", str(output_file), "--language", "python", "--force"]) + + assert output_file.exists() + + def test_cli_verbose_output(self): + """Test CLI verbose output option.""" + runner = CliRunner() + result = runner.invoke(main, ["--dry-run", "--language", "python", "--verbose"]) + assert result.exit_code == 0 + assert "python" in result.output.lower() or "Detected" in result.output + + def test_cli_multiple_languages(self): + """Test CLI with multiple languages.""" + runner = CliRunner() + result = runner.invoke(main, ["--dry-run", "--language", "python", "--language", "nodejs"]) + assert result.exit_code == 0 + + def test_cli_multiple_frameworks(self): + """Test CLI with multiple frameworks.""" + runner = CliRunner() + result = runner.invoke(main, ["--dry-run", "--framework", "django", "--framework", "react"]) + assert result.exit_code == 0 + + def test_cli_custom_patterns(self): + """Test CLI with custom patterns.""" + runner = CliRunner() + result = runner.invoke(main, ["--dry-run", "--custom", "custom_dir/", "--custom", "*.custom"]) + assert result.exit_code == 0 + assert "custom_dir/" in result.output + + def test_cli_os_patterns(self): + """Test CLI with OS patterns.""" + runner = CliRunner() + result = runner.invoke(main, ["--dry-run", "--os", "macos", "--os", "windows"]) + assert result.exit_code == 0 + assert ".DS_Store" in result.output + assert "Thumbs.db" in result.output + + def test_cli_ide_patterns(self): + """Test CLI with IDE patterns.""" + runner = CliRunner() + result = runner.invoke(main, ["--dry-run", "--ide", "vscode", "--ide", "jetbrains"]) + assert result.exit_code == 0 + assert ".vscode/" in result.output + assert ".idea/" in result.output + + def test_cli_nonexistent_path(self): + """Test CLI with nonexistent path.""" + runner = CliRunner() + result = runner.invoke(main, ["--path", "/nonexistent/path"]) + assert result.exit_code != 0 + + def test_cli_invalid_language(self): + """Test CLI with invalid language.""" + runner = CliRunner() + result = runner.invoke(main, ["--dry-run", "--language", "invalid_language"]) + assert result.exit_code != 0 + + def test_cli_invalid_framework(self): + """Test CLI with invalid framework.""" + runner = CliRunner() + result = runner.invoke(main, ["--dry-run", "--framework", "invalid_framework"]) + assert result.exit_code != 0 + + def test_detect_project_stack_python(self, python_project: Path): + """Test project stack detection for Python project.""" + from src.cli import detect_project_stack + + stack = detect_project_stack(python_project) + assert "python" in stack.get("languages", []) + + def test_detect_project_stack_nodejs(self, nodejs_project: Path): + """Test project stack detection for Node.js project.""" + from src.cli import detect_project_stack + + stack = detect_project_stack(nodejs_project) + assert "nodejs" in stack.get("languages", []) + + def test_detect_project_stack_django(self, django_project: Path): + """Test project stack detection for Django project.""" + from src.cli import detect_project_stack + + stack = detect_project_stack(django_project) + assert "django" in stack.get("frameworks", []) + + def test_detect_project_stack_react(self, react_project: Path): + """Test project stack detection for React project.""" + from src.cli import detect_project_stack + + stack = detect_project_stack(react_project) + assert "react" in stack.get("frameworks", []) + + def test_detect_project_stack_vscode(self, vscode_project: Path): + """Test IDE detection for VSCode project.""" + from src.cli import detect_project_stack + + stack = detect_project_stack(vscode_project) + assert "vscode" in stack.get("ides", []) + + def test_detect_project_stack_jetbrains(self, jetbrains_project: Path): + """Test IDE detection for JetBrains project.""" + from src.cli import detect_project_stack + + stack = detect_project_stack(jetbrains_project) + assert "jetbrains" in stack.get("ides", [])