@@ -155,3 +155,102 @@ def test_integer_invalid(self):
155155
156156 with pytest .raises (InvalidSchemaValue ):
157157 schema .unmarshal (value )
158+
159+
160+ class TestSchemaValidate (object ):
161+
162+ @pytest .mark .parametrize ('schema_type' , [
163+ 'boolean' , 'array' , 'integer' , 'number' , 'string' ,
164+ ])
165+ def test_null (self , schema_type ):
166+ schema = Schema (schema_type )
167+ value = None
168+
169+ with pytest .raises (InvalidSchemaValue ):
170+ schema .validate (value )
171+
172+ @pytest .mark .parametrize ('schema_type' , [
173+ 'boolean' , 'array' , 'integer' , 'number' , 'string' ,
174+ ])
175+ def test_nullable (self , schema_type ):
176+ schema = Schema (schema_type , nullable = True )
177+ value = None
178+
179+ result = schema .validate (value )
180+
181+ assert result is None
182+
183+ @pytest .mark .parametrize ('value' , [False , True ])
184+ def test_boolean (self , value ):
185+ schema = Schema ('boolean' )
186+
187+ result = schema .validate (value )
188+
189+ assert result == value
190+
191+ @pytest .mark .parametrize ('value' , [1 , 3.14 , 'true' , [True , False ]])
192+ def test_boolean_invalid (self , value ):
193+ schema = Schema ('boolean' )
194+
195+ with pytest .raises (InvalidSchemaValue ):
196+ schema .validate (value )
197+
198+ @pytest .mark .parametrize ('value' , [[1 , 2 ], (3 , 4 )])
199+ def test_array (self , value ):
200+ schema = Schema ('array' )
201+
202+ result = schema .validate (value )
203+
204+ assert result == value
205+
206+ @pytest .mark .parametrize ('value' , [False , 1 , 3.14 , 'true' ])
207+ def test_array_invalid (self , value ):
208+ schema = Schema ('array' )
209+
210+ with pytest .raises (InvalidSchemaValue ):
211+ schema .validate (value )
212+
213+ @pytest .mark .parametrize ('value' , [1 , 3 ])
214+ def test_integer (self , value ):
215+ schema = Schema ('integer' )
216+
217+ result = schema .validate (value )
218+
219+ assert result == value
220+
221+ @pytest .mark .parametrize ('value' , [False , 3.14 , 'true' , [1 , 2 ]])
222+ def test_integer_invalid (self , value ):
223+ schema = Schema ('integer' )
224+
225+ with pytest .raises (InvalidSchemaValue ):
226+ schema .validate (value )
227+
228+ @pytest .mark .parametrize ('value' , [1 , 3.14 ])
229+ def test_number (self , value ):
230+ schema = Schema ('number' )
231+
232+ result = schema .validate (value )
233+
234+ assert result == value
235+
236+ @pytest .mark .parametrize ('value' , [False , 'true' , [1 , 3 ]])
237+ def test_number_invalid (self , value ):
238+ schema = Schema ('number' )
239+
240+ with pytest .raises (InvalidSchemaValue ):
241+ schema .validate (value )
242+
243+ @pytest .mark .parametrize ('value' , ['true' , b'true' ])
244+ def test_string (self , value ):
245+ schema = Schema ('string' )
246+
247+ result = schema .validate (value )
248+
249+ assert result == value
250+
251+ @pytest .mark .parametrize ('value' , [False , 1 , 3.14 , [1 , 3 ]])
252+ def test_string_invalid (self , value ):
253+ schema = Schema ('string' )
254+
255+ with pytest .raises (InvalidSchemaValue ):
256+ schema .validate (value )
0 commit comments