#!/usr/bin/env python3 """Tests for linkctl-gamepad's pure helpers. Run: python3 tests/test_gamepad.py These cover what can be checked without a controller: decoding the kernel's joystick event struct, deadzone rescaling, command construction and argument parsing. Device discovery and the read loop need real hardware. """ import importlib.util import os import struct import sys import unittest HERE = os.path.dirname(os.path.abspath(__file__)) TARGET = os.path.join(HERE, "..", "bin", "linkctl-gamepad") # The script has no .py extension, so load it by path. _spec = importlib.util.spec_from_loader( "linkctl_gamepad", importlib.machinery.SourceFileLoader("linkctl_gamepad", TARGET), ) gp = importlib.util.module_from_spec(_spec) _spec.loader.exec_module(gp) def js_event(value, etype, number, tstamp=0): """Build a raw joystick event the way the kernel would.""" return struct.pack("