|
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 | 14 | from jsonschema.validators import _LATEST_VERSION, validate
|
@@ -675,17 +675,62 @@ 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 | + |
| 694 | + self.assertOutputs( |
| 695 | + files=dict(some_schema='{"const": "check"}', some_instance='"a"'), |
| 696 | + argv=["-i", "some_instance", "some_schema"], |
| 697 | + exit_code=1, |
| 698 | + stdout="", |
| 699 | + stderr="a: 'check' was expected\n", |
| 700 | + ) |
| 701 | + |
| 702 | + def test_it_validates_using_draft7_when_specified(self): |
| 703 | + """ |
| 704 | + Specifically, `const` validation applies for Draft 7. |
| 705 | + """ |
| 706 | + schema = """ |
| 707 | + { |
| 708 | + "$schema": "http://json-schema.org/draft-07/schema#", |
| 709 | + "const": "check" |
| 710 | + } |
| 711 | + """ |
| 712 | + instance = '"foo"' |
687 | 713 | self.assertOutputs(
|
688 |
| - files=dict(some_schema='{"minimum": 30}', some_instance="37"), |
| 714 | + files=dict(some_schema=schema, some_instance=instance), |
| 715 | + argv=["-i", "some_instance", "some_schema"], |
| 716 | + exit_code=1, |
| 717 | + stdout="", |
| 718 | + stderr="foo: 'check' was expected\n", |
| 719 | + ) |
| 720 | + |
| 721 | + def test_it_validates_using_draft4_when_specified(self): |
| 722 | + """ |
| 723 | + Specifically, `const` validation *does not* apply for Draft 4. |
| 724 | + """ |
| 725 | + schema = """ |
| 726 | + { |
| 727 | + "$schema": "http://json-schema.org/draft-04/schema#", |
| 728 | + "const": "check" |
| 729 | + } |
| 730 | + """ |
| 731 | + instance = '"foo"' |
| 732 | + self.assertOutputs( |
| 733 | + files=dict(some_schema=schema, some_instance=instance), |
689 | 734 | argv=["-i", "some_instance", "some_schema"],
|
690 | 735 | stdout="",
|
691 | 736 | stderr="",
|
@@ -717,15 +762,6 @@ def test_find_validator_in_jsonschema(self):
|
717 | 762 | )
|
718 | 763 | self.assertIs(arguments["validator"], Draft4Validator)
|
719 | 764 |
|
720 |
| - def test_latest_validator_is_the_default(self): |
721 |
| - arguments = cli.parse_args( |
722 |
| - [ |
723 |
| - "--instance", "mem://some/instance", |
724 |
| - "mem://some/schema", |
725 |
| - ] |
726 |
| - ) |
727 |
| - self.assertIs(arguments["validator"], _LATEST_VERSION) |
728 |
| - |
729 | 765 | def test_unknown_output(self):
|
730 | 766 | # Avoid the help message on stdout
|
731 | 767 | with captured_output() as (stdout, stderr):
|
|
0 commit comments