Add test configuration and fixtures
This commit is contained in:
127
tests/conftest.py
Normal file
127
tests/conftest.py
Normal file
@@ -0,0 +1,127 @@
|
||||
"""Pytest configuration and fixtures for DepAudit tests."""
|
||||
|
||||
import json
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_package_json():
|
||||
"""Sample package.json for JavaScript projects."""
|
||||
return {
|
||||
"name": "test-project",
|
||||
"version": "1.0.0",
|
||||
"description": "A test project",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"express": "^4.18.0",
|
||||
"lodash": "^4.17.21"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jest": "^29.0.0",
|
||||
"fsevents": "^2.3.0"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_requirements_txt():
|
||||
"""Sample requirements.txt for Python projects."""
|
||||
return """
|
||||
requests>=2.28.0
|
||||
flask>=2.0.0
|
||||
pytest>=7.0.0
|
||||
"""
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_pyproject_toml():
|
||||
"""Sample pyproject.toml for Python projects."""
|
||||
return """
|
||||
[project]
|
||||
name = "test-project"
|
||||
version = "1.0.0"
|
||||
description = "A test project"
|
||||
requires-python = ">=3.9"
|
||||
dependencies = [
|
||||
"requests>=2.28.0",
|
||||
"flask>=2.0.0",
|
||||
]
|
||||
|
||||
[project.optional-dependencies]
|
||||
dev = ["pytest>=7.0.0", "black>=22.0.0"]
|
||||
"""
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_go_mod():
|
||||
"""Sample go.mod for Go projects."""
|
||||
return """
|
||||
module github.com/test/project
|
||||
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/gin-gonic/gin v1.9.0
|
||||
github.com/spf13/viper v1.15.0
|
||||
)
|
||||
|
||||
require github.com/some/repo v1.2.0 // indirect
|
||||
"""
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_cargo_toml():
|
||||
"""Sample Cargo.toml for Rust projects."""
|
||||
return """
|
||||
[package]
|
||||
name = "test-project"
|
||||
version = "1.0.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
tokio = { version = "1.0", features = ["full"] }
|
||||
|
||||
[dev-dependencies]
|
||||
proptest = "1.0"
|
||||
"""
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_pom_xml():
|
||||
"""Sample pom.xml for Java projects."""
|
||||
return """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>test-project</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
<version>6.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.15.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
"""
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def temp_dir():
|
||||
"""Create a temporary directory for tests."""
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
yield Path(tmpdir)
|
||||
Reference in New Issue
Block a user