32 lines
873 B
Python
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()
|