Skip to content

Commit

Permalink
feat: extra testing helper (#203)
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii authored Apr 21, 2024
1 parent 8c66db1 commit df151f1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/repo_review/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,29 @@
import textwrap
from typing import Any

from ._compat import tomllib
from .checks import Check, get_check_url, process_result_bool
from .fixtures import apply_fixtures
from .processor import Result

__all__ = ["toml_loads", "compute_check"]


def __dir__() -> list[str]:
return __all__


def toml_loads(contents: str, /) -> Any:
"""
A helper function to quickly load a TOML string for Python 3.10+.
:param contents: The TOML string to load.
:return: The loaded TOML.
.. versionadded:: 0.10.6
"""
return tomllib.loads(contents)


def compute_check(name: str, /, **fixtures: Any) -> Result:
"""
Expand Down
5 changes: 5 additions & 0 deletions tests/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,8 @@ def test_testing_function():

assert repo_review.testing.compute_check("RF001", ruff={}).result
assert not repo_review.testing.compute_check("RF001", ruff=None).result


def test_toml_function():
pyproject = repo_review.testing.toml_loads("one.two = 3")
assert pyproject == {"one": {"two": 3}}

0 comments on commit df151f1

Please sign in to comment.