1- from  hypothesis  import  settings , given , strategies  as  st 
2- 
31import  pytest 
42
53from  opendbc .car  import  gen_empty_fingerprint 
64from  opendbc .car .structs  import  CarParams 
7- from  opendbc .car .fw_versions  import  build_fw_dict 
8- from  opendbc .car .hyundai .interface  import  CarInterface 
95from  opendbc .car .hyundai .hyundaicanfd  import  CanBus 
10- from  opendbc .car .hyundai .radar_interface  import  RADAR_START_ADDR 
116from  opendbc .car .hyundai .values  import  CAMERA_SCC_CAR , CANFD_CAR , CAN_GEARS , CAR , CHECKSUM , DATE_FW_ECUS , \
127                                         HYBRID_CAR , EV_CAR , FW_QUERY_CONFIG , LEGACY_SAFETY_MODE_CAR , CANFD_FUZZY_WHITELIST , \
138                                         UNSUPPORTED_LONGITUDINAL_CAR , PLATFORM_CODE_ECUS , HYUNDAI_VERSION_REQUEST_LONG , \
149                                         HyundaiFlags , get_platform_codes , HyundaiSafetyFlags 
15- from  opendbc .car .hyundai .fingerprints  import  FW_VERSIONS 
1610
1711Ecu  =  CarParams .Ecu 
1812
4539
4640class  TestHyundaiFingerprint :
4741  def  test_feature_detection (self ):
42+     from  opendbc .car .hyundai .interface  import  CarInterface 
43+     from  opendbc .car .hyundai .radar_interface  import  RADAR_START_ADDR 
4844    # LKA steering 
4945    for  lka_steering  in  (True , False ):
5046      fingerprint  =  gen_empty_fingerprint ()
@@ -63,6 +59,8 @@ def test_feature_detection(self):
6359      assert  CP .radarUnavailable  !=  radar 
6460
6561  def  test_alternate_limits (self ):
62+     from  opendbc .car .hyundai .interface  import  CarInterface 
63+     
6664    # Alternate lateral control limits, for high torque cars, verify Panda safety mode flag is set 
6765    fingerprint  =  gen_empty_fingerprint ()
6866    for  car_model  in  CAR :
@@ -83,6 +81,8 @@ def test_hybrid_ev_sets(self):
8381    assert  CANFD_CAR  &  HYBRID_CAR  ==  set (), "Hard coding CAN FD cars as hybrid is no longer supported" 
8482
8583  def  test_canfd_ecu_whitelist (self ):
84+     from  opendbc .car .hyundai .fingerprints  import  FW_VERSIONS 
85+     
8686    # Asserts only expected Ecus can exist in database for CAN-FD cars 
8787    for  car_model  in  CANFD_CAR :
8888      ecus  =  {fw [0 ] for  fw  in  FW_VERSIONS [car_model ].keys ()}
@@ -92,6 +92,8 @@ def test_canfd_ecu_whitelist(self):
9292                       f"{ car_model } { ecu_strings }  
9393
9494  def  test_blacklisted_parts (self , subtests ):
95+     from  opendbc .car .hyundai .fingerprints  import  FW_VERSIONS 
96+     
9597    # Asserts no ECUs known to be shared across platforms exist in the database. 
9698    # Tucson having Santa Cruz camera and EPS for example 
9799    for  car_model , ecus  in  FW_VERSIONS .items ():
@@ -106,6 +108,8 @@ def test_blacklisted_parts(self, subtests):
106108          assert  not  part .startswith (b'CW' ), "Car has bad part number" 
107109
108110  def  test_correct_ecu_response_database (self , subtests ):
111+     from  opendbc .car .hyundai .fingerprints  import  FW_VERSIONS 
112+     
109113    """ 
110114    Assert standard responses for certain ECUs, since they can 
111115    respond to multiple queries with different data 
@@ -117,15 +121,22 @@ def test_correct_ecu_response_database(self, subtests):
117121          assert  all (fw .startswith (expected_fw_prefix ) for  fw  in  fws ), \
118122                          f"FW from unexpected request in database: { (ecu , fws )}  
119123
120-   @ settings ( max_examples = 100 ) 
121-   @ given ( data = st . data ()) 
122-   def   test_platform_codes_fuzzy_fw ( self ,  data ): 
124+   def   test_platform_codes_fuzzy_fw ( self ): 
125+      from   hypothesis   import   settings ,  given ,  strategies   as   st 
126+      
123127    """Ensure function doesn't raise an exception""" 
124-     fw_strategy  =  st .lists (st .binary ())
125-     fws  =  data .draw (fw_strategy )
126-     get_platform_codes (fws )
128+     @settings (max_examples = 100 ) 
129+     @given (data = st .data ()) 
130+     def  _test_impl (data ):
131+       fw_strategy  =  st .lists (st .binary ())
132+       fws  =  data .draw (fw_strategy )
133+       get_platform_codes (fws )
134+     
135+     _test_impl ()
127136
128137  def  test_expected_platform_codes (self , subtests ):
138+     from  opendbc .car .hyundai .fingerprints  import  FW_VERSIONS 
139+     
129140    # Ensures we don't accidentally add multiple platform codes for a car unless it is intentional 
130141    for  car_model , ecus  in  FW_VERSIONS .items ():
131142      with  subtests .test (car_model = car_model .value ):
@@ -145,6 +156,8 @@ def test_expected_platform_codes(self, subtests):
145156  # Tests for platform codes, part numbers, and FW dates which Hyundai will use to fuzzy 
146157  # fingerprint in the absence of full FW matches: 
147158  def  test_platform_code_ecus_available (self , subtests ):
159+     from  opendbc .car .hyundai .fingerprints  import  FW_VERSIONS 
160+     
148161    # TODO: add queries for these non-CAN FD cars to get EPS 
149162    no_eps_platforms  =  CANFD_CAR  |  {CAR .KIA_SORENTO , CAR .KIA_OPTIMA_G4 , CAR .KIA_OPTIMA_G4_FL , CAR .KIA_OPTIMA_H ,
150163                                    CAR .KIA_OPTIMA_H_G4_FL , CAR .HYUNDAI_SONATA_LF , CAR .HYUNDAI_TUCSON , CAR .GENESIS_G90 , CAR .GENESIS_G80 , CAR .HYUNDAI_ELANTRA }
@@ -160,6 +173,8 @@ def test_platform_code_ecus_available(self, subtests):
160173          assert  platform_code_ecu  in  [e [0 ] for  e  in  ecus ]
161174
162175  def  test_fw_format (self , subtests ):
176+     from  opendbc .car .hyundai .fingerprints  import  FW_VERSIONS 
177+     
163178    # Asserts: 
164179    # - every supported ECU FW version returns one platform code 
165180    # - every supported ECU FW version has a part number 
@@ -219,6 +234,9 @@ def test_platform_codes_spot_check(self):
219234                               (b"ON-S9100" , b"190405" ), (b"ON-S9100" , b"190720" )}
220235
221236  def  test_fuzzy_excluded_platforms (self ):
237+     from  opendbc .car .hyundai .fingerprints  import  FW_VERSIONS 
238+     from  opendbc .car .fw_versions  import  build_fw_dict 
239+ 
222240    # Asserts a list of platforms that will not fuzzy fingerprint with platform codes due to them being shared. 
223241    # This list can be shrunk as we combine platforms and detect features 
224242    excluded_platforms  =  {
0 commit comments