"""Pytest configuration and fixtures for ConfigForge tests.""" import json import os import tempfile from pathlib import Path from typing import Dict, Any import pytest @pytest.fixture def sample_json_config() -> Dict[str, Any]: """Sample JSON configuration for testing.""" return { "database": { "host": "localhost", "port": 5432, "name": "myapp", "ssl": True }, "server": { "host": "0.0.0.0", "port": 8080, "debug": False }, "logging": { "level": "INFO", "format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s" } } @pytest.fixture def sample_yaml_config() -> str: """Sample YAML configuration for testing.""" return """database: host: localhost port: 5432 name: myapp ssl: true server: host: 0.0.0.0 port: 8080 debug: false logging: level: INFO """ @pytest.fixture def sample_toml_config() -> str: """Sample TOML configuration for testing.""" return """[database] host = "localhost" port = 5432 name = "myapp" ssl = true [server] host = "0.0.0.0" port = 8080 debug = false [logging] level = "INFO" """ @pytest.fixture def sample_env_config() -> str: """Sample ENV configuration for testing.""" return """DATABASE_HOST=localhost DATABASE_PORT=5432 DATABASE_NAME=myapp DATABASE_SSL=true SERVER_HOST=0.0.0.0 SERVER_PORT=8080 SERVER_DEBUG=false LOGGING_LEVEL=INFO """ @pytest.fixture def sample_json_schema() -> Dict[str, Any]: """Sample JSON Schema for validation testing.""" return { "$schema": "http://json-schema.org/draft-07/schema#", "title": "AppConfig", "type": "object", "required": ["database", "server"], "properties": { "database": { "type": "object", "required": ["host", "port", "name"], "properties": { "host": {"type": "string"}, "port": {"type": "integer", "minimum": 1, "maximum": 65535}, "name": {"type": "string"}, "ssl": {"type": "boolean"} } }, "server": { "type": "object", "required": ["host", "port"], "properties": { "host": {"type": "string"}, "port": {"type": "integer", "minimum": 1, "maximum": 65535}, "debug": {"type": "boolean"} } }, "logging": { "type": "object", "properties": { "level": {"type": "string", "enum": ["DEBUG", "INFO", "WARNING", "ERROR"]}, "format": {"type": "string"} } } } } @pytest.fixture def temp_config_file(sample_json_config): """Create a temporary JSON config file.""" with tempfile.NamedTemporaryFile(mode='w', suffix='.json', delete=False) as f: json.dump(sample_json_config, f) filepath = f.name yield filepath os.unlink(filepath) @pytest.fixture def temp_yaml_config_file(sample_yaml_config): """Create a temporary YAML config file.""" with tempfile.NamedTemporaryFile(mode='w', suffix='.yaml', delete=False) as f: f.write(sample_yaml_config) filepath = f.name yield filepath os.unlink(filepath) @pytest.fixture def temp_toml_config_file(sample_toml_config): """Create a temporary TOML config file.""" with tempfile.NamedTemporaryFile(mode='w', suffix='.toml', delete=False) as f: f.write(sample_toml_config) filepath = f.name yield filepath os.unlink(filepath) @pytest.fixture def temp_env_config_file(sample_env_config): """Create a temporary ENV config file.""" with tempfile.NamedTemporaryFile(mode='w', suffix='.env', delete=False) as f: f.write(sample_env_config) filepath = f.name yield filepath os.unlink(filepath) @pytest.fixture def temp_schema_file(sample_json_schema): """Create a temporary JSON schema file.""" with tempfile.NamedTemporaryFile(mode='w', suffix='.json', delete=False) as f: json.dump(sample_json_schema, f) filepath = f.name yield filepath os.unlink(filepath)