-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: validate schemas in regular testing (#450)
Followup to #447 based on testing suggestion from @abravalheri. Signed-off-by: Henry Schreiner <[email protected]>
- Loading branch information
Showing
5 changed files
with
60 additions
and
16 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 |
---|---|---|
@@ -1,12 +1,63 @@ | ||
from __future__ import annotations | ||
|
||
from pathlib import Path | ||
from typing import Any | ||
|
||
import pytest | ||
|
||
from scikit_build_core._compat import tomllib | ||
from scikit_build_core.settings.skbuild_schema import ( | ||
generate_skbuild_schema, | ||
get_skbuild_schema, | ||
) | ||
|
||
DIR = Path(__file__).parent.resolve() | ||
|
||
|
||
def test_compare_schemas(): | ||
""" | ||
Should be the same. If not, run nox -s generate_schema | ||
""" | ||
|
||
assert generate_skbuild_schema() == get_skbuild_schema() | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"filepath", | ||
[ | ||
*DIR.parent.joinpath("docs/examples").glob("**/pyproject.toml"), | ||
*DIR.joinpath("packages").glob("**/pyproject.toml"), | ||
], | ||
) | ||
def test_valid_schemas_files(filepath: Path) -> None: | ||
api = pytest.importorskip("validate_pyproject.api") | ||
|
||
with filepath.open("rb") as f: | ||
example = tomllib.load(f) | ||
|
||
validator = api.Validator() | ||
assert validator(example) is not None | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"addition", [{"minimum-version": 0.3}, {"random": "not valid"}] | ||
) | ||
def test_invalid_schemas(addition: dict[str, Any]) -> None: | ||
fastjsonschema = pytest.importorskip("fastjsonschema") | ||
api = pytest.importorskip("validate_pyproject.api") | ||
|
||
example_toml = """\ | ||
[project] | ||
name = "myproj" | ||
version = "0" | ||
[tool.scikit-build] | ||
minimum-version = "0.3" | ||
""" | ||
|
||
example = tomllib.loads(example_toml) | ||
example["tool"]["scikit-build"].update(**addition) | ||
|
||
validator = api.Validator() | ||
with pytest.raises(fastjsonschema.JsonSchemaValueException): | ||
validator(example) |