Files
dora-joy/tests/test_config.py
cristhian 3624c63ead
validate / validate (pull_request) Successful in 58m42s
validate / test (pull_request) Successful in 58m47s
validate / markdownlint (pull_request) Successful in 58m40s
add dora-joy node publishing gamepad axes and buttons
2026-09-16 05:10:33 -05:00

32 lines
873 B
Python

"""Settings, and refusing the ones that cannot work."""
import pytest
from dora_joy.config import Config
def test_the_first_pad_is_the_default():
assert Config.from_env().joystick_index == 0
def test_the_index_comes_from_the_environment(monkeypatch):
monkeypatch.setenv("JOYSTICK_INDEX", "2")
assert Config.from_env().joystick_index == 2
def test_an_index_that_is_not_a_number_names_the_variable(monkeypatch):
monkeypatch.setenv("JOYSTICK_INDEX", "left")
with pytest.raises(ValueError, match="JOYSTICK_INDEX"):
Config.from_env()
def test_a_negative_index_is_refused_at_startup(monkeypatch):
# Not at the first read of the pad, which is the one moment nobody is
# watching the node's stderr.
monkeypatch.setenv("JOYSTICK_INDEX", "-1")
with pytest.raises(ValueError, match="JOYSTICK_INDEX"):
Config.from_env()