38 lines
1 KiB
Python
38 lines
1 KiB
Python
import runpy
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
from omegaconf.errors import ConfigKeyError
|
|
|
|
SCRIPT_PATH = Path(__file__).parents[1] / "scripts" / "train.py"
|
|
|
|
|
|
def load_config(args):
|
|
script = runpy.run_path(str(SCRIPT_PATH), run_name="train_script")
|
|
return script["load_config"](args)
|
|
|
|
|
|
def test_cli_values_override_structured_defaults():
|
|
config = load_config(
|
|
[
|
|
"num_envs=32",
|
|
"lr=1e-4",
|
|
"grid_dims=[6,6]",
|
|
"checkpoint_path=models/test.eqx",
|
|
"opponent=hunter",
|
|
"resume_from=models/previous.eqx",
|
|
]
|
|
)
|
|
|
|
assert config.num_envs == 32
|
|
assert config.lr == 1e-4
|
|
assert list(config.grid_dims) == [6, 6]
|
|
assert config.checkpoint_path == "models/test.eqx"
|
|
assert config.opponent == "hunter"
|
|
assert config.resume_from == "models/previous.eqx"
|
|
assert config.rollout_steps == 256
|
|
|
|
|
|
def test_unknown_cli_key_is_rejected():
|
|
with pytest.raises(ConfigKeyError):
|
|
load_config(["unknown_option=1"])
|