diff --git a/src/repo_review/testing.py b/src/repo_review/testing.py index 86cca34..c756aef 100644 --- a/src/repo_review/testing.py +++ b/src/repo_review/testing.py @@ -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: """ diff --git a/tests/test_package.py b/tests/test_package.py index ba00580..8620915 100644 --- a/tests/test_package.py +++ b/tests/test_package.py @@ -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}}