26
26
(42.0 , 42 ),
27
27
('42.0' , 42 ),
28
28
('123456789.0' , 123_456_789 ),
29
- ('123456789123456.00001' , 123_456_789_123_456 ),
29
+ ('123456789123456.00001' , Err ( 'Input should be a valid integer, unable to parse string as an integer' ) ),
30
30
(int (1e10 ), int (1e10 )),
31
31
(i64_max , i64_max ),
32
32
pytest .param (
@@ -61,12 +61,18 @@ def test_int_py_and_json(py_and_json: PyAndJson, input_value, expected):
61
61
(Decimal ('1.0' ), 1 ),
62
62
(i64_max , i64_max ),
63
63
(str (i64_max ), i64_max ),
64
- # (str(i64_max + 1), i64_max + 1),
64
+ (
65
+ str (i64_max + 1 ),
66
+ Err (
67
+ "Input should be a valid integer, unable to parse string as an integer "
68
+ "[type=int_parsing, input_value='9223372036854775808', input_type=str]"
69
+ ),
70
+ ),
65
71
(
66
72
str (i64_max * 2 ),
67
73
Err (
68
- "Input integer too large to convert to 64-bit integer "
69
- "[type=int_overflow , input_value='18446744073709551614', input_type=str]"
74
+ "Input should be a valid integer, unable to parse string as an integer "
75
+ "[type=int_parsing , input_value='18446744073709551614', input_type=str]"
70
76
),
71
77
),
72
78
(i64_max + 1 , i64_max + 1 ),
@@ -87,6 +93,7 @@ def test_int_py_and_json(py_and_json: PyAndJson, input_value, expected):
87
93
id = 'tuple' ,
88
94
),
89
95
],
96
+ ids = repr ,
90
97
)
91
98
def test_int (input_value , expected ):
92
99
v = SchemaValidator ({'type' : 'int' })
@@ -350,24 +357,29 @@ def test_long_int(py_and_json: PyAndJson):
350
357
v .validate_test ('1' * 400 )
351
358
352
359
assert exc_info .value .errors (include_url = False ) == [
353
- {'type' : 'finite_number' , 'loc' : (), 'msg' : 'Input should be a finite number' , 'input' : '1' * 400 }
360
+ {
361
+ 'type' : 'int_parsing' ,
362
+ 'loc' : (),
363
+ 'msg' : 'Input should be a valid integer, unable to parse string as an integer' ,
364
+ 'input' : '1' * 400 ,
365
+ }
354
366
]
367
+ # insert_assert(repr(exc_info.value))
355
368
assert repr (exc_info .value ) == (
356
- '1 validation error for int\n '
357
- ' Input should be a finite number '
358
- '[type=finite_number, '
359
- "input_value='111111111111111111111111...11111111111111111111111', input_type=str]\n "
360
- f" For further information visit https://errors.pydantic.dev/{ __version__ } /v/finite_number"
369
+ "1 validation error for int\n "
370
+ " Input should be a valid integer, unable to parse string as an integer "
371
+ "[type=int_parsing, input_value='111111111111111111111111...11111111111111111111111', input_type=str]\n "
372
+ f" For further information visit https://errors.pydantic.dev/{ __version__ } /v/int_parsing"
361
373
)
362
374
363
375
364
376
def test_finite_number (py_and_json : PyAndJson ):
365
377
v = py_and_json ({'type' : 'int' })
366
378
367
- with pytest .raises (ValidationError , match = 'Input should be a finite number ' ):
379
+ with pytest .raises (ValidationError , match = 'Input should be a valid integer ' ):
368
380
v .validate_test ('-' + '1' * 400 )
369
381
370
- with pytest .raises (ValidationError , match = 'Input should be a finite number ' ):
382
+ with pytest .raises (ValidationError , match = 'Input should be a valid integer ' ):
371
383
v .validate_test ('nan' )
372
384
373
385
0 commit comments