84 lines
1.4 KiB
Python
84 lines
1.4 KiB
Python
"""Pytest configuration and fixtures."""
|
|
|
|
import pytest
|
|
import tempfile
|
|
import os
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_json():
|
|
return {
|
|
"name": "test-project",
|
|
"version": "1.0.0",
|
|
"debug": True,
|
|
"database": {
|
|
"host": "localhost",
|
|
"port": 5432,
|
|
"ssl": False
|
|
},
|
|
"tags": ["python", "cli"]
|
|
}
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_yaml():
|
|
return """name: test-project
|
|
version: '1.0.0'
|
|
debug: true
|
|
database:
|
|
host: localhost
|
|
port: 5432
|
|
ssl: false
|
|
tags:
|
|
- python
|
|
- cli
|
|
"""
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_toml():
|
|
return """name = "test-project"
|
|
version = "1.0.0"
|
|
debug = true
|
|
|
|
[database]
|
|
host = "localhost"
|
|
port = 5432
|
|
ssl = false
|
|
|
|
tags = ["python", "cli"]
|
|
"""
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_env():
|
|
return """NAME=test-project
|
|
VERSION=1.0.0
|
|
DEBUG=true
|
|
DATABASE_HOST=localhost
|
|
DATABASE_PORT=5432
|
|
DATABASE_SSL=false
|
|
TAGS=python,cli
|
|
"""
|
|
|
|
|
|
@pytest.fixture
|
|
def temp_file():
|
|
def _create_temp_file(content="", suffix=".txt"):
|
|
fd, path = tempfile.mkstemp(suffix=suffix)
|
|
os.write(fd, content.encode())
|
|
os.close(fd)
|
|
yield path
|
|
os.unlink(path)
|
|
return _create_temp_file
|
|
|
|
|
|
@pytest.fixture
|
|
def temp_dir():
|
|
def _create_temp_dir():
|
|
path = tempfile.mkdtemp()
|
|
yield path
|
|
import shutil
|
|
shutil.rmtree(path)
|
|
return _create_temp_dir
|