hokusai/tests/test_config.py
Konstantin Fickel 870023865d
feat: add OpenAI as provider for text and image generation
- Add openai_text.py: text generation via OpenAI chat completions API
  (gpt-4o, gpt-4o-mini, gpt-4.1, gpt-4.1-mini, gpt-4.1-nano, o3-mini)
- Add openai_image.py: image generation via OpenAI images API
  (gpt-image-1 with reference image support, dall-e-3, dall-e-2)
- Refactor builder provider dispatch from TargetType to model-name index
  to support multiple providers per target type
- Fix circular import between config.py and providers/__init__.py
  using TYPE_CHECKING guard
- Fix stale default model assertions in tests
- Add openai>=1.0.0 dependency
2026-02-15 13:48:06 +01:00

81 lines
2.8 KiB
Python

"""Integration tests for bulkgen.config."""
from __future__ import annotations
from pathlib import Path
import pytest
import yaml
from bulkgen.config import load_config
class TestLoadConfig:
"""Test loading and validating YAML config files end-to-end."""
def test_minimal_config(self, project_dir: Path) -> None:
config_path = project_dir / "test.bulkgen.yaml"
_ = config_path.write_text(
yaml.dump({"targets": {"out.txt": {"prompt": "hello"}}})
)
config = load_config(config_path)
assert "out.txt" in config.targets
assert config.targets["out.txt"].prompt == "hello"
assert config.defaults.text_model == "pixtral-large-latest"
assert config.defaults.image_model == "flux-2-pro"
def test_full_config_with_all_fields(self, project_dir: Path) -> None:
raw = {
"defaults": {
"text_model": "custom-text",
"image_model": "custom-image",
},
"targets": {
"banner.png": {
"prompt": "A wide banner",
"model": "flux-dev",
"width": 1920,
"height": 480,
"inputs": ["ref.png"],
"reference_images": ["ref.png"],
"control_images": ["ctrl.png"],
},
"story.md": {
"prompt": "Write a story",
"inputs": ["banner.png"],
},
},
}
config_path = project_dir / "full.bulkgen.yaml"
_ = config_path.write_text(yaml.dump(raw, default_flow_style=False))
config = load_config(config_path)
assert config.defaults.text_model == "custom-text"
assert config.defaults.image_model == "custom-image"
banner = config.targets["banner.png"]
assert banner.model == "flux-dev"
assert banner.width == 1920
assert banner.height == 480
assert banner.reference_images == ["ref.png"]
assert banner.control_images == ["ctrl.png"]
story = config.targets["story.md"]
assert story.model is None
assert story.inputs == ["banner.png"]
def test_empty_targets_rejected(self, project_dir: Path) -> None:
config_path = project_dir / "empty.bulkgen.yaml"
_ = config_path.write_text(yaml.dump({"targets": {}}))
with pytest.raises(Exception, match="At least one target"):
_ = load_config(config_path)
def test_missing_prompt_rejected(self, project_dir: Path) -> None:
config_path = project_dir / "bad.bulkgen.yaml"
_ = config_path.write_text(yaml.dump({"targets": {"out.txt": {}}}))
with pytest.raises(Exception):
_ = load_config(config_path)