Skip to content

Commit fac2a40

Browse files
authored
remove pydantic V1 comparisons from benchmark suite (#748)
1 parent 634087a commit fac2a40

File tree

7 files changed

+2
-650
lines changed

7 files changed

+2
-650
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ jobs:
103103

104104
- run: pytest
105105
env:
106-
BENCHMARK_VS_PYDANTIC: 1
107106
HYPOTHESIS_PROFILE: slow
108107

109108
test-os:

tests/benchmarks/README.md

Lines changed: 0 additions & 129 deletions
This file was deleted.

tests/benchmarks/complete_schema.py

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -209,91 +209,6 @@ def wrap_function(input_value, validator, info):
209209
}
210210

211211

212-
def pydantic_model():
213-
from datetime import date, datetime, time
214-
from typing import Any, Literal, Union
215-
216-
try:
217-
from pydantic import BaseModel, conbytes, confloat, confrozenset, conint, conlist, conset, constr, validator
218-
except ImportError:
219-
return None
220-
221-
class UnionModel1(BaseModel):
222-
field_str: str
223-
field_int: int
224-
field_float: float
225-
226-
class UnionModel2(BaseModel):
227-
field_float: float
228-
field_bytes: bytes
229-
field_date: date
230-
231-
class FunctionModel(BaseModel):
232-
field_before: str
233-
field_after: str
234-
field_wrap: str
235-
field_plain: Any
236-
237-
@validator('field_before', pre=True, allow_reuse=True)
238-
def append_before(cls, v):
239-
return f'{v} Changed'
240-
241-
@validator('field_after', 'field_wrap', 'field_plain', allow_reuse=True) # best attempts at wrap and plain
242-
def append_after(cls, v):
243-
return f'{v} Changed'
244-
245-
@validator('field_wrap', pre=True, allow_reuse=True) # other part of wrap
246-
def wrap_before(cls, v):
247-
return f'Input {v}'
248-
249-
class BranchModel(BaseModel):
250-
name: str
251-
sub_branch: 'BranchModel' = None
252-
253-
class Model(BaseModel):
254-
field_str: str
255-
field_str_con: constr(min_length=3, max_length=5, regex='^[a-z]+$')
256-
field_int: int
257-
field_int_con: conint(gt=1, lt=10, multiple_of=2)
258-
field_float: float
259-
field_float_con: confloat(ge=1.0, le=10.0, multiple_of=0.5)
260-
field_bool: bool
261-
field_bytes: bytes
262-
field_bytes_con: conbytes(min_length=6, max_length=1000)
263-
field_date: date
264-
field_date_con: date # todo ge='2020-01-01', lt='2020-01-02'
265-
field_time: time
266-
field_time_con: time # todo ge='06:00:00', lt='12:13:14'
267-
field_datetime: datetime
268-
field_datetime_con: datetime # todo ge='2000-01-01T06:00:00', lt='2020-01-02T12:13:14'
269-
field_list_any: list
270-
field_list_str: list[str]
271-
field_list_str_con: conlist(str, min_items=3, max_items=42)
272-
field_set_any: set
273-
field_set_int: set[int]
274-
field_set_int_con: conset(int, min_items=3, max_items=42)
275-
field_frozenset_any: frozenset
276-
field_frozenset_bytes: frozenset[bytes]
277-
field_frozenset_bytes_con: confrozenset(bytes, min_items=3, max_items=42)
278-
field_tuple_var_len_any: tuple[Any, ...]
279-
field_tuple_var_len_float: tuple[float, ...]
280-
field_tuple_var_len_float_con: tuple[float, ...] # todo min_items=3, max_items=42
281-
field_tuple_fix_len: tuple[str, int, float, bool]
282-
field_dict_any: dict
283-
field_dict_str_float: dict[str, float]
284-
field_literal_1_int: Literal[1]
285-
field_literal_1_str: Literal['foobar']
286-
field_literal_mult_int: Literal[1, 2, 3]
287-
field_literal_mult_str: Literal['foo', 'bar', 'baz']
288-
field_literal_assorted: Literal[1, 'foo', True]
289-
field_list_nullable_int: list[int | None]
290-
field_union: Union[str, UnionModel1, UnionModel2]
291-
field_functions_model: FunctionModel
292-
field_recursive: BranchModel
293-
294-
return Model
295-
296-
297212
def input_data_lax():
298213
return {
299214
'field_str': 'fo',

tests/benchmarks/test_complete_benchmark.py

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@
22
General benchmarks that attempt to cover all field types, through by no means all uses of all field types.
33
"""
44
import json
5-
import sys
65
from datetime import date, datetime, time
76

87
import pytest
98

109
from pydantic_core import SchemaValidator, ValidationError
1110

12-
from .complete_schema import input_data_lax, input_data_strict, input_data_wrong, pydantic_model, schema
13-
from .test_micro_benchmarks import skip_pydantic
14-
15-
pytestmark = pytest.mark.skipif(sys.version_info < (3, 10), reason='requires python3.10 or higher')
11+
from .complete_schema import input_data_lax, input_data_strict, input_data_wrong, schema
1612

1713

1814
def test_complete_valid():
@@ -77,14 +73,6 @@ def test_complete_valid():
7773
output2 = strict_validator.validate_python(input_data_strict())
7874
assert output_dict == output2.__dict__
7975

80-
model = pydantic_model()
81-
if model is None:
82-
print('pydantic is not installed, skipping pydantic tests')
83-
return
84-
85-
output_pydantic = model.parse_obj(input_data_lax())
86-
assert output_pydantic.dict() == output_dict
87-
8876

8977
def test_complete_invalid():
9078
lax_schema = schema()
@@ -93,17 +81,6 @@ def test_complete_invalid():
9381
lax_validator.validate_python(input_data_wrong())
9482
assert len(exc_info.value.errors(include_url=False)) == 738
9583

96-
model = pydantic_model()
97-
if model is None:
98-
print('pydantic is not installed, skipping pydantic tests')
99-
return
100-
101-
from pydantic import ValidationError as PydanticValidationError
102-
103-
with pytest.raises(PydanticValidationError) as exc_info:
104-
model.parse_obj(input_data_wrong())
105-
assert len(exc_info.value.errors()) == 530
106-
10784

10885
@pytest.mark.benchmark(group='complete')
10986
def test_complete_core_lax(benchmark):
@@ -117,14 +94,6 @@ def test_complete_core_strict(benchmark):
11794
benchmark(v.validate_python, input_data_strict())
11895

11996

120-
@skip_pydantic
121-
@pytest.mark.benchmark(group='complete')
122-
def test_complete_pyd(benchmark):
123-
model = pydantic_model()
124-
assert model is not None
125-
benchmark(model.parse_obj, input_data_lax())
126-
127-
12897
@pytest.mark.benchmark(group='complete-wrong')
12998
def test_complete_core_error(benchmark):
13099
v = SchemaValidator(schema())
@@ -151,23 +120,6 @@ def f():
151120
v.isinstance_python(data)
152121

153122

154-
@skip_pydantic
155-
@pytest.mark.benchmark(group='complete-wrong')
156-
def test_complete_pyd_error(benchmark):
157-
model = pydantic_model()
158-
assert model is not None
159-
data = input_data_wrong()
160-
161-
@benchmark
162-
def f():
163-
try:
164-
model.parse_obj(data)
165-
except ValueError:
166-
pass
167-
else:
168-
raise RuntimeError('expected ValueError')
169-
170-
171123
def default_json_encoder(obj):
172124
if isinstance(obj, bytes):
173125
return obj.decode('utf-8')
@@ -184,18 +136,6 @@ def test_complete_core_json(benchmark):
184136
benchmark(v.validate_json, json_data)
185137

186138

187-
@skip_pydantic
188-
@pytest.mark.benchmark(group='complete-json')
189-
def test_complete_pyd_json(benchmark):
190-
model = pydantic_model()
191-
assert model is not None
192-
json_data = json.dumps(input_data_lax(), default=default_json_encoder)
193-
194-
@benchmark
195-
def t():
196-
model.parse_raw(json_data, content_type='application/json')
197-
198-
199139
@pytest.mark.benchmark(group='build')
200140
def test_build_schema(benchmark):
201141
lax_schema = schema()

0 commit comments

Comments
 (0)