from datetime import datetime
from pathlib import PurePosixPath

import pytest

from govcrawler.storage.paths import build_reldir, to_os_path


def test_build_reldir_posix():
    d = datetime(2026, 4, 10, 12, 0, 0)
    r = build_reldir("gdqy", "szfwj", d, "raw_html")
    assert isinstance(r, PurePosixPath)
    assert str(r) == "raw_html/gdqy/szfwj/2026/04"


def test_build_reldir_invalid_kind():
    with pytest.raises(ValueError):
        build_reldir("gdqy", "szfwj", datetime(2026, 1, 1), "nonsense")


def test_to_os_path_joins():
    d = datetime(2026, 4, 10)
    r = build_reldir("gdqy", "szfwj", d, "articles_text")
    p = to_os_path("/tmp/data", r)
    assert p.parts[-5:] == ("articles_text", "gdqy", "szfwj", "2026", "04")
