Remove test_motors_bus fixtures
This commit is contained in:
parent
f960f4d8d4
commit
e0b292ab51
|
@ -10,29 +10,56 @@ from lerobot.common.motors.motors_bus import (
|
||||||
get_ctrl_table,
|
get_ctrl_table,
|
||||||
)
|
)
|
||||||
|
|
||||||
DUMMY_CTRL_TABLE = {"Present_Position": (13, 4)}
|
DUMMY_CTRL_TABLE_1 = {
|
||||||
|
"Firmware_Version": (0, 1),
|
||||||
|
"Model_Number": (1, 2),
|
||||||
|
"Present_Position": (3, 4),
|
||||||
|
"Goal_Position": (7, 2),
|
||||||
|
}
|
||||||
|
|
||||||
|
DUMMY_CTRL_TABLE_2 = {
|
||||||
|
"Model_Number": (0, 2),
|
||||||
|
"Firmware_Version": (2, 1),
|
||||||
|
"Present_Position": (3, 4),
|
||||||
|
"Goal_Position": (7, 4),
|
||||||
|
"Lock": (7, 4),
|
||||||
|
}
|
||||||
|
|
||||||
|
DUMMY_MODEL_CTRL_TABLE = {
|
||||||
|
"model_1": DUMMY_CTRL_TABLE_1,
|
||||||
|
"model_2": DUMMY_CTRL_TABLE_2,
|
||||||
|
}
|
||||||
|
|
||||||
DUMMY_BAUDRATE_TABLE = {
|
DUMMY_BAUDRATE_TABLE = {
|
||||||
0: 1_000_000,
|
0: 1_000_000,
|
||||||
1: 500_000,
|
1: 500_000,
|
||||||
}
|
}
|
||||||
|
|
||||||
DUMMY_ENCODING_TABLE = {
|
DUMMY_MODEL_BAUDRATE_TABLE = {
|
||||||
"Present_Position": 8,
|
"model_1": DUMMY_BAUDRATE_TABLE,
|
||||||
|
"model_2": DUMMY_BAUDRATE_TABLE,
|
||||||
}
|
}
|
||||||
|
|
||||||
DUMMY_MODEL_NUMBER_TABLE = {""}
|
DUMMY_ENCODING_TABLE = {
|
||||||
|
"Present_Position": 8,
|
||||||
|
"Goal_Position": 10,
|
||||||
|
}
|
||||||
|
|
||||||
|
DUMMY_MODEL_ENCODING_TABLE = {
|
||||||
|
"model_1": DUMMY_ENCODING_TABLE,
|
||||||
|
"model_2": DUMMY_ENCODING_TABLE,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class DummyMotorsBus(MotorsBus):
|
class DummyMotorsBus(MotorsBus):
|
||||||
available_baudrates = [1_000_000]
|
available_baudrates = [500_000, 1_000_000]
|
||||||
default_timeout = 1000
|
default_timeout = 1000
|
||||||
model_baudrate_table = {"model": DUMMY_BAUDRATE_TABLE}
|
model_baudrate_table = DUMMY_MODEL_BAUDRATE_TABLE
|
||||||
model_ctrl_table = {"model": DUMMY_CTRL_TABLE}
|
model_ctrl_table = DUMMY_MODEL_CTRL_TABLE
|
||||||
model_encoding_table = {"model": DUMMY_ENCODING_TABLE}
|
model_encoding_table = DUMMY_MODEL_ENCODING_TABLE
|
||||||
model_number_table = {"model": 1234}
|
model_number_table = {"model_1": 1234, "model_2": 5678}
|
||||||
model_resolution_table = {"model": 4096}
|
model_resolution_table = {"model_1": 4096, "model_2": 1024}
|
||||||
normalized_data = ["Present_Position"]
|
normalized_data = ["Present_Position", "Goal_Position"]
|
||||||
|
|
||||||
def __init__(self, port: str, motors: dict[str, Motor]):
|
def __init__(self, port: str, motors: dict[str, Motor]):
|
||||||
super().__init__(port, motors)
|
super().__init__(port, motors)
|
||||||
|
@ -48,81 +75,52 @@ class DummyMotorsBus(MotorsBus):
|
||||||
def broadcast_ping(self, num_retry, raise_on_error): ...
|
def broadcast_ping(self, num_retry, raise_on_error): ...
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
def test_get_ctrl_table():
|
||||||
def ctrl_table_1() -> dict:
|
|
||||||
return {
|
|
||||||
"Firmware_Version": (0, 1),
|
|
||||||
"Model_Number": (1, 2),
|
|
||||||
"Present_Position": (3, 4),
|
|
||||||
"Goal_Position": (7, 2),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def ctrl_table_2() -> dict:
|
|
||||||
return {
|
|
||||||
"Model_Number": (0, 2),
|
|
||||||
"Firmware_Version": (2, 1),
|
|
||||||
"Present_Position": (3, 4),
|
|
||||||
"Goal_Position": (7, 4),
|
|
||||||
"Lock": (7, 4),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def model_ctrl_table(ctrl_table_1, ctrl_table_2) -> dict:
|
|
||||||
return {
|
|
||||||
"model_1": ctrl_table_1,
|
|
||||||
"model_2": ctrl_table_2,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def test_get_ctrl_table(model_ctrl_table, ctrl_table_1):
|
|
||||||
model = "model_1"
|
model = "model_1"
|
||||||
ctrl_table = get_ctrl_table(model_ctrl_table, model)
|
ctrl_table = get_ctrl_table(DUMMY_MODEL_CTRL_TABLE, model)
|
||||||
assert ctrl_table == ctrl_table_1
|
assert ctrl_table == DUMMY_CTRL_TABLE_1
|
||||||
|
|
||||||
|
|
||||||
def test_get_ctrl_table_error(model_ctrl_table):
|
def test_get_ctrl_table_error():
|
||||||
model = "model_99"
|
model = "model_99"
|
||||||
with pytest.raises(KeyError, match=f"Control table for {model=} not found."):
|
with pytest.raises(KeyError, match=f"Control table for {model=} not found."):
|
||||||
get_ctrl_table(model_ctrl_table, model)
|
get_ctrl_table(DUMMY_MODEL_CTRL_TABLE, model)
|
||||||
|
|
||||||
|
|
||||||
def test_get_address(model_ctrl_table):
|
def test_get_address():
|
||||||
addr, n_bytes = get_address(model_ctrl_table, "model_1", "Firmware_Version")
|
addr, n_bytes = get_address(DUMMY_MODEL_CTRL_TABLE, "model_1", "Firmware_Version")
|
||||||
assert addr == 0
|
assert addr == 0
|
||||||
assert n_bytes == 1
|
assert n_bytes == 1
|
||||||
|
|
||||||
|
|
||||||
def test_get_address_error(model_ctrl_table):
|
def test_get_address_error():
|
||||||
model = "model_1"
|
model = "model_1"
|
||||||
data_name = "Lock"
|
data_name = "Lock"
|
||||||
with pytest.raises(KeyError, match=f"Address for '{data_name}' not found in {model} control table."):
|
with pytest.raises(KeyError, match=f"Address for '{data_name}' not found in {model} control table."):
|
||||||
get_address(model_ctrl_table, "model_1", data_name)
|
get_address(DUMMY_MODEL_CTRL_TABLE, "model_1", data_name)
|
||||||
|
|
||||||
|
|
||||||
def test_assert_same_address(model_ctrl_table):
|
def test_assert_same_address():
|
||||||
models = ["model_1", "model_2"]
|
models = ["model_1", "model_2"]
|
||||||
assert_same_address(model_ctrl_table, models, "Present_Position")
|
assert_same_address(DUMMY_MODEL_CTRL_TABLE, models, "Present_Position")
|
||||||
|
|
||||||
|
|
||||||
def test_assert_same_address_different_addresses(model_ctrl_table):
|
def test_assert_same_address_different_addresses():
|
||||||
models = ["model_1", "model_2"]
|
models = ["model_1", "model_2"]
|
||||||
with pytest.raises(
|
with pytest.raises(
|
||||||
NotImplementedError,
|
NotImplementedError,
|
||||||
match=re.escape("At least two motor models use a different address"),
|
match=re.escape("At least two motor models use a different address"),
|
||||||
):
|
):
|
||||||
assert_same_address(model_ctrl_table, models, "Model_Number")
|
assert_same_address(DUMMY_MODEL_CTRL_TABLE, models, "Model_Number")
|
||||||
|
|
||||||
|
|
||||||
def test_assert_same_address_different_bytes(model_ctrl_table):
|
def test_assert_same_address_different_bytes():
|
||||||
models = ["model_1", "model_2"]
|
models = ["model_1", "model_2"]
|
||||||
with pytest.raises(
|
with pytest.raises(
|
||||||
NotImplementedError,
|
NotImplementedError,
|
||||||
match=re.escape("At least two motor models use a different bytes representation"),
|
match=re.escape("At least two motor models use a different bytes representation"),
|
||||||
):
|
):
|
||||||
assert_same_address(model_ctrl_table, models, "Goal_Position")
|
assert_same_address(DUMMY_MODEL_CTRL_TABLE, models, "Goal_Position")
|
||||||
|
|
||||||
|
|
||||||
def test__serialize_data_invalid_length():
|
def test__serialize_data_invalid_length():
|
||||||
|
|
Loading…
Reference in New Issue