Newer
Older
SmTIAS-LightSim / tests / cli / conftest.py
"""cli テスト共通フィクスチャ.

不正 YAML など CLI 異常系テスト用の一時ファイルを提供する.
"""

from __future__ import annotations

from pathlib import Path

import pytest


@pytest.fixture
def invalid_yaml_file(tmp_path: Path) -> Path:
    """必須フィールド(name)が欠落した不正 YAML ファイルを tmp_path に書き出す.

    load_scene_yaml が Pydantic ValidationError を投げる経路を踏ませるためのフィクスチャ.
    FileNotFoundError とは異なる「読み込み失敗」経路のテスト用.
    """
    content = """\
# name フィールドを意図的に省略(必須フィールド欠落)
geometry:
  meshes:
    - id: sphere
      path: meshes/sphere.stl
      unit: mm
      material: white
materials:
  white:
    type: diffuse
    reflectance: 0.9
lights:
  - id: led_top
    type: point
    position: [0.0, 0.0, 50.0]
    intensity: 10.0
    profile: lambertian
sensor:
  type: perspective
  position: [0.0, 0.0, 100.0]
  target: [0.0, 0.0, 0.0]
  up: [0.0, 1.0, 0.0]
  fov_deg: 60.0
  film:
    width: 64
    height: 64
render:
  variant: llvm_ad_rgb
  integrator: path
  max_depth: 4
  spp: 4
"""
    yaml_path = tmp_path / "invalid_scene.yaml"
    yaml_path.write_text(content, encoding="utf-8")
    return yaml_path