-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Henry Schreiner <[email protected]>
- Loading branch information
Showing
6 changed files
with
112 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
""" | ||
Helpers for testing repo-review plugins. | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
import importlib.metadata | ||
import textwrap | ||
from typing import Any | ||
|
||
from .checks import Check, get_check_url, process_result_bool | ||
from .fixtures import apply_fixtures | ||
from .processor import Result | ||
|
||
|
||
def compute_check(name: str, /, **fixtures: Any) -> Result: | ||
""" | ||
A helper function to compute a check given fixtures, intended for testing. | ||
Currently, all fixtures are required to be passed in as keyword arguments, | ||
transitive fixtures are not supported. | ||
:param name: The name of the check to compute. | ||
:param fixtures: The fixtures to use when computing the check. | ||
:return: The computed result. | ||
.. versionadded:: 0.10.5 | ||
""" | ||
|
||
check_functions = ( | ||
ep.load() for ep in importlib.metadata.entry_points(group="repo_review.checks") | ||
) | ||
checks = { | ||
k: v | ||
for func in check_functions | ||
for k, v in apply_fixtures(fixtures, func).items() | ||
} | ||
check: Check = checks[name] | ||
completed_raw = apply_fixtures({"name": name, **fixtures}, check.check) | ||
completed = process_result_bool(completed_raw, check, name) | ||
result = None if completed is None else not completed | ||
doc = check.__doc__ or "" | ||
err_msg = completed or "" | ||
|
||
return Result( | ||
family=check.family, | ||
name=name, | ||
description=doc.format(self=check, name=name).strip(), | ||
result=result, | ||
err_msg=textwrap.dedent(err_msg), | ||
url=get_check_url(name, check), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters