Skip to content

Commit 690aa60

Browse files
committed
docs: complete code documentation
Signed-off-by: Zvi Grinberg <zgrinber@redhat.com>
1 parent 5983027 commit 690aa60

2 files changed

Lines changed: 62 additions & 4 deletions

File tree

src/concurrent_executor.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
logger = logging.getLogger(__name__)
99

1010
class ExecutionInput:
11-
11+
"""
12+
Data model for one test input being sent as request to the agent service
13+
"""
1214
def __init__(self,number : int, test: dict, payload: dict, request_id: str):
1315
self.number = number
1416
self.test = test
@@ -17,7 +19,9 @@ def __init__(self,number : int, test: dict, payload: dict, request_id: str):
1719

1820

1921
class ExecutionOutput:
20-
22+
"""
23+
Data model for one test output being received as result from the agent service
24+
"""
2125
def __init__(self, number: int, response: dict, request_id: str, test: dict) -> None:
2226
self.number = number
2327
self.response = response
@@ -26,12 +30,26 @@ def __init__(self, number: int, response: dict, request_id: str, test: dict) ->
2630
self.intercepted_error = ""
2731

2832
class ConcurrentExecutor:
33+
34+
"""
35+
Class that responsible for executing requests concurrently
36+
37+
Args:
38+
execution: the Execution instance that can send and orchestrate sending requests
39+
num_of_processes: Number of concurrent requests that will be sent at once to agent, by default, it's 2.
40+
41+
"""
2942
def __init__(self, execution: Execution, num_of_processes: int = 2):
3043

3144
self.execution = execution
3245
self.num_of_process = num_of_processes
33-
3446
def execute_one_request(self, payload_data: ExecutionInput):
47+
"""
48+
This method in charge of sending one request
49+
:param payload_data: input data containing payload of request and its metadata.
50+
:return: output object containing result from agent, or crafted output object
51+
in case error was intercepted on invocation.
52+
"""
3553
try:
3654
logger.info(f"Sending Request of test #{payload_data.number},"
3755
f"Test-id={Execution.generate_test_id(payload_data.payload)}")
@@ -57,7 +75,7 @@ def run_requests(self, execution_payloads: list[ExecutionInput]) -> list[Executi
5775
"""
5876

5977
with ThreadPoolExecutor(max_workers=self.num_of_process) as pool:
60-
78+
# Distribute the tests' requests payloads between the threads workers.
6179
results = pool.map(self.execute_one_request, execution_payloads)
6280
return list(results)
6381

src/it_results_interpreter.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,21 @@
3737
}
3838

3939
class 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

Comments
 (0)