Skip to content

Commit

Permalink
fix: support multiple tools, add test
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii committed Nov 20, 2023
1 parent 704cc9d commit 13ea848
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/validate_pyproject/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,8 @@ def critical_logging():
),
"tool": dict(
flags=("-t", "--tool"),
nargs="+",
action="append",
dest="tool",
default=(),
help="External tools file/url(s) to load, of the form name=URL#path",
),
}
Expand Down Expand Up @@ -155,6 +154,7 @@ def parse_args(
enabled = params.pop("enable", ())
disabled = params.pop("disable", ())
params["plugins"] = select_plugins(plugins, enabled, disabled)
params["tool"] = params["tool"] or []
return params_class(**params) # type: ignore[call-overload]


Expand Down
3 changes: 1 addition & 2 deletions src/validate_pyproject/pre_compile/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ def JSON_dict(name: str, value: str):
),
"tool": dict(
flags=("-t", "--tool"),
nargs="+",
action="append",
dest="tool",
default=(),
help="External tools file/url(s) to load, of the form name=URL#path",
),
}
Expand Down
9 changes: 9 additions & 0 deletions tests/examples/localtool/localtool.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$id": "https://simple-id.example",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"one": { "type": "integer" }
},
"additionalProperties": false
}
15 changes: 15 additions & 0 deletions tests/examples/localtool/nestedtool.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$id": "http://nested-id.example",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"nestedtool": {
"type": "object",
"properties": {
"two": { "type": "integer" }
},
"additionalProperties": false
}
},
"additionalProperties": false
}
6 changes: 6 additions & 0 deletions tests/examples/localtool/test_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"tools": {
"localtool": "tests/examples/localtool/localtool.schema.json",
"nestedtool": "tests/examples/localtool/nestedtool.schema.json#/properties/nestedtool"
}
}
5 changes: 5 additions & 0 deletions tests/examples/localtool/working.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[tool.localtool]
one = 1

[tool.nestedtool]
two = 2
1 change: 1 addition & 0 deletions tests/invalid-examples/localtool/fail1.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`tool.localtool.one` must be integer
2 changes: 2 additions & 0 deletions tests/invalid-examples/localtool/fail1.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tool.localtool]
one = "one"
1 change: 1 addition & 0 deletions tests/invalid-examples/localtool/fail2.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`tool.nestedtool.two` must be integer
2 changes: 2 additions & 0 deletions tests/invalid-examples/localtool/fail2.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tool.nestedtool]
two = "two"
6 changes: 6 additions & 0 deletions tests/invalid-examples/localtool/test_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"tools": {
"localtool": "tests/examples/localtool/localtool.schema.json",
"nestedtool": "tests/examples/localtool/nestedtool.schema.json#/properties/nestedtool"
}
}
11 changes: 10 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import pytest
from fastjsonschema import JsonSchemaValueException

from validate_pyproject import cli, plugins
from validate_pyproject import cli, errors, plugins


class TestHelp:
Expand Down Expand Up @@ -181,6 +181,15 @@ def test_multiple_files(tmp_path, capsys):
assert number_invalid == N + 3


def test_missing_toolname(tmp_path, capsys):
example = write_example(tmp_path, name="valid-pyproject.toml")
with pytest.raises(
errors.URLMissingTool,
match=r"Correct form is '--tool=<tool-name>=http://json\.schemastore\.org/poetry\.toml', with an optional",
):
cli.run(["--tool=http://json.schemastore.org/poetry.toml", str(example)])


@pytest.mark.skipif(sys.version_info[:2] < (3, 11), reason="requires 3.11+")
def test_parser_is_tomllib():
"""Make sure Python >= 3.11 uses tomllib instead of tomli"""
Expand Down

0 comments on commit 13ea848

Please sign in to comment.