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

feat: extra testing helper #203

Merged
merged 1 commit into from
Apr 21, 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 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}}
Loading