mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
[robotpy] Mirror most other subprojects (#8208)
GitOrigin-RevId: ac60fd3cf4a24023184376687da28373d14b781a This mirrors the robotpy files for the following projects: - apriltag - datalog - hal - ntcore - romiVendordep - wpilibc - wpimath - xrpVendordep This excludes cscore and the halsim wrappers for at this time. NOTE: This does not hook these projects up to the build system, just simply mirrors the files. The building will take place in a follow up PR to make it easier to review the changes necessary to build.
This commit is contained in:
47
hal/src/test/python/test_hal.py
Normal file
47
hal/src/test/python/test_hal.py
Normal file
@@ -0,0 +1,47 @@
|
||||
import hal
|
||||
|
||||
|
||||
def test_hal_simdevice():
|
||||
device = hal.SimDevice("deviceName")
|
||||
v = device.createInt("i", 0, 1)
|
||||
assert v.get() == 1
|
||||
assert v.type == hal.Type.INT
|
||||
|
||||
v.set(4)
|
||||
assert v.get() == 4
|
||||
|
||||
|
||||
def test_hal_simdevice_enum():
|
||||
device = hal.SimDevice("enumDevice")
|
||||
names = ["one", "two", "three"]
|
||||
v = device.createEnum("e", 0, names, 0)
|
||||
|
||||
assert v.get() == 0
|
||||
assert v.type == hal.Type.ENUM
|
||||
|
||||
for value, name in enumerate(names):
|
||||
v.set(value)
|
||||
assert repr(v) == f"<SimEnum name={name} value={value}>"
|
||||
|
||||
|
||||
def test_hal_simdevice_enum_double():
|
||||
device = hal.SimDevice("enumDevice")
|
||||
names = ["one", "two", "three"]
|
||||
values = [0.0, 1.0, 2.0]
|
||||
v = device.createEnumDouble("e", 0, names, values, 0)
|
||||
|
||||
assert v.get() == 0
|
||||
assert v.type == hal.Type.ENUM
|
||||
|
||||
# TODO: update this test to not use repr once https://github.com/wpilibsuite/allwpilib/issues/7800
|
||||
# is resolved
|
||||
|
||||
for value, (name, dvalue) in enumerate(zip(names, values)):
|
||||
v.set(value)
|
||||
assert repr(v) == f"<SimEnum name={name} value={value} dvalue={dvalue:.6f}>"
|
||||
|
||||
|
||||
def test_hal_send_error(capsys):
|
||||
hal._wpiHal.__test_senderr()
|
||||
cap = capsys.readouterr()
|
||||
assert cap.err == "Error at location: <20>badmessage\ncallstack\n\n"
|
||||
41
hal/src/test/python/test_hal_simulation.py
Normal file
41
hal/src/test/python/test_hal_simulation.py
Normal file
@@ -0,0 +1,41 @@
|
||||
import hal
|
||||
import hal.simulation
|
||||
|
||||
import typing
|
||||
|
||||
|
||||
def test_value_changed_callback():
|
||||
|
||||
recv: typing.Optional[typing.Tuple[bool, str, int]] = None
|
||||
|
||||
def created_cb(
|
||||
name: str, handle: int, direction: hal.SimValueDirection, value: hal.Value
|
||||
):
|
||||
nonlocal recv
|
||||
recv = (True, name, value.value)
|
||||
|
||||
def cb(name: str, handle: int, direction: hal.SimValueDirection, value: hal.Value):
|
||||
nonlocal recv
|
||||
recv = (False, name, value.value)
|
||||
|
||||
dev = hal.SimDevice("simd")
|
||||
|
||||
# Must keep the returned value alive or the callback will be unregistered
|
||||
devunused = hal.simulation.registerSimValueCreatedCallback(dev, created_cb, True)
|
||||
assert recv is None
|
||||
|
||||
val = dev.createInt("answer", 0, 42)
|
||||
|
||||
assert recv == (True, "answer", 42)
|
||||
recv = None
|
||||
|
||||
# Must keep the returned value alive or the callback will be unregistered
|
||||
unused = hal.simulation.registerSimValueChangedCallback(val, cb, True)
|
||||
|
||||
assert recv == (False, "answer", 42)
|
||||
recv = None
|
||||
|
||||
val.set(84)
|
||||
|
||||
assert recv == (False, "answer", 84)
|
||||
recv = None
|
||||
Reference in New Issue
Block a user