Skip to content

Commit

Permalink
tests: use most recent repo-review in testing (#414)
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii authored Apr 22, 2024
1 parent e0440e0 commit a168566
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ repos:
- click
- markdown-it-py
- pytest
- repo-review
- repo-review>=0.10.6
- rich
- tomli
- types-PyYAML
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dynamic = ["version", "readme"]
dependencies = [
"pyyaml",
"repo-review",
"tomli; python_version<'3.11'",
]

[project.optional-dependencies]
Expand All @@ -40,7 +41,7 @@ cli = [
]
test = [
"pytest >=7",
"repo-review >=0.10.5",
"repo-review >=0.10.6",
]
dev = [
"pytest >=7",
Expand Down
47 changes: 23 additions & 24 deletions tests/test_pyproject.py
Original file line number Diff line number Diff line change
@@ -1,95 +1,94 @@
from sp_repo_review._compat import tomllib
from sp_repo_review.checks import pyproject
from repo_review.testing import compute_check, toml_loads


def test_PP002_okay():
toml = tomllib.loads("""
toml = toml_loads("""
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
""")
assert pyproject.PP002.check(toml)
assert compute_check("PP002", pyproject=toml).result


def test_PP002_not_list():
toml = tomllib.loads("""
toml = toml_loads("""
[build-system]
requires = "setuptools"
build-backend = "setuptools.build_meta"
""")
assert not pyproject.PP002.check(toml)
assert not compute_check("PP002", pyproject=toml).result


def test_PP002_missing():
toml = tomllib.loads("""
toml = toml_loads("""
[project]
name = "hi"
version = "1.0.0"
""")
assert not pyproject.PP002.check(toml)
assert not compute_check("PP002", pyproject=toml).result


def test_PP003_no_wheel():
toml = tomllib.loads("""
toml = toml_loads("""
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
""")
assert pyproject.PP003.check(toml)
assert compute_check("PP003", pyproject=toml).result


def test_PP003_has_wheel():
toml = tomllib.loads("""
toml = toml_loads("""
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
""")
assert not pyproject.PP003.check(toml)
assert not compute_check("PP003", pyproject=toml).result


def test_PP302_okay_intstr():
toml = tomllib.loads("""
toml = toml_loads("""
[tool.pytest.ini_options]
minversion = "7"
""")
assert pyproject.PP302.check(toml)
assert compute_check("PP302", pyproject=toml).result


def test_PP302_okay_verstr():
toml = tomllib.loads("""
toml = toml_loads("""
[tool.pytest.ini_options]
minversion = "7.0.2"
""")
assert pyproject.PP302.check(toml)
assert compute_check("PP302", pyproject=toml).result


def test_PP302_okay_rawint():
toml = tomllib.loads("""
toml = toml_loads("""
[tool.pytest.ini_options]
minversion = 7
""")
assert pyproject.PP302.check(toml)
assert compute_check("PP302", pyproject=toml).result


def test_PP302_okay_rawfloat():
toml = tomllib.loads("""
toml = toml_loads("""
[tool.pytest.ini_options]
minversion = 7.0
""")
assert pyproject.PP302.check(toml)
assert compute_check("PP302", pyproject=toml).result


def test_PP302_missing():
toml = tomllib.loads("""
toml = toml_loads("""
[tool.pytest]
ini_options = {}
""")
assert not pyproject.PP302.check(toml)
assert not compute_check("PP302", pyproject=toml).result


def test_PP302_too_low():
toml = tomllib.loads("""
toml = toml_loads("""
[tool.pytest.ini_options]
minversion = "5"
""")
assert not pyproject.PP302.check(toml)
assert not compute_check("PP302", pyproject=toml).result
22 changes: 12 additions & 10 deletions tests/test_ruff.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
from sp_repo_review._compat import tomllib
from sp_repo_review.checks import ruff
from repo_review.testing import compute_check, toml_loads


def test_rf003_with_rp():
toml = tomllib.loads("""
toml = toml_loads("""
project.requires-python = ">=3.12"
tool.ruff.anything = "1"
""")
assert ruff.RF002.check(toml, toml["tool"]["ruff"])
assert compute_check("RF002", pyproject=toml, ruff=toml["tool"]["ruff"]).result


def test_rf003_no_rp():
toml = tomllib.loads("""
toml = toml_loads("""
project.name = "hi"
tool.ruff.target-version = "3.12"
""")
assert ruff.RF002.check(toml, toml["tool"]["ruff"])
assert compute_check("RF002", pyproject=toml, ruff=toml["tool"]["ruff"]).result


def test_rf003_both():
toml = tomllib.loads("""
toml = toml_loads("""
project.requires-python = ">=3.12"
tool.ruff.target-version = "3.12"
""")
assert isinstance(ruff.RF002.check(toml, toml["tool"]["ruff"]), str)
check_result = compute_check("RF002", pyproject=toml, ruff=toml["tool"]["ruff"])
assert check_result.result is False


def test_rf003_split_ok():
toml = tomllib.loads("""
toml = toml_loads("""
project.requires-python = ">=3.12"
""")
assert ruff.RF002.check(toml, {"target-version": "3.12"})
assert compute_check(
"RF002", pyproject=toml, ruff={"target-version": "3.12"}
).result

0 comments on commit a168566

Please sign in to comment.