|
8 | 8 | import subprocess |
9 | 9 | import sys |
10 | 10 |
|
11 | | -from jsonschema import Draft4Validator, __version__, cli |
| 11 | +from jsonschema import Draft4Validator, Draft7Validator, __version__, cli |
12 | 12 | from jsonschema.exceptions import SchemaError, ValidationError |
13 | 13 | 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 |
15 | 15 |
|
16 | 16 |
|
17 | 17 | def fake_validator(*errors): |
@@ -675,20 +675,28 @@ def test_successful_validation_of_just_the_schema(self): |
675 | 675 | stderr="", |
676 | 676 | ) |
677 | 677 |
|
678 | | - def test_successful_validation__of_just_the_schema_pretty_output(self): |
| 678 | + def test_successful_validation_of_just_the_schema_pretty_output(self): |
679 | 679 | self.assertOutputs( |
680 | 680 | files=dict(some_schema="{}", some_instance="{}"), |
681 | 681 | argv=["--output", "pretty", "-i", "some_instance", "some_schema"], |
682 | 682 | stdout="===[SUCCESS]===(some_instance)===\n", |
683 | 683 | stderr="", |
684 | 684 | ) |
685 | 685 |
|
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 | + |
687 | 694 | self.assertOutputs( |
688 | | - files=dict(some_schema='{"minimum": 30}', some_instance="37"), |
| 695 | + files=dict(some_schema='{"const": "check"}', some_instance='"a"'), |
689 | 696 | argv=["-i", "some_instance", "some_schema"], |
| 697 | + exit_code=1, |
690 | 698 | stdout="", |
691 | | - stderr="", |
| 699 | + stderr="a: 'check' was expected\n", |
692 | 700 | ) |
693 | 701 |
|
694 | 702 | def test_it_validates_using_draft7_when_specified(self): |
@@ -719,7 +727,7 @@ def test_it_validates_using_draft4_when_specified(self): |
719 | 727 | "$schema": "http://json-schema.org/draft-04/schema#", |
720 | 728 | "const": "check" |
721 | 729 | } |
722 | | - """ |
| 730 | + """ |
723 | 731 | instance = '"foo"' |
724 | 732 | self.assertOutputs( |
725 | 733 | files=dict(some_schema=schema, some_instance=instance), |
@@ -754,16 +762,6 @@ def test_find_validator_in_jsonschema(self): |
754 | 762 | ) |
755 | 763 | self.assertIs(arguments["validator"], Draft4Validator) |
756 | 764 |
|
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 | | - |
767 | 765 | def test_unknown_output(self): |
768 | 766 | # Avoid the help message on stdout |
769 | 767 | with captured_output() as (stdout, stderr): |
|
0 commit comments