from __future__ import annotations

from pathlib import Path

import pytest


def test_load_yaml_empty_file(tmp_path: Path):
    from argus.ray.yaml_io import load_yaml

    p = tmp_path / "empty.yaml"
    p.write_text("", encoding="utf-8")
    assert load_yaml(str(p)) == {}


def test_load_yaml_requires_mapping(tmp_path: Path):
    from argus.ray.yaml_io import load_yaml

    p = tmp_path / "bad.yaml"
    p.write_text("- 1\n- 2\n", encoding="utf-8")
    with pytest.raises(ValueError, match="yaml root must be a mapping"):
        load_yaml(str(p))


def test_dump_yaml_roundtrip_smoke(tmp_path: Path):
    from argus.ray.yaml_io import dump_yaml, load_yaml

    text = dump_yaml({"a": 1, "b": {"c": "d"}})
    assert "a: 1" in text

    p = tmp_path / "x.yaml"
    p.write_text(text, encoding="utf-8")
    assert load_yaml(str(p))["b"]["c"] == "d"

