Skip to content

Commit

Permalink
Fix an issue in copy_param_from_config (#42)
Browse files Browse the repository at this point in the history
Signed-off-by: hoangtungdinh <[email protected]>
Co-authored-by: hoangtungdinh <[email protected]>
  • Loading branch information
hoangtungdinh and hoangtungdinh authored Sep 26, 2024
1 parent bfed12f commit d9b0540
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
24 changes: 19 additions & 5 deletions qc_baselib/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,9 @@ def add_checker_summary(
else:
checker.summary += f" {content}"

def _get_checker_bundle(self, checker_bundle_name: str) -> result.CheckerBundleType:
def _get_checker_bundle_without_error(
self, checker_bundle_name: str
) -> Union[None, result.CheckerBundleType]:
if self._report_results is None:
raise RuntimeError(
"Report not initialized. Initialize the report first by registering the version or a checker bundle."
Expand All @@ -264,16 +266,21 @@ def _get_checker_bundle(self, checker_bundle_name: str) -> result.CheckerBundleT
None,
)

return bundle

def _get_checker_bundle(self, checker_bundle_name: str) -> result.CheckerBundleType:
bundle = self._get_checker_bundle_without_error(checker_bundle_name)

if bundle is None:
raise RuntimeError(
f"Bundle not found. The specified {checker_bundle_name} does not exist on the report. Register the bundle first."
)

return bundle

def _get_checker(
def _get_checker_without_error(
self, bundle: result.CheckerBundleType, checker_id: str
) -> result.CheckerType:
) -> Union[None, result.CheckerType]:
checker = next(
(
checker
Expand All @@ -283,6 +290,13 @@ def _get_checker(
None,
)

return checker

def _get_checker(
self, bundle: result.CheckerBundleType, checker_id: str
) -> result.CheckerType:
checker = self._get_checker_without_error(bundle, checker_id)

if checker is None:
raise RuntimeError(
f"Checker not found. The specified {checker_id} does not exist on the report. Register the checker first."
Expand Down Expand Up @@ -814,7 +828,7 @@ def copy_param_from_config(self, config: Configuration) -> None:

# Copy Configuration checker bundle and checker parameters to Result
for config_bundle in config.get_all_checker_bundles():
result_bundle = self._get_checker_bundle(
result_bundle = self._get_checker_bundle_without_error(
checker_bundle_name=config_bundle.application
)

Expand All @@ -827,7 +841,7 @@ def copy_param_from_config(self, config: Configuration) -> None:
)

for config_checker in config_bundle.checkers:
result_checker = self._get_checker(
result_checker = self._get_checker_without_error(
bundle=result_bundle,
checker_id=config_checker.checker_id,
)
Expand Down
15 changes: 15 additions & 0 deletions tests/test_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,21 @@ def test_result_config_param_copy() -> None:
value=2.0,
)

config.register_checker(
checker_bundle_name="TestCheckerBundle",
checker_id="FirstNonExistingTestChecker",
min_level=IssueSeverity.INFORMATION,
max_level=IssueSeverity.ERROR,
)

config.register_checker_bundle(checker_bundle_name="NonExistingTestCheckerBundle")
config.register_checker(
checker_bundle_name="NonExistingTestCheckerBundle",
checker_id="SecondNonExistingTestChecker",
min_level=IssueSeverity.INFORMATION,
max_level=IssueSeverity.ERROR,
)

result = Result()
result.register_checker_bundle(
build_date="",
Expand Down

0 comments on commit d9b0540

Please sign in to comment.