@@ -898,36 +898,22 @@ def test_minItems_invalid_string(self):
898
898
899
899
900
900
class ValidatorTestMixin (MetaSchemaTestsMixin , object ):
901
- def setUp (self ):
902
- self .instance = object ()
903
- self .schema = {}
904
- self .validator = self .Validator (self .schema )
905
-
906
901
def test_valid_instances_are_valid (self ):
907
- errors = iter ([])
908
-
909
- with mock .patch .object (
910
- self .validator , "iter_errors" , return_value = errors ,
911
- ):
912
- self .assertTrue (
913
- self .validator .is_valid (self .instance , self .schema )
914
- )
902
+ schema , instance = self .valid
903
+ self .assertTrue (self .Validator (schema ).is_valid (instance ))
915
904
916
905
def test_invalid_instances_are_not_valid (self ):
917
- errors = iter ([ValidationError ("An error!" )])
918
-
919
- with mock .patch .object (
920
- self .validator , "iter_errors" , return_value = errors ,
921
- ):
922
- self .assertFalse (
923
- self .validator .is_valid (self .instance , self .schema )
924
- )
906
+ schema , instance = self .invalid
907
+ self .assertFalse (self .Validator (schema ).is_valid (instance ))
925
908
926
909
def test_non_existent_properties_are_ignored (self ):
927
910
self .Validator ({object (): object ()}).validate (instance = object ())
928
911
929
912
def test_it_creates_a_ref_resolver_if_not_provided (self ):
930
- self .assertIsInstance (self .validator .resolver , validators .RefResolver )
913
+ self .assertIsInstance (
914
+ self .Validator ({}).resolver ,
915
+ validators .RefResolver ,
916
+ )
931
917
932
918
def test_it_delegates_to_a_ref_resolver (self ):
933
919
ref , schema = "someCoolRef" , {"type" : "integer" }
@@ -957,14 +943,14 @@ def resolving(this, ref):
957
943
self .Validator (schema , resolver = resolver ).validate (None )
958
944
959
945
def test_is_type_is_true_for_valid_type (self ):
960
- self .assertTrue (self .validator .is_type ("foo" , "string" ))
946
+ self .assertTrue (self .Validator ({}) .is_type ("foo" , "string" ))
961
947
962
948
def test_is_type_is_false_for_invalid_type (self ):
963
- self .assertFalse (self .validator .is_type ("foo" , "array" ))
949
+ self .assertFalse (self .Validator ({}) .is_type ("foo" , "array" ))
964
950
965
951
def test_is_type_evades_bool_inheriting_from_int (self ):
966
- self .assertFalse (self .validator .is_type (True , "integer" ))
967
- self .assertFalse (self .validator .is_type (True , "number" ))
952
+ self .assertFalse (self .Validator ({}) .is_type (True , "integer" ))
953
+ self .assertFalse (self .Validator ({}) .is_type (True , "number" ))
968
954
969
955
@unittest .skipIf (PY3 , "In Python 3 json.load always produces unicode" )
970
956
def test_string_a_bytestring_is_a_string (self ):
@@ -1085,6 +1071,8 @@ def test_False_is_not_a_schema_even_if_you_forget_to_check(self):
1085
1071
1086
1072
class TestDraft3Validator (AntiDraft6LeakMixin , ValidatorTestMixin , TestCase ):
1087
1073
Validator = validators .Draft3Validator
1074
+ valid = {}, {}
1075
+ invalid = {"type" : "integer" }, "foo"
1088
1076
1089
1077
def test_any_type_is_valid_for_type_any (self ):
1090
1078
validator = self .Validator ({"type" : "any" })
@@ -1106,23 +1094,29 @@ def test_any_type_is_redefinable(self):
1106
1094
validator .validate ("foo" )
1107
1095
1108
1096
def test_is_type_is_true_for_any_type (self ):
1109
- self .assertTrue (self .validator .is_valid (object (), {"type" : "any" }))
1097
+ self .assertTrue (self .Validator ({}) .is_valid (object (), {"type" : "any" }))
1110
1098
1111
1099
def test_is_type_does_not_evade_bool_if_it_is_being_tested (self ):
1112
- self .assertTrue (self .validator .is_type (True , "boolean" ))
1113
- self .assertTrue (self .validator .is_valid (True , {"type" : "any" }))
1100
+ self .assertTrue (self .Validator ({}) .is_type (True , "boolean" ))
1101
+ self .assertTrue (self .Validator ({}) .is_valid (True , {"type" : "any" }))
1114
1102
1115
1103
1116
1104
class TestDraft4Validator (AntiDraft6LeakMixin , ValidatorTestMixin , TestCase ):
1117
1105
Validator = validators .Draft4Validator
1106
+ valid = {}, {}
1107
+ invalid = {"type" : "integer" }, "foo"
1118
1108
1119
1109
1120
1110
class TestDraft6Validator (ValidatorTestMixin , TestCase ):
1121
1111
Validator = validators .Draft6Validator
1112
+ valid = {}, {}
1113
+ invalid = {"type" : "integer" }, "foo"
1122
1114
1123
1115
1124
1116
class TestDraft7Validator (ValidatorTestMixin , TestCase ):
1125
1117
Validator = validators .Draft7Validator
1118
+ valid = {}, {}
1119
+ invalid = {"type" : "integer" }, "foo"
1126
1120
1127
1121
1128
1122
class TestBuiltinFormats (TestCase ):
0 commit comments