interfaces: test interface attributes (#29301)

* test

* draft

* draft

* clean up

* clean up

* better test

* clean up

* check car info

* uncomment

* rm space

* no loop

* use dbc

* more clear

* one line
pull/29540/head
Shane Smiskol 2 years ago committed by GitHub
parent e9e0661771
commit 225ed2ed5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 27
      selfdrive/car/tests/test_car_interfaces.py

@ -11,6 +11,7 @@ from common.realtime import DT_CTRL
from selfdrive.car import gen_empty_fingerprint
from selfdrive.car.car_helpers import interfaces
from selfdrive.car.fingerprints import all_known_cars
from selfdrive.car.interfaces import get_interface_attr
from selfdrive.test.fuzzy_generation import DrawType, FuzzyGenerator
@ -109,5 +110,31 @@ class TestCarInterfaces(unittest.TestCase):
hasattr(radar_interface, '_update') and hasattr(radar_interface, 'trigger_msg'):
radar_interface._update([radar_interface.trigger_msg])
def test_interface_attrs(self):
"""Asserts basic behavior of interface attribute getter"""
num_brands = len(get_interface_attr('CAR'))
self.assertGreaterEqual(num_brands, 13)
# Should return value for all brands when not combining, even if attribute doesn't exist
ret = get_interface_attr('FAKE_ATTR')
self.assertEqual(len(ret), num_brands)
# Make sure we can combine dicts
ret = get_interface_attr('DBC', combine_brands=True)
self.assertGreaterEqual(len(ret), 170)
# We don't support combining non-dicts
ret = get_interface_attr('CAR', combine_brands=True)
self.assertEqual(len(ret), 0)
# If brand has None value, it shouldn't return when ignore_none=True is specified
none_brands = {b for b, v in get_interface_attr('FINGERPRINTS').items() if v is None}
self.assertGreaterEqual(len(none_brands), 1)
ret = get_interface_attr('FINGERPRINTS', ignore_none=True)
none_brands_in_ret = none_brands.intersection(ret)
self.assertEqual(len(none_brands_in_ret), 0, f'Brands with None values in ignore_none=True result: {none_brands_in_ret}')
if __name__ == "__main__":
unittest.main()

Loading…
Cancel
Save