Initial upload: gitignore-generator-cli v1.0.0 with CI/CD workflow

This commit is contained in:
2026-01-30 15:34:16 +00:00
parent 9250d73d2f
commit cb8074ed0b

136
tests/test_detector.py Normal file
View File

@@ -0,0 +1,136 @@
"""Tests for detector.py."""
import tempfile
from pathlib import Path
import pytest
from gitignore_generator.detector import (
ProjectDetector,
detect_project,
suggest_gitignore,
DETECTION_RULES
)
class TestProjectDetector:
"""Tests for ProjectDetector class."""
@pytest.fixture
def detector(self):
"""Create detector with temp directory."""
with tempfile.TemporaryDirectory() as tmpdir:
yield ProjectDetector(Path(tmpdir))
def test_detect_node_project(self, detector):
"""Test detecting Node.js project."""
(detector.path / 'package.json').touch()
(detector.path / 'node_modules').mkdir()
result = detector.detect()
assert 'node' in result
def test_detect_python_project(self, detector):
"""Test detecting Python project."""
(detector.path / 'requirements.txt').touch()
(detector.path / 'venv').mkdir()
result = detector.detect()
assert 'python' in result
def test_detect_django_project(self, detector):
"""Test detecting Django project."""
(detector.path / 'manage.py').touch()
(detector.path / 'settings.py').touch()
result = detector.detect()
assert 'django' in result
def test_detect_multiple_technologies(self, detector):
"""Test detecting multiple technologies."""
(detector.path / 'package.json').touch()
(detector.path / 'requirements.txt').touch()
(detector.path / 'Dockerfile').touch()
result = detector.detect()
assert 'node' in result
assert 'python' in result
assert 'docker' in result
def test_detect_no_project(self, detector):
"""Test when no project is detected."""
result = detector.detect()
assert len(result) == 0
def test_detect_with_min_confidence(self, detector):
"""Test minimum confidence threshold."""
(detector.path / 'package.json').touch()
result = detector.detect(min_confidence=2)
assert 'node' not in result
def test_get_detection_details(self, detector):
"""Test getting detailed detection results."""
(detector.path / 'package.json').touch()
(detector.path / 'yarn.lock').touch()
details = detector.get_detection_details()
assert len(details) > 0
assert details[0]['technology'] == 'node'
assert details[0]['confidence'] >= 1
def test_suggest_gitignore(self, detector):
"""Test gitignore suggestions."""
(detector.path / 'package.json').touch()
(detector.path / 'requirements.txt').touch()
(detector.path / 'manage.py').touch()
suggestions = detector.suggest_gitignore()
assert 'node' in suggestions
assert 'python' in suggestions
assert 'django' in suggestions
def test_scan_directory(self, detector):
"""Test directory scanning."""
(detector.path / 'package.json').touch()
(detector.path / 'requirements.txt').touch()
result = detector.scan_directory()
assert 'node' in result
assert 'python' in result
class TestDetectionRules:
"""Tests for detection rules configuration."""
def test_detection_rules_exist(self):
"""Test that detection rules are defined."""
assert len(DETECTION_RULES) > 0
def test_common_technologies_have_rules(self):
"""Test that common technologies have detection rules."""
common = ['node', 'python', 'django', 'rails', 'java', 'go', 'rust', 'dotnet']
for tech in common:
assert tech in DETECTION_RULES
assert len(DETECTION_RULES[tech]) > 0
def test_each_rule_has_markers(self):
"""Test that each detection rule has markers."""
for tech, markers in DETECTION_RULES.items():
assert len(markers) > 0, f"{tech} has no markers"
class TestConvenienceFunctions:
"""Tests for convenience functions."""
def test_detect_project_function(self, detector):
"""Test detect_project convenience function."""
(detector.path / 'requirements.txt').touch()
result = detect_project(detector.path)
assert 'python' in result
def test_suggest_gitignore_function(self, detector):
"""Test suggest_gitignore convenience function."""
(detector.path / 'requirements.txt').touch()
result = suggest_gitignore(detector.path)
assert 'python' in result