Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helper functions for query checker status #34

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions qc_baselib/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,3 +595,22 @@ 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

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
114 changes: 114 additions & 0 deletions tests/test_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,3 +920,117 @@ 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


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