diff --git a/opendbc/car/tests/test_car_interfaces.py b/opendbc/car/tests/test_car_interfaces.py index a329ee3b6b2..1945bb5a291 100644 --- a/opendbc/car/tests/test_car_interfaces.py +++ b/opendbc/car/tests/test_car_interfaces.py @@ -2,6 +2,7 @@ import math import hypothesis.strategies as st import pytest +from functools import cache from hypothesis import Phase, given, settings from collections.abc import Callable from typing import Any @@ -27,7 +28,8 @@ MAX_EXAMPLES = int(os.environ.get('MAX_EXAMPLES', '15')) -def get_fuzzy_car_interface(car_name: str, draw: DrawType) -> CarInterfaceBase: +@cache +def get_fuzzy_strategy(): # Fuzzy CAN fingerprints and FW versions to test more states of the CarInterface fingerprint_strategy = st.fixed_dictionaries({0: st.dictionaries(st.integers(min_value=0, max_value=0x800), st.sampled_from(DLC_TO_LEN))}) @@ -44,8 +46,11 @@ def get_fuzzy_car_interface(car_name: str, draw: DrawType) -> CarInterfaceBase: 'car_fw': car_fw_strategy, 'alpha_long': st.booleans(), }) + return params_strategy + - params: dict = draw(params_strategy) +def get_fuzzy_car_interface(car_name: str, draw: DrawType) -> CarInterfaceBase: + params: dict = draw(get_fuzzy_strategy()) # reduce search space by duplicating CAN fingerprints across all buses params['fingerprints'] |= {key + 1: params['fingerprints'][0] for key in range(6)}