1% Regression tests for automotive scanner configuration 2 3+ Load general modules 4 5= Load contribution layer 6 7from scapy.contrib.automotive.scanner.test_case import AutomotiveTestCase 8from scapy.contrib.automotive.scanner.configuration import AutomotiveTestCaseExecutorConfiguration 9from scapy.contrib.automotive.scanner.staged_test_case import StagedAutomotiveTestCase 10 11+ Basic checks 12 13= Definition of Test classes 14 15class MyTestCase1(AutomotiveTestCase): 16 _description = "MyTestCase1" 17 def supported_responses(self): 18 return [] 19 20 21class MyTestCase2(AutomotiveTestCase): 22 _description = "MyTestCase2" 23 def supported_responses(self): 24 return [] 25 26class MyTestCase3(AutomotiveTestCase): 27 _description = "MyTestCase3" 28 def supported_responses(self): 29 return [] 30 31class MyTestCase4(AutomotiveTestCase): 32 _description = "MyTestCase4" 33 def supported_responses(self): 34 return [] 35 36= creation of config with classes 37 38config = AutomotiveTestCaseExecutorConfiguration( 39 [MyTestCase1, MyTestCase2, MyTestCase3, MyTestCase4]) 40 41assert len(config.test_cases) == 4 42assert len(config.test_case_clss) == 4 43assert len(config.stages) == 0 44assert len(config.staged_test_cases) == 0 45assert config.verbose == False 46assert config.debug == False 47 48 49= creation of config with instances 50 51config = AutomotiveTestCaseExecutorConfiguration( 52 [MyTestCase1(), MyTestCase2(), MyTestCase3(), MyTestCase4()]) 53 54assert len(config.test_cases) == 4 55assert len(config.test_case_clss) == 4 56assert len(config.stages) == 0 57assert len(config.staged_test_cases) == 0 58assert config.verbose == False 59assert config.debug == False 60 61 62= creation of config with instances and classes 63 64config = AutomotiveTestCaseExecutorConfiguration( 65 [MyTestCase2(), MyTestCase2(), MyTestCase3, MyTestCase4]) 66 67assert len(config.test_cases) == 4 68assert len(config.test_case_clss) == 3 69assert len(config.stages) == 0 70assert len(config.staged_test_cases) == 0 71assert config.verbose == False 72assert config.debug == False 73 74 75= creation of config with instances and classes and global configuration and local configuration 76 77config = AutomotiveTestCaseExecutorConfiguration( 78 [MyTestCase2(), MyTestCase2(), MyTestCase3, MyTestCase4], 79 global_config=42, verbose=True, MyTestCase2_kwargs={"local_config": 41}) 80 81assert len(config.test_cases) == 4 82assert len(config.test_case_clss) == 3 83assert len(config.stages) == 0 84assert len(config.staged_test_cases) == 0 85assert config.verbose == True 86assert config.debug == False 87assert config["MyTestCase2"]["global_config"] == 42 88assert config["MyTestCase2"]["local_config"] == 41 89assert config["MyTestCase2"]["verbose"] == True 90try: 91 print(config["MyTestCase1"]["global_config"]) 92 raise AssertionError 93except KeyError: 94 pass 95 96assert len(config["MyTestCase3"]) == 3 97assert len(config["MyTestCase2"]) == 4 98 99try: 100 print(config["MyTestCase3"]["local_config"]) 101 raise AssertionError 102except KeyError: 103 pass 104 105 106= creation of config with stages 107 108st = StagedAutomotiveTestCase([MyTestCase1(), MyTestCase2()]) 109 110config = AutomotiveTestCaseExecutorConfiguration( 111 [MyTestCase2(), MyTestCase2, MyTestCase3, MyTestCase4, st]) 112 113assert len(config.test_cases) == 5 114assert len(config.test_case_clss) == 5 115assert len(config.stages) == 1 116assert len(config.staged_test_cases) == 2 117assert config.verbose == False 118assert config.debug == False 119assert config.staged_test_cases[0].__class__ == MyTestCase1 120assert config.staged_test_cases[1].__class__ == MyTestCase2 121assert config.stages[0].__class__ == StagedAutomotiveTestCase 122 123= creation of config with stages class 124 125class myStagedTestCase(StagedAutomotiveTestCase): 126 def __init__(self): 127 # type: () -> None 128 super(myStagedTestCase, self).__init__( 129 [MyTestCase1(), MyTestCase2()], 130 None) 131 132 133config = AutomotiveTestCaseExecutorConfiguration( 134 [MyTestCase2(), MyTestCase2, MyTestCase3, MyTestCase4, myStagedTestCase]) 135 136assert len(config.test_cases) == 5 137assert len(config.test_case_clss) == 5 138assert len(config.stages) == 1 139assert len(config.staged_test_cases) == 2 140assert config.staged_test_cases[0].__class__ == MyTestCase1 141assert config.staged_test_cases[1].__class__ == MyTestCase2 142assert config.stages[0].__class__ == myStagedTestCase 143assert config.verbose == False 144assert config.debug == False 145