% Regression tests for automotive scanner test_case + Load general modules = Load contribution layer from scapy.contrib.automotive.scanner.test_case import AutomotiveTestCase from scapy.contrib.automotive.ecu import EcuState + Basic checks = Definition of Test class class MyTestCase(AutomotiveTestCase): _description = "MyTestCase" _supported_kwargs = {"testarg": (int, None)} def supported_responses(self): return [] = Check supported kwargs try: MyTestCase.check_kwargs({"testarg": 5}) except Scapy_Exception as e: assert False try: MyTestCase.check_kwargs({"test": 5}) assert False except Scapy_Exception as e: assert "Keyword-Argument test not supported" in str(e) try: MyTestCase.check_kwargs({"testarg": 5.5}) assert False except Scapy_Exception as e: assert "Keyword-Value" in str(e) assert "is not instance of type " in str(e) or \ "is not instance of type " in str(e) = Create instance of test class mt = MyTestCase() mt._state_completed[EcuState(session=1)] = True mt._state_completed[EcuState(session=2)] = True mt._state_completed[EcuState(session=3)] = False = Tests of has_completed assert mt.completed is False assert mt.has_completed(EcuState(session=1)) assert mt.has_completed(EcuState(session=3)) is False assert len(mt.scanned_states) == 3 = Tests of has_completed with new state assert mt.completed is False assert mt.has_completed(EcuState(session=4)) is False assert mt.has_completed(EcuState(session=3)) is False assert len(mt.scanned_states) == 4 = Tests of completed mt._state_completed[EcuState(session=3)] = True mt._state_completed[EcuState(session=4)] = True assert mt.completed = Test of show header = mt._show_header(dump=True) assert "MyTestCase" in header state_info = mt._show_state_information(dump=True) assert "session" in state_info assert "False" not in state_info assert "True" in state_info mt._state_completed[EcuState(session=3)] = False state_info = mt._show_state_information(dump=True) assert "session" in state_info assert "False" in state_info assert "True" in state_info dump = mt.show(dump=True, verbose=True) assert "session" in dump assert "MyTestCase" in dump