Skip to content

Commit

Permalink
test: add unit testing for vehicle state
Browse files Browse the repository at this point in the history
Signed-off-by: ktro2828 <[email protected]>
  • Loading branch information
ktro2828 committed Nov 16, 2024
1 parent eeb1a16 commit 398d4d6
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion t4_devkit/schema/tables/vehicle_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class AdditionalInfo:
speed: float | None = field(default=None)


@define
@define(slots=False)
@SCHEMAS.register(SchemaName.VEHICLE_STATE)
class VehicleState(SchemaBase):
"""A dataclass to represent schema table of `vehicle_state.json`.
Expand Down
26 changes: 26 additions & 0 deletions tests/schema/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,29 @@ def surface_ann_json(surface_ann_dict) -> Generator[str, Any, None]:
with tempfile.NamedTemporaryFile(suffix=".json", delete=False) as f:
save_json([surface_ann_dict], f.name)
yield f.name


# === VehicleState ===
@pytest.fixture(scope="module")
def vehicle_state_dict() -> dict:
"""Return a dummy vehicle state as dictionary."""
return {
"token": "269572c280bd5cf9630ca542e6a60185",
"timestamp": 1724306784277396,
"accel_pedal": 0.0,
"brake_pedal": 1.0,
"steer_pedal": 0.6063521901837905,
"steering_tire_angle": 0.6063522100448608,
"steering_wheel_angle": 9.291000366210938,
"shift_state": "PARK",
"indicators": {"left": "off", "right": "on", "hazard": "off"},
"additional_info": {"speed": 0.0},
}


@pytest.fixture(scope="module")
def vehicle_state_json(vehicle_state_dict) -> Generator[str, Any, None]:
"""Return a file path of dummy vehicle state record."""
with tempfile.NamedTemporaryFile(suffix=".json", delete=False) as f:
save_json([vehicle_state_dict], f.name)
yield f.name
12 changes: 12 additions & 0 deletions tests/schema/tables/test_vehicle_state_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from t4_devkit.schema import VehicleState


def test_vehicle_state_json(vehicle_state_json) -> None:
"""Test loading vehicle state from a json file."""
_ = VehicleState.from_json(vehicle_state_json)


def test_vehicle_state(vehicle_state_dict) -> None:
"""Test loading vehicle state from a dictionary."""
s = VehicleState.from_dict(vehicle_state_dict)
print(s)
5 changes: 5 additions & 0 deletions tests/schema/test_schema_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ def test_build_surface_ann(surface_ann_json) -> None:
_ = build_schema(SchemaName.SURFACE_ANN, surface_ann_json)


def test_build_vehicle_state(vehicle_state_json) -> None:
"""Test building vehicle state."""
_ = build_schema(SchemaName.VEHICLE_STATE, vehicle_state_json)


def test_build_visibility(visibility_json) -> None:
"""Test building visibility."""
_ = build_schema(SchemaName.VISIBILITY, visibility_json)
1 change: 1 addition & 0 deletions tests/schema/test_schema_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def test_schema_name() -> None:
"object_ann": True,
"surface_ann": True,
"keypoint": True,
"vehicle_state": True,
}

# check all enum members are covered by above names
Expand Down

0 comments on commit 398d4d6

Please sign in to comment.