94
tests/conftest.py
Normal file
94
tests/conftest.py
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
"""Pytest configuration and fixtures."""
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from pathlib import Path
|
||||||
|
import tempfile
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def sample_json_file():
|
||||||
|
"""Create a temporary JSON file for testing."""
|
||||||
|
with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as f:
|
||||||
|
import json
|
||||||
|
json.dump({
|
||||||
|
"name": "test-app",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"debug": True,
|
||||||
|
"port": 8080,
|
||||||
|
"database": {
|
||||||
|
"host": "localhost",
|
||||||
|
"port": 5432
|
||||||
|
},
|
||||||
|
"features": ["auth", "api", "logging"]
|
||||||
|
}, f)
|
||||||
|
f.flush()
|
||||||
|
yield f.name
|
||||||
|
os.unlink(f.name)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def sample_yaml_file():
|
||||||
|
"""Create a temporary YAML file for testing."""
|
||||||
|
with tempfile.NamedTemporaryFile(mode="w", suffix=".yaml", delete=False) as f:
|
||||||
|
f.write("""
|
||||||
|
name: test-app
|
||||||
|
version: 1.0.0
|
||||||
|
debug: true
|
||||||
|
port: 8080
|
||||||
|
database:
|
||||||
|
host: localhost
|
||||||
|
port: 5432
|
||||||
|
features:
|
||||||
|
- auth
|
||||||
|
- api
|
||||||
|
- logging
|
||||||
|
""")
|
||||||
|
f.flush()
|
||||||
|
yield f.name
|
||||||
|
os.unlink(f.name)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def sample_toml_file():
|
||||||
|
"""Create a temporary TOML file for testing."""
|
||||||
|
with tempfile.NamedTemporaryFile(mode="w", suffix=".toml", delete=False) as f:
|
||||||
|
f.write("""
|
||||||
|
name = "test-app"
|
||||||
|
version = "1.0.0"
|
||||||
|
debug = true
|
||||||
|
port = 8080
|
||||||
|
|
||||||
|
[database]
|
||||||
|
host = "localhost"
|
||||||
|
port = 5432
|
||||||
|
""")
|
||||||
|
f.flush()
|
||||||
|
yield f.name
|
||||||
|
os.unlink(f.name)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def sample_ini_file():
|
||||||
|
"""Create a temporary INI file for testing."""
|
||||||
|
with tempfile.NamedTemporaryFile(mode="w", suffix=".ini", delete=False) as f:
|
||||||
|
f.write("""
|
||||||
|
[app]
|
||||||
|
name = test-app
|
||||||
|
version = 1.0.0
|
||||||
|
debug = true
|
||||||
|
|
||||||
|
[database]
|
||||||
|
host = localhost
|
||||||
|
port = 5432
|
||||||
|
""")
|
||||||
|
f.flush()
|
||||||
|
yield f.name
|
||||||
|
os.unlink(f.name)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def temp_dir():
|
||||||
|
"""Create a temporary directory for testing."""
|
||||||
|
with tempfile.TemporaryDirectory() as tmpdir:
|
||||||
|
yield Path(tmpdir)
|
||||||
Reference in New Issue
Block a user