55 lines
1.5 KiB
Python
55 lines
1.5 KiB
Python
"""The probe: what it draws, without a pad or a terminal."""
|
|
|
|
from dora_joy.gamepad import Sample
|
|
from dora_joy.probe import bar, render
|
|
from tests.conftest import stick
|
|
|
|
|
|
def test_a_centred_stick_puts_the_marker_in_the_middle():
|
|
drawn = bar(0.0)
|
|
|
|
assert drawn[len(drawn) // 2] == "#"
|
|
|
|
|
|
def test_the_bar_leans_the_way_the_stick_is_pushed():
|
|
left = bar(-1.0)
|
|
right = bar(1.0)
|
|
|
|
assert left.index("#") < left.index("|")
|
|
assert right.index("#") > right.index("|")
|
|
|
|
|
|
def test_a_reading_beyond_full_deflection_stays_on_the_bar():
|
|
# SDL has been known to report slightly outside -1..1 on a worn stick.
|
|
assert "#" in bar(-4.0)
|
|
assert "#" in bar(4.0)
|
|
|
|
|
|
def test_no_gamepad_says_so_and_names_the_index_it_looked_for(config):
|
|
config.joystick_index = 2
|
|
|
|
drawn = render(Sample(present=False), config)
|
|
|
|
assert "no gamepad found" in drawn
|
|
assert "index 2" in drawn
|
|
|
|
|
|
def test_every_axis_the_pad_reports_is_shown(config):
|
|
# A pad whose sticks land on unexpected indices is what this is for, so
|
|
# nothing may be hidden.
|
|
drawn = render(Sample(axes=[0.0] * 8, buttons=[], present=True), config)
|
|
|
|
assert "axes (8 reported)" in drawn
|
|
for index in range(8):
|
|
assert f" {index} " in drawn
|
|
|
|
|
|
def test_the_buttons_being_held_are_listed_by_index(config):
|
|
drawn = render(stick(buttons=[False, True, False, True]), config)
|
|
|
|
assert "1, 3" in drawn
|
|
|
|
|
|
def test_a_pad_with_nothing_pressed_says_so(config):
|
|
assert "none pressed" in render(stick(), config)
|