@@ -38,29 +38,6 @@ def test_list():
3838 assert v .validate_json (b'[[1, 2], [3,' , allow_partial = True ) == [(1 , 2 )]
3939
4040
41- def test_list_partial_nested ():
42- v = SchemaValidator (
43- core_schema .tuple_positional_schema (
44- [core_schema .int_schema (), core_schema .list_schema (core_schema .int_schema ())]
45- ),
46- )
47- assert v .validate_python ([1 , [2 , 3 ]]) == (1 , [2 , 3 ])
48- assert v .validate_python ([1 , [2 , 3 ]], allow_partial = True ) == (1 , [2 , 3 ])
49- with pytest .raises (ValidationError ) as exc_info :
50- v .validate_python ((1 , [2 , 3 , 'x' ]))
51- assert exc_info .value .errors (include_url = False ) == snapshot (
52- [
53- {
54- 'type' : 'int_parsing' ,
55- 'loc' : (1 , 2 ),
56- 'msg' : 'Input should be a valid integer, unable to parse string as an integer' ,
57- 'input' : 'x' ,
58- }
59- ]
60- )
61- assert v .validate_python ((1 , [2 , 3 , 'x' ]), allow_partial = True ) == (1 , [2 , 3 ])
62-
63-
6441@pytest .mark .parametrize ('collection_type' , [core_schema .set_schema , core_schema .frozenset_schema ])
6542def test_set_frozenset (collection_type ):
6643 v = SchemaValidator (
@@ -253,3 +230,17 @@ def test_double_nested():
253230 for i in range (1 , len (json )):
254231 value = v .validate_json (json [:i ], allow_partial = True )
255232 assert isinstance (value , dict )
233+
234+
235+ def test_tuple_list ():
236+ """Tuples don't support partial, so behaviour should be disabled."""
237+ v = SchemaValidator (
238+ core_schema .tuple_positional_schema (
239+ [core_schema .list_schema (core_schema .int_schema ()), core_schema .int_schema ()]
240+ ),
241+ )
242+ assert v .validate_python ([['1' , '2' ], '3' ], allow_partial = True ) == snapshot (([1 , 2 ], 3 ))
243+ with pytest .raises (ValidationError , match = r'1\s+Input should be a valid integer' ):
244+ v .validate_python ([['1' , '2' ], 'x' ], allow_partial = True )
245+ with pytest .raises (ValidationError , match = r'0\.1\s+Input should be a valid integer' ):
246+ v .validate_python ([['1' , 'x' ], '2' ], allow_partial = True )
0 commit comments