File size: 1,252 Bytes
0185029
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from __future__ import annotations

from pathlib import Path

import pytest

from orarl import (
    available_configs,
    config_path,
    documentation_path,
    script_path,
)

RELEASE_ROOT = Path(__file__).resolve().parents[1]


def test_source_resources_are_discoverable() -> None:
    assert available_configs() == (
        "grpo_4b.yaml",
        "grpo_9b.yaml",
        "orarl_4b.yaml",
        "orarl_9b.yaml",
    )
    assert config_path("orarl_4b.yaml") == (RELEASE_ROOT / "configs" / "orarl_4b.yaml")
    assert documentation_path("environment.md") == (RELEASE_ROOT / "docs" / "environment.md")
    assert documentation_path("training.md") == (RELEASE_ROOT / "docs" / "training.md")
    assert documentation_path("evaluation.md") == (RELEASE_ROOT / "docs" / "evaluation.md")
    assert script_path("train_orarl.sh") == (RELEASE_ROOT / "scripts" / "train_orarl.sh")


@pytest.mark.parametrize("name", ("", ".", "..", "../orarl_4b.yaml"))
def test_resource_names_reject_path_traversal(name: str) -> None:
    with pytest.raises(ValueError, match="file name"):
        config_path(name)


def test_unknown_resource_has_clear_error() -> None:
    with pytest.raises(FileNotFoundError, match="not found"):
        config_path("unknown.yaml")