summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Berman <Julian@GrayVines.com>2020-08-26 09:03:10 -0400
committerJulian Berman <Julian@GrayVines.com>2020-08-26 09:03:36 -0400
commit9c6c79a60deb48424052ba68550ec081a4e64bd0 (patch)
tree302655d418cba9bc698b42f21c1b828f09fc3724
parent32b4de4810ebafdb5f28a21c3aabd29b9e2d1880 (diff)
downloadjsonschema-9c6c79a60deb48424052ba68550ec081a4e64bd0.tar.gz
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.
-rw-r--r--jsonschema/tests/test_cli.py32
1 files changed, 15 insertions, 17 deletions
diff --git a/jsonschema/tests/test_cli.py b/jsonschema/tests/test_cli.py
index 12c21a3..4216759 100644
--- a/jsonschema/tests/test_cli.py
+++ b/jsonschema/tests/test_cli.py
@@ -8,10 +8,10 @@ import os
import subprocess
import sys
-from jsonschema import Draft4Validator, __version__, cli
+from jsonschema import Draft4Validator, Draft7Validator, __version__, cli
from jsonschema.exceptions import SchemaError, ValidationError
from jsonschema.tests._helpers import captured_output
-from jsonschema.validators import _LATEST_VERSION, validate, validator_for
+from jsonschema.validators import _LATEST_VERSION, validate
def fake_validator(*errors):
@@ -675,7 +675,7 @@ class TestCLI(TestCase):
stderr="",
)
- def test_successful_validation__of_just_the_schema_pretty_output(self):
+ def test_successful_validation_of_just_the_schema_pretty_output(self):
self.assertOutputs(
files=dict(some_schema="{}", some_instance="{}"),
argv=["--output", "pretty", "-i", "some_instance", "some_schema"],
@@ -683,12 +683,20 @@ class TestCLI(TestCase):
stderr="",
)
- def test_real_validator(self):
+ def test_it_validates_using_the_latest_validator_when_unspecified(self):
+ # There isn't a better way now I can think of to ensure that the
+ # latest version was used, given that the call to validator_for
+ # is hidden inside the CLI, so guard that that's the case, and
+ # this test will have to be updated when versions change until
+ # we can think of a better way to ensure this behavior.
+ self.assertIs(Draft7Validator, _LATEST_VERSION)
+
self.assertOutputs(
- files=dict(some_schema='{"minimum": 30}', some_instance="37"),
+ files=dict(some_schema='{"const": "check"}', some_instance='"a"'),
argv=["-i", "some_instance", "some_schema"],
+ exit_code=1,
stdout="",
- stderr="",
+ stderr="a: 'check' was expected\n",
)
def test_it_validates_using_draft7_when_specified(self):
@@ -719,7 +727,7 @@ class TestCLI(TestCase):
"$schema": "http://json-schema.org/draft-04/schema#",
"const": "check"
}
- """
+ """
instance = '"foo"'
self.assertOutputs(
files=dict(some_schema=schema, some_instance=instance),
@@ -754,16 +762,6 @@ class TestParser(TestCase):
)
self.assertIs(arguments["validator"], Draft4Validator)
- def test_latest_validator_is_the_default(self):
- arguments = cli.parse_args(
- [
- "--instance", "mem://some/instance",
- "mem://some/schema",
- ]
- )
- arguments["validator"] = validator_for(arguments["schema"])
- self.assertIs(arguments["validator"], _LATEST_VERSION)
-
def test_unknown_output(self):
# Avoid the help message on stdout
with captured_output() as (stdout, stderr):