Skip to content

Commit ddc6341

Browse files
authored
Merge pull request #459 from python-jsonschema/enhance-testing
Minor testing enhancements
2 parents e31b55f + 08d04a7 commit ddc6341

File tree

7 files changed

+85
-6
lines changed

7 files changed

+85
-6
lines changed

tests/acceptance/test_custom_validator_class.py

+25
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,28 @@ def test_custom_validator_class_can_pass_when_valid(run_line, tmp_path):
147147
],
148148
)
149149
assert result.exit_code == 0 # pass
150+
151+
152+
@pytest.mark.parametrize(
153+
"add_opts",
154+
(
155+
["--builtin-schema", "vendor.github-workflows"],
156+
["--check-metaschema"],
157+
),
158+
)
159+
def test_custom_validator_class_is_incompatible_with_schema_opts(
160+
run_line, tmp_path, add_opts
161+
):
162+
doc = tmp_path / "instance.json"
163+
doc.write_text("{}")
164+
result = run_line(
165+
[
166+
"check-jsonschema",
167+
"--validator-class",
168+
"foo:MyValidator",
169+
str(doc),
170+
]
171+
+ add_opts
172+
)
173+
assert result.exit_code == 2
174+
assert "--validator-class can only be used with --schemafile" in result.stderr

tests/unit/cli/conftest.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import pytest
2+
from click.testing import CliRunner
3+
4+
5+
@pytest.fixture
6+
def runner() -> CliRunner:
7+
return CliRunner(mix_stderr=False)

tests/unit/cli/test_callbacks.py

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import click
2+
import pytest
3+
4+
from check_jsonschema.cli.warnings import deprecation_warning_callback
5+
6+
7+
@click.command("foo")
8+
@click.option(
9+
"--bar",
10+
is_flag=True,
11+
callback=deprecation_warning_callback("--bar", is_flag=True),
12+
)
13+
@click.option(
14+
"--baz",
15+
callback=deprecation_warning_callback(
16+
"--baz", append_message="Use --frob instead!"
17+
),
18+
)
19+
def mycli(bar, baz):
20+
print(bar)
21+
if baz:
22+
print(baz)
23+
24+
25+
def test_deprecation_warning_callback_on_missing_opts(runner):
26+
result = runner.invoke(mycli, [])
27+
assert result.exit_code == 0
28+
assert result.stdout == "False\n"
29+
30+
31+
def test_deprecation_warning_callback_on_flag(runner):
32+
with pytest.warns(
33+
UserWarning,
34+
match="'--bar' is deprecated and will be removed in a future release",
35+
):
36+
result = runner.invoke(mycli, ["--bar"], catch_exceptions=False)
37+
assert result.exit_code == 0, result.stdout
38+
assert result.stdout == "True\n"
39+
40+
41+
def test_deprecation_warning_callback_added_message(runner):
42+
with pytest.warns(
43+
UserWarning,
44+
match=(
45+
"'--baz' is deprecated and will be removed in a future release. "
46+
"Use --frob instead!"
47+
),
48+
):
49+
result = runner.invoke(mycli, ["--baz", "ok"], catch_exceptions=False)
50+
assert result.exit_code == 0, result.stdout
51+
assert result.stdout == "False\nok\n"

tests/unit/test_cli_parse.py renamed to tests/unit/cli/test_parse.py

-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import click
66
import pytest
7-
from click.testing import CliRunner
87

98
from check_jsonschema import main as cli_main
109
from check_jsonschema.cli.parse_result import ParseResult, SchemaLoadingMode
@@ -43,11 +42,6 @@ def get_ctx(*args):
4342
yield m
4443

4544

46-
@pytest.fixture
47-
def runner() -> CliRunner:
48-
return CliRunner(mix_stderr=False)
49-
50-
5145
@pytest.mark.parametrize(
5246
"schemafile,builtin_schema,check_metaschema,expect_mode",
5347
[

tests/unit/formats/test_rfc3339.py

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def test_simple_positive_cases(datestr):
2222
@pytest.mark.parametrize(
2323
"datestr",
2424
(
25+
object(),
2526
"2018-12-31T23:59:59",
2627
"2018-12-31T23:59:59+00:00Z",
2728
"2018-12-31 23:59:59",

tests/unit/formats/test_time.py

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def test_simple_positive_cases(timestr):
2121
@pytest.mark.parametrize(
2222
"timestr",
2323
(
24+
object(),
2425
"12:34:56",
2526
"23:59:60Z",
2627
"23:59:59+24:00",

0 commit comments

Comments
 (0)