fix: update test imports to use gitignore_generator module instead of src
Some checks failed
CI / test (3.11) (push) Has been cancelled
CI / test (3.12) (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / build (push) Has been cancelled
CI / test (3.10) (push) Has been cancelled

This commit is contained in:
2026-02-02 16:23:34 +00:00
parent 1f275038a5
commit 21f72e2bd0

View File

@@ -1,5 +1,6 @@
from click.testing import CliRunner
from src.cli import main
from gitignore_generator.cli import main
class TestCLI:
@@ -14,160 +15,142 @@ class TestCLI:
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
assert "interactive" 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):
def test_generate_python(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):
def test_generate_multiple_templates(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"])
result = runner.invoke(main, ["generate", "python", "vscode"])
assert result.exit_code == 0
content = (tmp_path / ".gitignore").read_text()
assert "# existing content" not in content
assert "__pycache__" in content
assert ".vscode" 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):
def test_generate_to_stdout(self, tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
runner = CliRunner()
result = runner.invoke(main, ["detect"])
result = runner.invoke(main, ["generate", "python", "--output", "-"])
assert result.exit_code == 0
assert "No known project type detected" in result.output
assert "__pycache__" 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):
def test_generate_no_templates(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
assert "No templates specified" in result.output
def test_generate_language_option(self, tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
def test_list_templates(self):
runner = CliRunner()
result = runner.invoke(main, ["generate", "--language", "python"])
result = runner.invoke(main, ["list"])
assert result.exit_code == 0
assert "__pycache__" in (tmp_path / ".gitignore").read_text()
assert "Languages" in result.output
assert "python" in result.output
def test_generate_framework_option(self, tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
def test_list_by_category(self):
runner = CliRunner()
result = runner.invoke(main, ["generate", "--framework", "django"])
result = runner.invoke(main, ["list", "--category", "languages"])
assert result.exit_code == 0
assert "python" in result.output
assert "IDEs" not in result.output
def test_generate_ide_option(self, tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
def test_search_templates(self):
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)])
result = runner.invoke(main, ["search", "python"])
assert result.exit_code == 0
assert "python" in result.output
def test_detect_invalid_path(self):
def test_search_no_results(self):
runner = CliRunner()
result = runner.invoke(main, ["detect", "/nonexistent/path"])
result = runner.invoke(main, ["search", "nonexistent12345"])
assert result.exit_code == 0
assert "No templates found" in result.output
def test_validate_valid_file(self, tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
gitignore = tmp_path / ".gitignore"
gitignore.write_text("__pycache__\n*.pyc")
runner = CliRunner()
result = runner.invoke(main, ["validate", str(gitignore)])
assert result.exit_code == 0
assert "Valid" in result.output
def test_validate_invalid_pattern(self, tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
gitignore = tmp_path / ".gitignore"
gitignore.write_text("__pycache__\\n")
runner = CliRunner()
result = runner.invoke(main, ["validate", str(gitignore)])
assert result.exit_code == 0
assert "Invalid" in result.output
def test_interactive(self, tmp_path, monkeypatch, capsys):
monkeypatch.chdir(tmp_path)
runner = CliRunner()
result = runner.invoke(main, ["interactive"], input="1\n1\n\n\nn\n.gitignore\n")
assert result.exit_code == 0
def test_template_add(self, tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
template_file = tmp_path / "my_template.gitignore"
template_file.write_text("# custom template")
runner = CliRunner()
result = runner.invoke(main, ["template-add", "custom", str(template_file)])
assert result.exit_code == 0
def test_template_export(self, tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
runner = CliRunner()
result = runner.invoke(main, ["template-export", "python", "exported.gitignore"])
assert result.exit_code == 0
assert (tmp_path / "exported.gitignore").exists()
def test_info_command(self):
runner = CliRunner()
result = runner.invoke(main, ["info", "python"])
assert result.exit_code == 0
assert "python" in result.output
def test_info_nonexistent(self):
runner = CliRunner()
result = runner.invoke(main, ["info", "nonexistent12345"])
assert result.exit_code != 0
def test_generate_overwrite(self, tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
gitignore = tmp_path / ".gitignore"
gitignore.write_text("# existing content")
runner = CliRunner()
result = runner.invoke(main, ["generate", "python", "--overwrite"])
assert result.exit_code == 0
content = gitignore.read_text()
assert "# existing content" not in content
assert "__pycache__" in content
import pytest
from pathlib import Path
def test_generate_append(self, tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
gitignore = tmp_path / ".gitignore"
gitignore.write_text("# existing content")
runner = CliRunner()
result = runner.invoke(main, ["generate", "python"])
assert result.exit_code == 0
content = gitignore.read_text()
assert "# existing content" in content
assert "__pycache__" in content