55 lines
2.5 KiB
Python
55 lines
2.5 KiB
Python
"""The registry as the launcher reads it (python -m framegen.settings) and `run.py --set KEY=VALUE`."""
|
|
import json
|
|
|
|
import pytest
|
|
|
|
from framegen import settings as S
|
|
|
|
|
|
def test_specs_json_is_plain_json_with_what_the_launcher_draws():
|
|
reg = json.loads(json.dumps(S.specs_json()))
|
|
assert reg["path"].endswith("settings.json")
|
|
keys = [s["key"] for s in reg["specs"]]
|
|
assert keys == [s.key for s in S.SPECS] and len(set(keys)) == len(keys)
|
|
for s in reg["specs"]:
|
|
for field in ("label", "group", "sub", "help", "default", "live", "saved", "quick", "impact", "experimental",
|
|
"applies", "sources", "choices"):
|
|
assert field in s, (s["key"], field)
|
|
assert s["group"], s["key"] # every setting has a section
|
|
values = [c["value"] for c in s["choices"]]
|
|
assert s["default"] in values, s["key"]
|
|
if s["applies"]: # what it depends on is a setting, and the values are that setting's
|
|
dep = S.BY_KEY[s["applies"]["key"]]
|
|
assert all(dep.accepts(v) for v in s["applies"]["values"]), s["key"]
|
|
|
|
|
|
def test_sub_headings_follow_the_layout():
|
|
by = {s["key"]: s for s in S.specs_json()["specs"]}
|
|
assert (by["hz"]["group"], by["hz"]["sub"]) == ("Frame generation", "Basics")
|
|
assert (by["output_res"]["group"], by["output_res"]["sub"]) == ("Upscaling", "Output")
|
|
|
|
|
|
@pytest.mark.parametrize("text,want", [
|
|
("interp=false", ("interp", False)), ("hz=90", ("hz", 90)), ("hz=210", ("hz", 210)),
|
|
("scaler=vsr", ("scaler", "vsr")), ('scaler="fsr"', ("scaler", "fsr")), ("fsr_sharpness=1", ("fsr_sharpness", 1.0)),
|
|
("overlay_scale=1.25", ("overlay_scale", 1.25)), ("output_res=2560x1080", ("output_res", "2560x1080")),
|
|
("game_fps=60", ("game_fps", "60")), ('game_fps="60"', ("game_fps", "60")),
|
|
("overlay_style=graphs", ("overlay_style", "graphs")), ("replay=0", ("replay", 0)),
|
|
])
|
|
def test_parse_set_takes_json_values_and_bare_words(text, want):
|
|
assert S.parse_set(text) == want
|
|
assert type(S.parse_set(text)[1]) is type(want[1])
|
|
|
|
|
|
@pytest.mark.parametrize("text", ["nonsense=1", "hz", "hz=45", "interp=1", "vsr_quality=true", "scaler=dlss", "=1",
|
|
"fill=[1]"])
|
|
def test_parse_set_refuses_what_the_setting_does_not_accept(text):
|
|
with pytest.raises(ValueError):
|
|
S.parse_set(text)
|
|
|
|
|
|
def test_every_choice_of_every_setting_goes_through_parse_set():
|
|
for spec in S.SPECS:
|
|
for v in spec.choices:
|
|
assert S.parse_set(f"{spec.key}={json.dumps(v)}") == (spec.key, v)
|