From 341f8420dbd309c8465e1872839baacd1c1f3438 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Thu, 1 Feb 2024 17:11:10 -0600 Subject: [PATCH] fw_versions: type annotate test_brand_ecu_matches (#31272) * test this * we --- selfdrive/car/fw_versions.py | 4 ++-- selfdrive/car/tests/test_fw_fingerprint.py | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/selfdrive/car/fw_versions.py b/selfdrive/car/fw_versions.py index c9ca249ceb..78a875d2d7 100755 --- a/selfdrive/car/fw_versions.py +++ b/selfdrive/car/fw_versions.py @@ -201,12 +201,12 @@ def get_present_ecus(logcan, sendcan, num_pandas=1) -> Set[EcuAddrBusType]: return ecu_responses -def get_brand_ecu_matches(ecu_rx_addrs): +def get_brand_ecu_matches(ecu_rx_addrs: Set[EcuAddrBusType]) -> dict[str, set[AddrType]]: """Returns dictionary of brands and matches with ECUs in their FW versions""" brand_addrs = {brand: config.get_all_ecus(VERSIONS[brand], include_ecu_type=False) for brand, config in FW_QUERY_CONFIGS.items()} - brand_matches = {brand: set() for brand, _, _ in REQUESTS} + brand_matches: dict[str, set[AddrType]] = {brand: set() for brand, _, _ in REQUESTS} brand_rx_offsets = {(brand, r.rx_offset) for brand, _, r in REQUESTS} for addr, sub_addr, _ in ecu_rx_addrs: diff --git a/selfdrive/car/tests/test_fw_fingerprint.py b/selfdrive/car/tests/test_fw_fingerprint.py index f2de3ab770..8b3a45da6a 100755 --- a/selfdrive/car/tests/test_fw_fingerprint.py +++ b/selfdrive/car/tests/test_fw_fingerprint.py @@ -11,7 +11,7 @@ from cereal import car from openpilot.selfdrive.car.car_helpers import interfaces from openpilot.selfdrive.car.fingerprints import FW_VERSIONS from openpilot.selfdrive.car.fw_versions import FW_QUERY_CONFIGS, FUZZY_EXCLUDE_ECUS, VERSIONS, build_fw_dict, \ - match_fw_to_car, get_fw_versions, get_present_ecus + match_fw_to_car, get_brand_ecu_matches, get_fw_versions, get_present_ecus from openpilot.selfdrive.car.vin import get_vin CarFw = car.CarParams.CarFw @@ -178,6 +178,14 @@ class TestFwFingerprint(unittest.TestCase): self.assertFalse(request_obj.auxiliary and request_obj.bus == 1 and request_obj.obd_multiplexing, f"{brand.title()}: OBD multiplexed request is marked auxiliary: {request_obj}") + def test_brand_ecu_matches(self): + empty_response = {brand: set() for brand in FW_QUERY_CONFIGS} + self.assertEqual(get_brand_ecu_matches(set()), empty_response) + + # we ignore bus + expected_response = empty_response | {'toyota': {(0x750, 0xf)}} + self.assertEqual(get_brand_ecu_matches({(0x758, 0xf, 99)}), expected_response) + class TestFwFingerprintTiming(unittest.TestCase): N: int = 5