Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9c6c79a

Browse files
committed
Move the latest validator CLI test to where it must go now.
Checking that validator_for works correctly was not the intention of that test. For now, that means we need a guard to ensure we test a validator that only would work if the latest version was used. We can clean that up later. Also remove test_real_validator, since there's now 3 different tests using real validators.
1 parent 32b4de4 commit 9c6c79a

1 file changed

Lines changed: 15 additions & 17 deletions

File tree

jsonschema/tests/test_cli.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
import subprocess
99
import sys
1010

11-
from jsonschema import Draft4Validator, __version__, cli
11+
from jsonschema import Draft4Validator, Draft7Validator, __version__, cli
1212
from jsonschema.exceptions import SchemaError, ValidationError
1313
from jsonschema.tests._helpers import captured_output
14-
from jsonschema.validators import _LATEST_VERSION, validate, validator_for
14+
from jsonschema.validators import _LATEST_VERSION, validate
1515

1616

1717
def fake_validator(*errors):
@@ -675,20 +675,28 @@ def test_successful_validation_of_just_the_schema(self):
675675
stderr="",
676676
)
677677

678-
def test_successful_validation__of_just_the_schema_pretty_output(self):
678+
def test_successful_validation_of_just_the_schema_pretty_output(self):
679679
self.assertOutputs(
680680
files=dict(some_schema="{}", some_instance="{}"),
681681
argv=["--output", "pretty", "-i", "some_instance", "some_schema"],
682682
stdout="===[SUCCESS]===(some_instance)===\n",
683683
stderr="",
684684
)
685685

686-
def test_real_validator(self):
686+
def test_it_validates_using_the_latest_validator_when_unspecified(self):
687+
# There isn't a better way now I can think of to ensure that the
688+
# latest version was used, given that the call to validator_for
689+
# is hidden inside the CLI, so guard that that's the case, and
690+
# this test will have to be updated when versions change until
691+
# we can think of a better way to ensure this behavior.
692+
self.assertIs(Draft7Validator, _LATEST_VERSION)
693+
687694
self.assertOutputs(
688-
files=dict(some_schema='{"minimum": 30}', some_instance="37"),
695+
files=dict(some_schema='{"const": "check"}', some_instance='"a"'),
689696
argv=["-i", "some_instance", "some_schema"],
697+
exit_code=1,
690698
stdout="",
691-
stderr="",
699+
stderr="a: 'check' was expected\n",
692700
)
693701

694702
def test_it_validates_using_draft7_when_specified(self):
@@ -719,7 +727,7 @@ def test_it_validates_using_draft4_when_specified(self):
719727
"$schema": "http://json-schema.org/draft-04/schema#",
720728
"const": "check"
721729
}
722-
"""
730+
"""
723731
instance = '"foo"'
724732
self.assertOutputs(
725733
files=dict(some_schema=schema, some_instance=instance),
@@ -754,16 +762,6 @@ def test_find_validator_in_jsonschema(self):
754762
)
755763
self.assertIs(arguments["validator"], Draft4Validator)
756764

757-
def test_latest_validator_is_the_default(self):
758-
arguments = cli.parse_args(
759-
[
760-
"--instance", "mem://some/instance",
761-
"mem://some/schema",
762-
]
763-
)
764-
arguments["validator"] = validator_for(arguments["schema"])
765-
self.assertIs(arguments["validator"], _LATEST_VERSION)
766-
767765
def test_unknown_output(self):
768766
# Avoid the help message on stdout
769767
with captured_output() as (stdout, stderr):

0 commit comments

Comments
 (0)