Files
Warehouse-Digital-Twin-and-…/tests/conftest.py
T

97 lines
2.7 KiB
Python

"""Shared pytest fixtures for Warehouse Digital Twin."""
from __future__ import annotations
import json
from pathlib import Path
from typing import Any, Dict
import pytest
@pytest.fixture
def project_root() -> Path:
"""Return the absolute path to the project root directory."""
return Path(__file__).resolve().parents[1]
@pytest.fixture
def project_config_dir(project_root: Path) -> Path:
"""Return the path to the real project configuration directory."""
return project_root / "config"
@pytest.fixture
def temp_config_dir(tmp_path: Path) -> Path:
"""Create a temporary directory with valid configuration files for testing."""
config_dir = tmp_path / "config"
config_dir.mkdir(parents=True, exist_ok=True)
warehouse_data = {
"coordinate_system": {"type": "right_handed_cartesian", "units": "meters"},
"dimensions": {"width": 60.0, "depth": 40.0, "height": 8.0},
"zones": {
"zone_a": {"name": "Zone A"},
"zone_b": {"name": "Zone B"},
"zone_c": {"name": "Zone C"},
},
"stations": [{"station_id": "st_1", "type": "dock", "position": [1.0, 1.0, 0.0]}],
"charging_stations": [{"station_id": "ch_1", "position": [2.0, 2.0, 0.0], "capacity": 1}],
}
robots_data = {
"robot_types": {
"light_amr": {
"payload_capacity_kg": 150.0,
"max_speed_mps": 1.8,
"battery_capacity_kwh": 3.0,
}
},
"fleet": [
{
"robot_id": "amr_1",
"robot_type": "light_amr",
"initial_position": [0.0, 0.0, 0.0],
}
],
}
inventory_data = {
"categories": {
"zone_a_items": {
"name": "Zone A Items",
"items": [
{
"item_id": "item_1",
"name": "Filter HF-1",
"unit_weight_kg": 2.0,
"initial_stock": 100,
}
],
}
}
}
simulation_data = {
"simulation": {
"duration_seconds": 3600.0,
"random_seed": 42,
}
}
dispatch_data = {
"active_policy": "nearest_idle",
"available_policies": ["nearest_idle", "priority_first"],
}
for name, data in [
("warehouse.json", warehouse_data),
("robots.json", robots_data),
("inventory.json", inventory_data),
("simulation.json", simulation_data),
("dispatch_policies.json", dispatch_data),
]:
with open(config_dir / name, "w", encoding="utf-8") as f:
json.dump(data, f)
return config_dir