|
1 | 1 | import datetime |
2 | 2 | import math |
3 | 3 | import re |
| 4 | +import sys |
4 | 5 | from typing import Annotated |
5 | 6 |
|
6 | 7 | import pytest |
@@ -168,21 +169,27 @@ def test_multiple_of_bounds(self, val): |
168 | 169 | def test_nonnegative_integer_fields(self, field): |
169 | 170 | Meta(**{field: 0}) |
170 | 171 | Meta(**{field: 10}) |
| 172 | + Meta(**{field: sys.maxsize}) |
171 | 173 | with pytest.raises(TypeError, match=f"`{field}` must be an int, got float"): |
172 | 174 | Meta(**{field: 1.5}) |
173 | 175 |
|
174 | 176 | with pytest.raises(ValueError, match=f"`{field}` must be >= 0, got -1"): |
175 | 177 | Meta(**{field: -1}) |
| 178 | + with pytest.raises(ValueError, match=f"`{field}` must be >= 0, got -10"): |
| 179 | + Meta(**{field: -10}) |
| 180 | + with pytest.raises( |
| 181 | + ValueError, match=f"`{field}` must be >= 0, got {-sys.maxsize - 1}" |
| 182 | + ): |
| 183 | + Meta(**{field: -sys.maxsize - 1}) |
176 | 184 |
|
177 | 185 | @pytest.mark.parametrize("field", ["min_length", "max_length"]) |
178 | | - @pytest.mark.parametrize("val", [2**63, 10**400, -(10**400)]) |
| 186 | + @pytest.mark.parametrize( |
| 187 | + "val", [sys.maxsize + 1, -sys.maxsize - 2, 10**400, -(10**400)] |
| 188 | + ) |
179 | 189 | def test_nonnegative_integer_fields_out_of_range(self, field, val): |
180 | | - # Doesn't fit in a Py_ssize_t. The overflow must not be reported as |
181 | | - # the value being negative, which it isn't. |
| 190 | + # Values outside Py_ssize_t need a range error in either direction. |
182 | 191 | with pytest.raises(ValueError, match=f"`{field}` is out of range"): |
183 | 192 | Meta(**{field: val}) |
184 | | - with pytest.raises(ValueError, match=f"{field}` must be >= 0, got -10"): |
185 | | - Meta(**{field: -10}) |
186 | 193 |
|
187 | 194 | @pytest.mark.parametrize("field", ["pattern", "title", "description"]) |
188 | 195 | def test_string_fields(self, field): |
|
0 commit comments