From 9e8e7cf7bb6e79e8f6a7a30a17a75e794dad8d4e Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Sun, 1 Feb 2026 20:51:50 +0000 Subject: [PATCH] Add test suite for confgen --- app/tests/conftest.py | 98 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 app/tests/conftest.py diff --git a/app/tests/conftest.py b/app/tests/conftest.py new file mode 100644 index 0000000..9072cd0 --- /dev/null +++ b/app/tests/conftest.py @@ -0,0 +1,98 @@ +"""Pytest configuration and fixtures for confgen tests.""" + +import tempfile +from pathlib import Path +from typing import Generator + +import pytest + + +@pytest.fixture +def temp_project_dir() -> Generator[Path, None, None]: + """Create a temporary directory for testing.""" + with tempfile.TemporaryDirectory() as tmp_dir: + yield Path(tmp_dir) + + +@pytest.fixture +def sample_template(temp_project_dir: Path) -> Path: + """Create a sample template file.""" + template_content = """ +app_name: {{APP_NAME}} +version: {{VERSION}} +database: + host: {{DB_HOST}} + port: {{DB_PORT}} +""" + template_path = temp_project_dir / "template.yaml.j2" + template_path.write_text(template_content) + return template_path + + +@pytest.fixture +def sample_config(temp_project_dir: Path) -> Path: + """Create a sample configuration file.""" + config_content = """ +app_name: myapp +version: 1.0.0 +database: + host: localhost + port: 5432 +""" + config_path = temp_project_dir / "config.yaml" + config_path.write_text(config_content) + return config_path + + +@pytest.fixture +def sample_schema(temp_project_dir: Path) -> Path: + """Create a sample JSON schema.""" + import json + + schema_content = { + "type": "object", + "properties": { + "app_name": {"type": "string"}, + "version": {"type": "string"}, + "database": { + "type": "object", + "properties": { + "host": {"type": "string"}, + "port": {"type": "integer", "minimum": 1, "maximum": 65535}, + }, + "required": ["host", "port"], + }, + }, + "required": ["app_name", "database"], + } + schema_path = temp_project_dir / "schema.json" + schema_path.write_text(json.dumps(schema_content)) + return schema_path + + +@pytest.fixture +def confgen_config(temp_project_dir: Path) -> Path: + """Create a sample confgen.yaml configuration.""" + config_content = """ +templates: + sample: + path: template.yaml.j2 + format: yaml + +environments: + dev: + variables: + APP_NAME: myapp-dev + VERSION: 1.0.0-dev + DB_HOST: localhost + DB_PORT: 5432 + prod: + variables: + APP_NAME: myapp + VERSION: 1.0.0 + DB_HOST: db.example.com + DB_PORT: 5432 +""" + config_path = temp_project_dir / "confgen.yaml" + config_path.write_text(config_content) + return config_path