|
2 | 2 | Numerous benchmarks of specific functionality.
|
3 | 3 | """
|
4 | 4 | import json
|
5 |
| -import platform |
6 |
| -import sys |
7 | 5 | from datetime import date, datetime, timedelta, timezone
|
8 | 6 | from decimal import Decimal
|
9 | 7 | from enum import Enum
|
|
16 | 14 | from pydantic_core import ArgsKwargs, PydanticCustomError, SchemaValidator, ValidationError, core_schema
|
17 | 15 | from pydantic_core import ValidationError as CoreValidationError
|
18 | 16 |
|
19 |
| -skip_pypy_deep_stack = pytest.mark.skipif( |
20 |
| - platform.python_implementation() == 'PyPy' and pydantic_core._pydantic_core.build_profile == 'debug', |
21 |
| - reason='PyPy does not have enough stack space for Rust debug builds to recurse very deep', |
22 |
| -) |
23 |
| - |
24 |
| -skip_wasm_deep_stack = pytest.mark.skipif( |
25 |
| - sys.platform == 'emscripten', reason='wasm does not have enough stack space to recurse very deep' |
26 |
| -) |
27 |
| - |
28 | 17 |
|
29 | 18 | class TestBenchmarkSimpleModel:
|
30 | 19 | @pytest.fixture(scope='class')
|
@@ -274,14 +263,12 @@ def definition_model_data():
|
274 | 263 | data = {'width': -1}
|
275 | 264 |
|
276 | 265 | _data = data
|
277 |
| - for i in range(100): |
| 266 | + for i in range(pydantic_core._pydantic_core._recursion_limit - 2): |
278 | 267 | _data['branch'] = {'width': i}
|
279 | 268 | _data = _data['branch']
|
280 | 269 | return data
|
281 | 270 |
|
282 | 271 |
|
283 |
| -@skip_pypy_deep_stack |
284 |
| -@skip_wasm_deep_stack |
285 | 272 | @pytest.mark.benchmark(group='recursive model')
|
286 | 273 | def test_definition_model_core(definition_model_data, benchmark):
|
287 | 274 | class CoreBranch:
|
@@ -1180,23 +1167,22 @@ def test_tagged_union_int_keys_json(benchmark):
|
1180 | 1167 | benchmark(v.validate_json, payload)
|
1181 | 1168 |
|
1182 | 1169 |
|
1183 |
| -@skip_pypy_deep_stack |
1184 |
| -@skip_wasm_deep_stack |
1185 | 1170 | @pytest.mark.benchmark(group='field_function_validator')
|
1186 | 1171 | def test_field_function_validator(benchmark) -> None:
|
1187 | 1172 | def f(v: int, info: core_schema.FieldValidationInfo) -> int:
|
1188 | 1173 | assert info.field_name == 'x'
|
1189 | 1174 | return v + 1
|
1190 | 1175 |
|
1191 | 1176 | schema: core_schema.CoreSchema = core_schema.int_schema()
|
| 1177 | + limit = pydantic_core._pydantic_core._recursion_limit - 3 |
1192 | 1178 |
|
1193 |
| - for _ in range(100): |
| 1179 | + for _ in range(limit): |
1194 | 1180 | schema = core_schema.field_after_validator_function(f, 'x', schema)
|
1195 | 1181 |
|
1196 | 1182 | schema = core_schema.typed_dict_schema({'x': core_schema.typed_dict_field(schema)})
|
1197 | 1183 |
|
1198 | 1184 | v = SchemaValidator(schema)
|
1199 | 1185 | payload = {'x': 0}
|
1200 |
| - assert v.validate_python(payload) == {'x': 100} |
| 1186 | + assert v.validate_python(payload) == {'x': limit} |
1201 | 1187 |
|
1202 | 1188 | benchmark(v.validate_python, payload)
|
0 commit comments