3737}
3838
3939class IntegrationTestsResultsInterpreter :
40+ """
41+ This class responsible for each non-skipped test entry:
42+ 1. Match its result with its expectation
43+ 2. If it's a mismatch, prints a red message to log with test entry id, and increment failures.
44+ 3. If it's a match, prints a green message to log with test entry id.
45+ 4. For tests that their invocation failed, the mismatch will be guaranteed.
46+
47+ """
4048 def __init__ (self , tests : list [dict ], results : list [dict ], strict_mode : bool = False ):
49+ """
50+
51+ :param tests: List of tests entries from input file
52+ :param results: List of tests results aggregated and retrieved from agent service
53+ :param strict_mode: Whether to enable strict mode matching for comparison between tests and results.
54+ """
4155 self .tests = tests
4256 self .results = results
4357 self .failures = 0
@@ -112,6 +126,13 @@ def prepare_common_result_fields(self, result: dict, result_index: int):
112126 return result_fields
113127
114128 def __match_one_result_with_test (self , test_fields : dict , result_fields : dict ) -> bool :
129+ """
130+ This method gets a test entry, and its corresponding result entry from agent,
131+ and returns whether the test succeeded or not.
132+ :param test_fields: dict containing test entry data and metadata
133+ :param result_fields: dict containing result output, data and metadata
134+ :return: True if test succeeded, and False if test failed.
135+ """
115136 (actual_result , allowed_labels , expected_label ,
116137 justification_label , test_expected_result ) = self .get_test_to_be_matched_fields (result_fields , test_fields )
117138 if test_expected_result == actual_result :
@@ -126,6 +147,13 @@ def __match_one_result_with_test(self, test_fields: dict, result_fields: dict) -
126147 return False
127148
128149 def get_test_to_be_matched_fields (self , result_fields : dict , test_fields : dict ) -> tuple [str , list , str , str , str ]:
150+ """
151+ This method extract the fields from test entry and the corresponding result entry
152+ that are important for comparison.
153+ :param result_fields: result entry fields dictionary
154+ :param test_fields: test entry fields dictionary
155+ :return: tuple containing the fields from both dicts that are required for comparison.
156+ """
129157 justification_status = result_fields .get (JUSTIFICATION_STATUS )
130158 justification_label : str = result_fields .get (JUSTIFICATION_LABEL )
131159 allowed_labels = test_fields .get (ALLOWED_DEVIATION_LABELS , [])
@@ -135,13 +163,25 @@ def get_test_to_be_matched_fields(self, result_fields: dict, test_fields: dict)
135163 return actual_result , allowed_labels , expected_label , justification_label , test_expected_result
136164
137165 def build_common_test_header (self , test_fields : dict ) -> str :
166+ """
167+ Build a printable test header for identification of a test entry
168+ :param test_fields: dict containing various test entry fields
169+ :return: a formatted string containing a printable test id that can fully identify the test entry.
170+ """
138171 test_no = test_fields .get (TEST_NO )
139172 lang = test_fields .get (LANGUAGE )
140173 cve = test_fields .get (VULN_ID )
141174 git = test_fields .get (GIT_REPO )
142175 return f'Test #{ test_no } : Language={ lang } , vuln_id={ cve } , git_repo={ git } '
143176
144177 def build_common_test_footer (self , test_fields : dict , result_fields : dict ) -> str :
178+ """
179+ This method crafts a string that containing the data relevant for test comparison for a given test case.
180+ It takes the relevant fields from test entry and its corresponding result.
181+ :param result_fields: result entry fields dictionary
182+ :param test_fields: test entry fields dictionary
183+ :return: a formatted script that fully describe the test result ( all relevant fields)
184+ """
145185 (actual_result , allowed_labels , expected_label ,
146186 justification_label , test_expected_result ) = self .get_test_to_be_matched_fields (result_fields , test_fields )
147187
0 commit comments