Add test files for CLI, config, detector, and generator modules
Some checks failed
CI / test (push) Has been cancelled
Some checks failed
CI / test (push) Has been cancelled
This commit is contained in:
225
tests/test_detector.py
Normal file
225
tests/test_detector.py
Normal file
@@ -0,0 +1,225 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
from typing import List, Optional
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from src.detector import ProjectDetector
|
||||||
|
|
||||||
|
|
||||||
|
class TestProjectDetector:
|
||||||
|
def test_detect_python_project(self, tmp_path):
|
||||||
|
(tmp_path / "requirements.txt").touch()
|
||||||
|
(tmp_path / "setup.py").touch()
|
||||||
|
detector = ProjectDetector(tmp_path)
|
||||||
|
detected = detector.detect()
|
||||||
|
assert "python" in detected
|
||||||
|
|
||||||
|
def test_detect_javascript_project(self, tmp_path):
|
||||||
|
(tmp_path / "package.json").touch()
|
||||||
|
(tmp_path / "node_modules").mkdir()
|
||||||
|
detector = ProjectDetector(tmp_path)
|
||||||
|
detected = detector.detect()
|
||||||
|
assert "javascript" in detected
|
||||||
|
|
||||||
|
def test_detect_typescript_project(self, tmp_path):
|
||||||
|
(tmp_path / "tsconfig.json").touch()
|
||||||
|
detector = ProjectDetector(tmp_path)
|
||||||
|
detected = detector.detect()
|
||||||
|
assert "typescript" in detected
|
||||||
|
|
||||||
|
def test_detect_java_project(self, tmp_path):
|
||||||
|
(tmp_path / "pom.xml").touch()
|
||||||
|
detector = ProjectDetector(tmp_path)
|
||||||
|
detected = detector.detect()
|
||||||
|
assert "java" in detected
|
||||||
|
|
||||||
|
def test_detect_go_project(self, tmp_path):
|
||||||
|
(tmp_path / "go.mod").touch()
|
||||||
|
detector = ProjectDetector(tmp_path)
|
||||||
|
detected = detector.detect()
|
||||||
|
assert "go" in detected
|
||||||
|
|
||||||
|
def test_detect_rust_project(self, tmp_path):
|
||||||
|
(tmp_path / "Cargo.toml").touch()
|
||||||
|
detector = ProjectDetector(tmp_path)
|
||||||
|
detected = detector.detect()
|
||||||
|
assert "rust" in detected
|
||||||
|
|
||||||
|
def test_detect_dotnet_project(self, tmp_path):
|
||||||
|
(tmp_path / "test.csproj").touch()
|
||||||
|
detector = ProjectDetector(tmp_path)
|
||||||
|
detected = detector.detect()
|
||||||
|
assert "dotnet" in detected
|
||||||
|
|
||||||
|
def test_detect_php_project(self, tmp_path):
|
||||||
|
(tmp_path / "composer.json").touch()
|
||||||
|
detector = ProjectDetector(tmp_path)
|
||||||
|
detected = detector.detect()
|
||||||
|
assert "php" in detected
|
||||||
|
|
||||||
|
def test_detect_ruby_project(self, tmp_path):
|
||||||
|
(tmp_path / "Gemfile").touch()
|
||||||
|
detector = ProjectDetector(tmp_path)
|
||||||
|
detected = detector.detect()
|
||||||
|
assert "ruby" in detected
|
||||||
|
|
||||||
|
def test_detect_django_project(self, tmp_path):
|
||||||
|
(tmp_path / "manage.py").touch()
|
||||||
|
(tmp_path / "requirements.txt").write_text("django>=4.0\n")
|
||||||
|
detector = ProjectDetector(tmp_path)
|
||||||
|
detected = detector.detect()
|
||||||
|
assert "django" in detected
|
||||||
|
assert "python" in detected
|
||||||
|
|
||||||
|
def test_detect_flask_project(self, tmp_path):
|
||||||
|
(tmp_path / "app.py").touch()
|
||||||
|
(tmp_path / "requirements.txt").write_text("flask>=2.0\n")
|
||||||
|
detector = ProjectDetector(tmp_path)
|
||||||
|
detected = detector.detect()
|
||||||
|
assert "flask" in detected
|
||||||
|
assert "python" in detected
|
||||||
|
|
||||||
|
def test_detect_react_project(self, tmp_path):
|
||||||
|
(tmp_path / "package.json").write_text('{"dependencies": {"react": "^18.0"}}')
|
||||||
|
detector = ProjectDetector(tmp_path)
|
||||||
|
detected = detector.detect()
|
||||||
|
assert "react" in detected
|
||||||
|
assert "javascript" in detected
|
||||||
|
|
||||||
|
def test_detect_vue_project(self, tmp_path):
|
||||||
|
(tmp_path / "package.json").write_text('{"dependencies": {"vue": "^3.0"}}')
|
||||||
|
detector = ProjectDetector(tmp_path)
|
||||||
|
detected = detector.detect()
|
||||||
|
assert "vue" in detected
|
||||||
|
assert "javascript" in detected
|
||||||
|
|
||||||
|
def test_detect_angular_project(self, tmp_path):
|
||||||
|
(tmp_path / "angular.json").touch()
|
||||||
|
detector = ProjectDetector(tmp_path)
|
||||||
|
detected = detector.detect()
|
||||||
|
assert "angular" in detected
|
||||||
|
|
||||||
|
def test_detect_rails_project(self, tmp_path):
|
||||||
|
(tmp_path / "Gemfile").touch()
|
||||||
|
(tmp_path / "config").mkdir()
|
||||||
|
detector = ProjectDetector(tmp_path)
|
||||||
|
detected = detector.detect()
|
||||||
|
assert "rails" in detected
|
||||||
|
assert "ruby" in detected
|
||||||
|
|
||||||
|
def test_detect_laravel_project(self, tmp_path):
|
||||||
|
(tmp_path / "artisan").touch()
|
||||||
|
(tmp_path / "composer.json").touch()
|
||||||
|
detector = ProjectDetector(tmp_path)
|
||||||
|
detected = detector.detect()
|
||||||
|
assert "laravel" in detected
|
||||||
|
assert "php" in detected
|
||||||
|
|
||||||
|
def test_detect_spring_project(self, tmp_path):
|
||||||
|
(tmp_path / "pom.xml").touch()
|
||||||
|
(tmp_path / "src" / "main").mkdir(parents=True)
|
||||||
|
detector = ProjectDetector(tmp_path)
|
||||||
|
detected = detector.detect()
|
||||||
|
assert "spring" in detected
|
||||||
|
assert "java" in detected
|
||||||
|
|
||||||
|
def test_detect_vscode(self, tmp_path):
|
||||||
|
(tmp_path / ".vscode").mkdir()
|
||||||
|
(tmp_path / ".vscode" / "settings.json").touch()
|
||||||
|
detector = ProjectDetector(tmp_path)
|
||||||
|
detected = detector.detect()
|
||||||
|
assert "vscode" in detected
|
||||||
|
|
||||||
|
def test_detect_jetbrains(self, tmp_path):
|
||||||
|
(tmp_path / ".idea").mkdir()
|
||||||
|
(tmp_path / "test.iml").touch()
|
||||||
|
detector = ProjectDetector(tmp_path)
|
||||||
|
detected = detector.detect()
|
||||||
|
assert "jetbrains" in detected
|
||||||
|
|
||||||
|
def test_detect_docker(self, tmp_path):
|
||||||
|
(tmp_path / "Dockerfile").touch()
|
||||||
|
(tmp_path / "docker-compose.yml").touch()
|
||||||
|
detector = ProjectDetector(tmp_path)
|
||||||
|
detected = detector.detect()
|
||||||
|
assert "docker" in detected
|
||||||
|
|
||||||
|
def test_detect_gradle(self, tmp_path):
|
||||||
|
(tmp_path / "build.gradle").touch()
|
||||||
|
(tmp_path / "gradle.properties").touch()
|
||||||
|
detector = ProjectDetector(tmp_path)
|
||||||
|
detected = detector.detect()
|
||||||
|
assert "gradle" in detected
|
||||||
|
|
||||||
|
def test_detect_maven(self, tmp_path):
|
||||||
|
(tmp_path / "pom.xml").touch()
|
||||||
|
detector = ProjectDetector(tmp_path)
|
||||||
|
detected = detector.detect()
|
||||||
|
assert "maven" in detected
|
||||||
|
|
||||||
|
def test_detect_jupyter(self, tmp_path):
|
||||||
|
(tmp_path / "test.ipynb").touch()
|
||||||
|
(tmp_path / ".ipynb_checkpoints").mkdir()
|
||||||
|
detector = ProjectDetector(tmp_path)
|
||||||
|
detected = detector.detect()
|
||||||
|
assert "jupyter" in detected
|
||||||
|
|
||||||
|
def test_detect_terraform(self, tmp_path):
|
||||||
|
(tmp_path / "main.tf").touch()
|
||||||
|
(tmp_path / "terraform.tfstate").touch()
|
||||||
|
detector = ProjectDetector(tmp_path)
|
||||||
|
detected = detector.detect()
|
||||||
|
assert "terraform" in detected
|
||||||
|
|
||||||
|
def test_detect_empty_directory(self, tmp_path):
|
||||||
|
detector = ProjectDetector(tmp_path)
|
||||||
|
detected = detector.detect()
|
||||||
|
assert len(detected) == 0
|
||||||
|
|
||||||
|
def test_detect_multiple_types(self, tmp_path):
|
||||||
|
(tmp_path / "requirements.txt").touch()
|
||||||
|
(tmp_path / "package.json").touch()
|
||||||
|
(tmp_path / ".vscode").mkdir()
|
||||||
|
detector = ProjectDetector(tmp_path)
|
||||||
|
detected = detector.detect()
|
||||||
|
assert "python" in detected
|
||||||
|
assert "javascript" in detected
|
||||||
|
assert "vscode" in detected
|
||||||
|
|
||||||
|
def test_get_language(self, tmp_path):
|
||||||
|
(tmp_path / "requirements.txt").touch()
|
||||||
|
detector = ProjectDetector(tmp_path)
|
||||||
|
detector.detect()
|
||||||
|
assert detector.get_language() == "python"
|
||||||
|
|
||||||
|
def test_get_framework(self, tmp_path):
|
||||||
|
(tmp_path / "manage.py").touch()
|
||||||
|
(tmp_path / "requirements.txt").write_text("django>=4.0\n")
|
||||||
|
detector = ProjectDetector(tmp_path)
|
||||||
|
detector.detect()
|
||||||
|
assert detector.get_framework() == "django"
|
||||||
|
|
||||||
|
def test_get_ide(self, tmp_path):
|
||||||
|
(tmp_path / ".vscode").mkdir()
|
||||||
|
detector = ProjectDetector(tmp_path)
|
||||||
|
detector.detect()
|
||||||
|
assert detector.get_ide() == "vscode"
|
||||||
|
|
||||||
|
def test_detect_macos_specific(self, tmp_path):
|
||||||
|
(tmp_path / ".DS_Store").touch()
|
||||||
|
detector = ProjectDetector(tmp_path)
|
||||||
|
detected = detector.detect()
|
||||||
|
assert "macos" in detected
|
||||||
|
|
||||||
|
def test_detect_linux_specific(self, tmp_path):
|
||||||
|
(tmp_path / "~").touch()
|
||||||
|
detector = ProjectDetector(tmp_path)
|
||||||
|
detected = detector.detect()
|
||||||
|
assert "linux" in detected
|
||||||
|
|
||||||
|
def test_detect_windows_specific(self, tmp_path):
|
||||||
|
(tmp_path / "Thumbs.db").touch()
|
||||||
|
(tmp_path / "desktop.ini").touch()
|
||||||
|
detector = ProjectDetector(tmp_path)
|
||||||
|
detected = detector.detect()
|
||||||
|
assert "windows" in detected
|
||||||
Reference in New Issue
Block a user