174 lines
6.4 KiB
Python
174 lines
6.4 KiB
Python
from click.testing import CliRunner
|
|
from src.cli import main
|
|
|
|
|
|
class TestCLI:
|
|
def test_main_version(self):
|
|
runner = CliRunner()
|
|
result = runner.invoke(main, ["--version"])
|
|
assert result.exit_code == 0
|
|
assert "gitignore-generator" in result.output
|
|
|
|
def test_main_help(self):
|
|
runner = CliRunner()
|
|
result = runner.invoke(main, ["--help"])
|
|
assert result.exit_code == 0
|
|
assert "generate" in result.output
|
|
assert "detect" in result.output
|
|
assert "list" in result.output
|
|
assert "wizard" in result.output
|
|
|
|
def test_generate_help(self):
|
|
runner = CliRunner()
|
|
result = runner.invoke(main, ["generate", "--help"])
|
|
assert result.exit_code == 0
|
|
assert "--output" in result.output
|
|
assert "--language" in result.output
|
|
assert "--framework" in result.output
|
|
assert "--ide" in result.output
|
|
|
|
def test_generate_python_stdout(self, tmp_path, monkeypatch):
|
|
monkeypatch.chdir(tmp_path)
|
|
runner = CliRunner()
|
|
result = runner.invoke(main, ["generate", "python", "--stdout"])
|
|
assert result.exit_code == 0
|
|
assert "__pycache__" in result.output
|
|
|
|
def test_generate_multiple_types(self, tmp_path, monkeypatch):
|
|
monkeypatch.chdir(tmp_path)
|
|
runner = CliRunner()
|
|
result = runner.invoke(
|
|
main, ["generate", "python", "vscode", "--stdout"]
|
|
)
|
|
assert result.exit_code == 0
|
|
assert "__pycache__" in result.output
|
|
assert ".vscode" in result.output
|
|
|
|
def test_generate_to_file(self, tmp_path, monkeypatch):
|
|
monkeypatch.chdir(tmp_path)
|
|
runner = CliRunner()
|
|
result = runner.invoke(main, ["generate", "python"])
|
|
assert result.exit_code == 0
|
|
assert (tmp_path / ".gitignore").exists()
|
|
|
|
def test_generate_append_to_existing(self, tmp_path, monkeypatch):
|
|
monkeypatch.chdir(tmp_path)
|
|
(tmp_path / ".gitignore").write_text("# existing content\n")
|
|
runner = CliRunner()
|
|
result = runner.invoke(main, ["generate", "python"])
|
|
assert result.exit_code == 0
|
|
content = (tmp_path / ".gitignore").read_text()
|
|
assert "# existing content" in content
|
|
assert "__pycache__" in content
|
|
|
|
def test_generate_overwrite(self, tmp_path, monkeypatch):
|
|
monkeypatch.chdir(tmp_path)
|
|
(tmp_path / ".gitignore").write_text("# existing content\n")
|
|
runner = CliRunner()
|
|
result = runner.invoke(main, ["generate", "python", "--overwrite"])
|
|
assert result.exit_code == 0
|
|
content = (tmp_path / ".gitignore").read_text()
|
|
assert "# existing content" not in content
|
|
assert "__pycache__" in content
|
|
|
|
def test_detect_help(self):
|
|
runner = CliRunner()
|
|
result = runner.invoke(main, ["detect", "--help"])
|
|
assert result.exit_code == 0
|
|
|
|
def test_detect_no_project(self, tmp_path, monkeypatch):
|
|
monkeypatch.chdir(tmp_path)
|
|
runner = CliRunner()
|
|
result = runner.invoke(main, ["detect"])
|
|
assert result.exit_code == 0
|
|
assert "No known project type detected" in result.output
|
|
|
|
def test_detect_python_project(self, tmp_path, monkeypatch):
|
|
monkeypatch.chdir(tmp_path)
|
|
(tmp_path / "requirements.txt").touch()
|
|
runner = CliRunner()
|
|
result = runner.invoke(main, ["detect"])
|
|
assert result.exit_code == 0
|
|
assert "python" in result.output
|
|
|
|
def test_list_help(self):
|
|
runner = CliRunner()
|
|
result = runner.invoke(main, ["list", "--help"])
|
|
assert result.exit_code == 0
|
|
|
|
def test_list_all(self):
|
|
runner = CliRunner()
|
|
result = runner.invoke(main, ["list"])
|
|
assert result.exit_code == 0
|
|
assert "Language" in result.output
|
|
assert "Framework" in result.output
|
|
assert "IDE" in result.output
|
|
|
|
def test_list_by_category(self):
|
|
runner = CliRunner()
|
|
result = runner.invoke(main, ["list", "--category", "language"])
|
|
assert result.exit_code == 0
|
|
assert "python" in result.output
|
|
assert "javascript" in result.output
|
|
|
|
def test_generate_no_types_no_detection(self, tmp_path, monkeypatch):
|
|
monkeypatch.chdir(tmp_path)
|
|
runner = CliRunner()
|
|
result = runner.invoke(main, ["generate"])
|
|
assert result.exit_code == 1
|
|
assert "No project type detected" in result.output
|
|
|
|
def test_generate_language_option(self, tmp_path, monkeypatch):
|
|
monkeypatch.chdir(tmp_path)
|
|
runner = CliRunner()
|
|
result = runner.invoke(main, ["generate", "--language", "python"])
|
|
assert result.exit_code == 0
|
|
assert "__pycache__" in (tmp_path / ".gitignore").read_text()
|
|
|
|
def test_generate_framework_option(self, tmp_path, monkeypatch):
|
|
monkeypatch.chdir(tmp_path)
|
|
runner = CliRunner()
|
|
result = runner.invoke(main, ["generate", "--framework", "django"])
|
|
assert result.exit_code == 0
|
|
|
|
def test_generate_ide_option(self, tmp_path, monkeypatch):
|
|
monkeypatch.chdir(tmp_path)
|
|
runner = CliRunner()
|
|
result = runner.invoke(main, ["generate", "--ide", "vscode"])
|
|
assert result.exit_code == 0
|
|
assert ".vscode" in (tmp_path / ".gitignore").read_text()
|
|
|
|
def test_generate_os_option(self, tmp_path, monkeypatch):
|
|
monkeypatch.chdir(tmp_path)
|
|
runner = CliRunner()
|
|
result = runner.invoke(main, ["generate", "--os", "macos"])
|
|
assert result.exit_code == 0
|
|
|
|
def test_generate_tools_option(self, tmp_path, monkeypatch):
|
|
monkeypatch.chdir(tmp_path)
|
|
runner = CliRunner()
|
|
result = runner.invoke(main, ["generate", "--tools", "docker"])
|
|
assert result.exit_code == 0
|
|
|
|
def test_generate_invalid_type(self, tmp_path, monkeypatch):
|
|
monkeypatch.chdir(tmp_path)
|
|
runner = CliRunner()
|
|
result = runner.invoke(main, ["generate", "invalid_type"])
|
|
assert result.exit_code == 2
|
|
|
|
def test_detect_specific_path(self, tmp_path, monkeypatch):
|
|
(tmp_path / "requirements.txt").touch()
|
|
runner = CliRunner()
|
|
result = runner.invoke(main, ["detect", str(tmp_path)])
|
|
assert result.exit_code == 0
|
|
assert "python" in result.output
|
|
|
|
def test_detect_invalid_path(self):
|
|
runner = CliRunner()
|
|
result = runner.invoke(main, ["detect", "/nonexistent/path"])
|
|
assert result.exit_code != 0
|
|
|
|
|
|
import pytest
|
|
from pathlib import Path
|