From 1e4ec8bd43a5a935d39dd9b33289e915ee3ce99e Mon Sep 17 00:00:00 2001 From: hoangtungdinh <11166240+hoangtungdinh@users.noreply.github.com> Date: Wed, 11 Sep 2024 11:48:09 +0200 Subject: [PATCH 1/2] Add get checker status function Signed-off-by: hoangtungdinh <11166240+hoangtungdinh@users.noreply.github.com> --- qc_baselib/result.py | 11 +++++++++++ tests/test_result.py | 45 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/qc_baselib/result.py b/qc_baselib/result.py index ed0fe8b..8f57253 100644 --- a/qc_baselib/result.py +++ b/qc_baselib/result.py @@ -595,3 +595,14 @@ def all_checkers_completed_without_issue(self, check_id_set: Set[str]) -> bool: result = result and checker_result return result + + def get_checker_status(self, checker_id: str) -> Union[None, StatusType]: + """ + Return None if the checker is not found. + """ + for bundle in self._report_results.checker_bundles: + for checker in bundle.checkers: + if checker.checker_id == checker_id: + return checker.status + + return None diff --git a/tests/test_result.py b/tests/test_result.py index 5350131..ad7163d 100644 --- a/tests/test_result.py +++ b/tests/test_result.py @@ -920,3 +920,48 @@ def test_registration_without_summary() -> None: ) assert True + + +def test_get_checker_status() -> None: + result_report = Result() + + result_report.register_checker_bundle( + name="TestBundle", + build_date="2024-05-31", + description="Example checker bundle", + version="0.0.1", + ) + + assert result_report.get_checker_status("TestChecker") == None + + result_report.register_checker( + checker_bundle_name="TestBundle", + checker_id="TestChecker", + description="", + ) + + assert result_report.get_checker_status("TestChecker") == None + + result_report.set_checker_status( + checker_bundle_name="TestBundle", + checker_id="TestChecker", + status=StatusType.COMPLETED, + ) + + assert result_report.get_checker_status("TestChecker") == StatusType.COMPLETED + + result_report.set_checker_status( + checker_bundle_name="TestBundle", + checker_id="TestChecker", + status=StatusType.SKIPPED, + ) + + assert result_report.get_checker_status("TestChecker") == StatusType.SKIPPED + + result_report.set_checker_status( + checker_bundle_name="TestBundle", + checker_id="TestChecker", + status=StatusType.ERROR, + ) + + assert result_report.get_checker_status("TestChecker") == StatusType.ERROR From 28b597ca0f5fd8293153bf133fe7664dc187036f Mon Sep 17 00:00:00 2001 From: hoangtungdinh <11166240+hoangtungdinh@users.noreply.github.com> Date: Wed, 11 Sep 2024 12:24:32 +0200 Subject: [PATCH 2/2] Add function to check if all checkers are completed Signed-off-by: hoangtungdinh <11166240+hoangtungdinh@users.noreply.github.com> --- qc_baselib/result.py | 8 +++++ tests/test_result.py | 69 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/qc_baselib/result.py b/qc_baselib/result.py index 8f57253..714d0c2 100644 --- a/qc_baselib/result.py +++ b/qc_baselib/result.py @@ -606,3 +606,11 @@ def get_checker_status(self, checker_id: str) -> Union[None, StatusType]: return checker.status return None + + def all_checkers_completed(self) -> bool: + for bundle in self._report_results.checker_bundles: + for checker in bundle.checkers: + if checker.status != StatusType.COMPLETED: + return False + + return True diff --git a/tests/test_result.py b/tests/test_result.py index ad7163d..b3a8f77 100644 --- a/tests/test_result.py +++ b/tests/test_result.py @@ -965,3 +965,72 @@ def test_get_checker_status() -> None: ) assert result_report.get_checker_status("TestChecker") == StatusType.ERROR + + +def test_all_checkers_completed() -> None: + result_report = Result() + + result_report.register_checker_bundle( + name="TestBundle", + build_date="2024-05-31", + description="Example checker bundle", + version="0.0.1", + ) + + assert result_report.all_checkers_completed() == True + + result_report.register_checker( + checker_bundle_name="TestBundle", + checker_id="TestChecker", + description="", + ) + + assert result_report.all_checkers_completed() == False + + result_report.set_checker_status( + checker_bundle_name="TestBundle", + checker_id="TestChecker", + status=StatusType.COMPLETED, + ) + + assert result_report.all_checkers_completed() == True + + result_report.set_checker_status( + checker_bundle_name="TestBundle", + checker_id="TestChecker", + status=StatusType.SKIPPED, + ) + + assert result_report.all_checkers_completed() == False + + result_report.set_checker_status( + checker_bundle_name="TestBundle", + checker_id="TestChecker", + status=StatusType.ERROR, + ) + + assert result_report.all_checkers_completed() == False + + result_report.register_checker( + checker_bundle_name="TestBundle", + checker_id="SecondTestChecker", + description="", + ) + + assert result_report.all_checkers_completed() == False + + result_report.set_checker_status( + checker_bundle_name="TestBundle", + checker_id="TestChecker", + status=StatusType.COMPLETED, + ) + + assert result_report.all_checkers_completed() == False + + result_report.set_checker_status( + checker_bundle_name="TestBundle", + checker_id="SecondTestChecker", + status=StatusType.COMPLETED, + ) + + assert result_report.all_checkers_completed() == True