Add test files and configuration

This commit is contained in:
2026-02-01 20:17:00 +00:00
parent dc2d3a3515
commit 5109e7b8d8

96
tests/conftest.py Normal file
View File

@@ -0,0 +1,96 @@
"""Pytest configuration and fixtures for auto-gitignore tests."""
import tempfile
from pathlib import Path
from typing import Generator
import pytest
@pytest.fixture
def temp_project_dir() -> Generator[Path, None, None]:
"""Create a temporary directory for testing."""
with tempfile.TemporaryDirectory() as tmp_dir:
yield Path(tmp_dir)
@pytest.fixture
def python_project(temp_project_dir: Path) -> Path:
"""Create a mock Python project structure."""
(temp_project_dir / "requirements.txt").write_text("requests==2.28.0\n")
(temp_project_dir / "setup.py").write_text("from setuptools import setup\n")
src_dir = temp_project_dir / "src"
src_dir.mkdir(exist_ok=True)
(src_dir / "main.py").write_text("print('hello')\n")
return temp_project_dir
@pytest.fixture
def nodejs_project(temp_project_dir: Path) -> Path:
"""Create a mock Node.js project structure."""
(temp_project_dir / "package.json").write_text('{"name": "test", "version": "1.0.0"}\n')
src_dir = temp_project_dir / "src"
src_dir.mkdir(exist_ok=True)
(src_dir / "index.js").write_text("console.log('hello')\n")
return temp_project_dir
@pytest.fixture
def django_project(temp_project_dir: Path) -> Path:
"""Create a mock Django project structure."""
(temp_project_dir / "requirements.txt").write_text("django==4.0.0\n")
(temp_project_dir / "manage.py").write_text("#!/usr/bin/env python\n")
myproject_dir = temp_project_dir / "myproject"
myproject_dir.mkdir(exist_ok=True)
(myproject_dir / "__init__.py").write_text("")
(myproject_dir / "settings.py").write_text("")
(myproject_dir / "urls.py").write_text("")
return temp_project_dir
@pytest.fixture
def react_project(temp_project_dir: Path) -> Path:
"""Create a mock React project structure."""
(temp_project_dir / "package.json").write_text('{"name": "test", "dependencies": {"react": "^18.0.0"}}\n')
src_dir = temp_project_dir / "src"
src_dir.mkdir(exist_ok=True)
(src_dir / "App.js").write_text("import React from 'react'\n")
return temp_project_dir
@pytest.fixture
def mixed_project(temp_project_dir: Path) -> Path:
"""Create a mock mixed-language project structure."""
(temp_project_dir / "requirements.txt").write_text("django==4.0.0\n")
(temp_project_dir / "package.json").write_text('{"name": "test", "dependencies": {"react": "^18.0.0"}}\n')
backend_dir = temp_project_dir / "src" / "backend"
backend_dir.mkdir(parents=True, exist_ok=True)
(backend_dir / "main.py").write_text("print('hello')\n")
frontend_dir = temp_project_dir / "src" / "frontend"
frontend_dir.mkdir(parents=True, exist_ok=True)
(frontend_dir / "App.js").write_text("import React from 'react'\n")
return temp_project_dir
@pytest.fixture
def vscode_project(temp_project_dir: Path) -> Path:
"""Create a mock project with VSCode configuration."""
vscode_dir = temp_project_dir / ".vscode"
vscode_dir.mkdir(exist_ok=True)
(vscode_dir / "settings.json").write_text("{}\n")
src_dir = temp_project_dir / "src"
src_dir.mkdir(exist_ok=True)
(src_dir / "main.py").write_text("print('hello')\n")
return temp_project_dir
@pytest.fixture
def jetbrains_project(temp_project_dir: Path) -> Path:
"""Create a mock project with JetBrains IDE configuration."""
idea_dir = temp_project_dir / ".idea"
idea_dir.mkdir(exist_ok=True)
(idea_dir / "modules.xml").write_text("<project>\n</project>\n")
src_dir = temp_project_dir / "src"
src_dir.mkdir(exist_ok=True)
(src_dir / "main.py").write_text("print('hello')\n")
return temp_project_dir