sample_id stringlengths 21 196 | text stringlengths 105 936k | metadata dict | category stringclasses 6
values |
|---|---|---|---|
pydantic/pydantic:tests/types/test_model.py | from typing import Union
import pytest
from pydantic import BaseModel, ConfigDict, SerializationInfo, TypeAdapter, model_serializer
@pytest.mark.parametrize('config', [True, False, None])
@pytest.mark.parametrize('runtime', [True, False, None])
def test_polymorphic_serialization(config: Union[bool, None], runtime: ... | {
"repo_id": "pydantic/pydantic",
"file_path": "tests/types/test_model.py",
"license": "MIT License",
"lines": 58,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:tests/types/test_union.py | from typing import ClassVar, Literal, Union
from typing_extensions import TypedDict
import pydantic
def test_field_serializer_in_nested_union_called_only_twice():
class MyModel(pydantic.BaseModel):
a: int
b: int
field_a_serializer_calls: ClassVar[int] = 0
@pydantic.field_serial... | {
"repo_id": "pydantic/pydantic",
"file_path": "tests/types/test_union.py",
"license": "MIT License",
"lines": 54,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:tests/benchmarks/test_regex.py | from typing import Annotated, Any
from pydantic import Field, create_model
from .shared import DeferredModel, rebuild_model
def test_repeated_regex_pattern(benchmark):
ConstraintType = Annotated[str, Field(pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$')]
fields: dict[str, Any] = {f'f{i}': ConstraintType fo... | {
"repo_id": "pydantic/pydantic",
"file_path": "tests/benchmarks/test_regex.py",
"license": "MIT License",
"lines": 8,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:tests/benchmarks/test_validators_build.py | from pydantic import BaseModel, computed_field, field_validator
def test_validators_build(benchmark) -> None:
class Base1(BaseModel):
a: int
@field_validator('a', mode='after')
@classmethod
def val_a(cls, value: int) -> int: ...
@computed_field
def prop(self) -> i... | {
"repo_id": "pydantic/pydantic",
"file_path": "tests/benchmarks/test_validators_build.py",
"license": "MIT License",
"lines": 28,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/.github/check_version.py | #!/usr/bin/env python3
"""
Check the version in Cargo.toml matches the version from `GITHUB_REF` environment variable.
"""
import os
import re
import sys
from pathlib import Path
def main() -> int:
cargo_path = Path('Cargo.toml')
if not cargo_path.is_file():
print(f'✖ path "{cargo_path}" does not exi... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/.github/check_version.py",
"license": "MIT License",
"lines": 37,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
pydantic/pydantic:pydantic-core/python/pydantic_core/core_schema.py | """
This module contains definitions to build schemas which `pydantic_core` can
validate and serialize.
"""
from __future__ import annotations as _annotations
import sys
import warnings
from collections.abc import Hashable, Mapping
from datetime import date, datetime, time, timedelta
from decimal import Decimal
from ... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/python/pydantic_core/core_schema.py",
"license": "MIT License",
"lines": 3819,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
pydantic/pydantic:pydantic-core/tests/benchmarks/complete_schema.py | from __future__ import annotations
from decimal import Decimal
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from pydantic_core import CoreSchema
def schema(*, strict: bool = False) -> CoreSchema:
class MyModel:
# __slots__ is not required, but it avoids __pydantic_fields_set__ falling into __d... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/benchmarks/complete_schema.py",
"license": "MIT License",
"lines": 350,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/benchmarks/nested_schema.py | from __future__ import annotations
from typing import TYPE_CHECKING, Any
if TYPE_CHECKING:
from pydantic_core import core_schema as cs
N = 5 # arbitrary number that takes ~0.05s per run
class MyModel:
# __slots__ is not required, but it avoids __pydantic_fields_set__ falling into __dict__
__slots__ = ... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/benchmarks/nested_schema.py",
"license": "MIT License",
"lines": 79,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/benchmarks/test_complete_benchmark.py | """
General benchmarks that attempt to cover all field types, through by no means all uses of all field types.
"""
import json
from datetime import date, datetime, time
from decimal import Decimal
from uuid import UUID
import pytest
from pydantic_core import SchemaSerializer, SchemaValidator, ValidationError
from .... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/benchmarks/test_complete_benchmark.py",
"license": "MIT License",
"lines": 146,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/benchmarks/test_micro_benchmarks.py | """
Numerous benchmarks of specific functionality.
"""
import decimal
import json
import platform
import sys
from datetime import date, datetime, timedelta, timezone
from decimal import Decimal
from enum import Enum
from typing import Any
from uuid import UUID
import pytest
from dirty_equals import IsStr
import pyda... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/benchmarks/test_micro_benchmarks.py",
"license": "MIT License",
"lines": 1116,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/benchmarks/test_nested_benchmark.py | """
Benchmarks for nested / recursive schemas using definitions.
"""
from typing import Callable
from pydantic_core import SchemaValidator
from .nested_schema import inlined_schema, input_data_valid, schema_using_defs
def test_nested_schema_using_defs(benchmark: Callable[..., None]) -> None:
v = SchemaValidato... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/benchmarks/test_nested_benchmark.py",
"license": "MIT License",
"lines": 16,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/benchmarks/test_serialization_micro.py | import json
from dataclasses import dataclass
from datetime import date, datetime
from uuid import UUID
import pytest
from pydantic_core import SchemaSerializer, SchemaValidator, core_schema, to_json
class TestBenchmarkSimpleModel:
@pytest.fixture(scope='class')
def core_schema(self):
class CoreMode... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/benchmarks/test_serialization_micro.py",
"license": "MIT License",
"lines": 386,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/serializers/test_any.py | import dataclasses
import ipaddress
import json
import platform
import re
import sys
from collections import namedtuple
from datetime import date, datetime, time, timedelta, timezone
from decimal import Decimal
from enum import Enum
from math import inf, isinf, isnan, nan
from pathlib import Path
from typing import Cla... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/serializers/test_any.py",
"license": "MIT License",
"lines": 612,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/serializers/test_bytes.py | import base64
import json
from enum import Enum
import pytest
from pydantic_core import PydanticSerializationError, SchemaSerializer, core_schema, to_json
def test_bytes():
s = SchemaSerializer(core_schema.bytes_schema())
assert s.to_python(b'foobar') == b'foobar'
assert s.to_python('emoji 💩'.encode())... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/serializers/test_bytes.py",
"license": "MIT License",
"lines": 128,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/serializers/test_complex.py | import math
import pytest
from pydantic_core import SchemaSerializer, core_schema
@pytest.mark.parametrize(
'value,expected',
[
(complex(-1.23e-4, 567.89), '-0.000123+567.89j'),
(complex(0, -1.23), '-1.23j'),
(complex(1.5, 0), '1.5+0j'),
(complex(1.5, -0.0), '1.5-0j'),
... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/serializers/test_complex.py",
"license": "MIT License",
"lines": 39,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/serializers/test_dataclasses.py | import dataclasses
import json
import platform
import sys
from typing import ClassVar
import pytest
from pydantic_core import SchemaSerializer, SchemaValidator, core_schema
on_pypy = platform.python_implementation() == 'PyPy'
# pypy doesn't seem to maintain order of `__dict__`
if on_pypy:
IsStrictDict = dict
els... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/serializers/test_dataclasses.py",
"license": "MIT License",
"lines": 248,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/serializers/test_datetime.py | from datetime import date, datetime, time, timedelta, timezone
import pytest
from pydantic_core import SchemaSerializer, core_schema
def test_datetime():
v = SchemaSerializer(core_schema.datetime_schema())
assert v.to_python(datetime(2022, 12, 2, 12, 13, 14)) == datetime(2022, 12, 2, 12, 13, 14)
assert... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/serializers/test_datetime.py",
"license": "MIT License",
"lines": 316,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/serializers/test_decimal.py | from decimal import Decimal
import pytest
from pydantic_core import SchemaSerializer, core_schema
def test_decimal():
v = SchemaSerializer(core_schema.decimal_schema())
assert v.to_python(Decimal('123.456')) == Decimal('123.456')
assert v.to_python(Decimal('123.456'), mode='json') == '123.456'
asse... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/serializers/test_decimal.py",
"license": "MIT License",
"lines": 48,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/serializers/test_definitions.py | import pytest
from pydantic_core import SchemaError, SchemaSerializer, core_schema
def test_custom_ser():
s = SchemaSerializer(
core_schema.definitions_schema(
core_schema.list_schema(core_schema.definition_reference_schema('foobar')),
[core_schema.int_schema(ref='foobar', seriali... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/serializers/test_definitions.py",
"license": "MIT License",
"lines": 106,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/serializers/test_definitions_recursive.py | import pytest
from pydantic_core import SchemaSerializer, core_schema
def test_branch_nullable():
s = SchemaSerializer(
core_schema.definitions_schema(
core_schema.definition_reference_schema('Branch'),
[
core_schema.typed_dict_schema(
{
... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/serializers/test_definitions_recursive.py",
"license": "MIT License",
"lines": 113,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/serializers/test_dict.py | import json
import pytest
from dirty_equals import IsStrictDict
from pydantic_core import SchemaSerializer, core_schema
def test_dict_str_int():
v = SchemaSerializer(core_schema.dict_schema(core_schema.str_schema(), core_schema.int_schema()))
assert v.to_python({'a': 1, 'b': 2, 'c': 3}) == {'a': 1, 'b': 2, ... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/serializers/test_dict.py",
"license": "MIT License",
"lines": 111,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/serializers/test_enum.py | from enum import Enum
import pytest
from pydantic_core import SchemaSerializer, core_schema
def test_plain_enum():
class MyEnum(Enum):
a = 1
b = 2
v = SchemaSerializer(core_schema.enum_schema(MyEnum, list(MyEnum.__members__.values())))
# debug(v)
assert v.to_python(MyEnum.a) is MyE... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/serializers/test_enum.py",
"license": "MIT License",
"lines": 108,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/serializers/test_format.py | import json
import re
from datetime import date
from uuid import UUID
import pytest
from pydantic_core import PydanticSerializationError, SchemaSerializer, core_schema
@pytest.mark.parametrize(
'value,formatting_string,expected_python,expected_json',
[
(42.12345, '0.4f', 42.12345, b'"42.1234"'),
... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/serializers/test_format.py",
"license": "MIT License",
"lines": 99,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/serializers/test_functions.py | import json
import os
import platform
import re
import sys
from collections import deque
from operator import attrgetter
from pathlib import Path
import pytest
from pydantic_core import (
PydanticOmit,
PydanticSerializationError,
PydanticSerializationUnexpectedValue,
SchemaSerializer,
core_schema,... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/serializers/test_functions.py",
"license": "MIT License",
"lines": 596,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/serializers/test_generator.py | import pytest
from dirty_equals import IsStr
from pydantic_core import SchemaSerializer, core_schema
def gen_ok(*things):
yield from things
def gen_error(*things):
yield from things
raise ValueError('oops')
def test_generator_any_iter():
s = SchemaSerializer(core_schema.generator_schema(core_sche... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/serializers/test_generator.py",
"license": "MIT License",
"lines": 120,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/serializers/test_infer.py | from enum import Enum
from pydantic_core import SchemaSerializer, core_schema
# serializing enum calls methods in serializers::infer
def test_infer_to_python():
class MyEnum(Enum):
complex_ = complex(1, 2)
v = SchemaSerializer(core_schema.enum_schema(MyEnum, list(MyEnum.__members__.values())))
a... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/serializers/test_infer.py",
"license": "MIT License",
"lines": 18,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/serializers/test_json.py | from pydantic_core import SchemaSerializer, core_schema
def test_json_int():
s = SchemaSerializer(core_schema.json_schema(core_schema.int_schema()))
assert s.to_python(1) == 1
assert s.to_python(1, round_trip=True) == '1'
assert s.to_python(1, mode='json') == 1
assert s.to_python(1, mode='json', ... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/serializers/test_json.py",
"license": "MIT License",
"lines": 34,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/serializers/test_json_or_python.py | from enum import Enum
from pydantic_core import SchemaSerializer, core_schema
def test_json_or_python():
def s1(v: int) -> int:
return v + 1
def s2(v: int) -> int:
return v + 2
s = SchemaSerializer(
core_schema.json_or_python_schema(
core_schema.int_schema(serializat... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/serializers/test_json_or_python.py",
"license": "MIT License",
"lines": 31,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/serializers/test_list_tuple.py | import json
from functools import partial
import pytest
from pydantic_core import (
PydanticSerializationError,
SchemaSerializer,
core_schema,
)
def test_list_any():
v = SchemaSerializer(core_schema.list_schema(core_schema.any_schema()))
assert v.to_python(['a', 'b', 'c']) == ['a', 'b', 'c']
... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/serializers/test_list_tuple.py",
"license": "MIT License",
"lines": 357,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/serializers/test_literal.py | from dataclasses import dataclass
from enum import Enum
from typing import Literal, Union
import pytest
from pydantic_core import SchemaError, SchemaSerializer, core_schema
from ..conftest import plain_repr
def test_int_literal():
s = SchemaSerializer(core_schema.literal_schema([1, 2, 3]))
r = plain_repr(s... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/serializers/test_literal.py",
"license": "MIT License",
"lines": 120,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/serializers/test_model.py | import dataclasses
import json
import platform
import warnings
from functools import cached_property
from random import randint
from typing import Any, ClassVar
import pytest
from dirty_equals import IsJson
from pydantic_core import (
PydanticSerializationError,
SchemaSerializer,
SchemaValidator,
core... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/serializers/test_model.py",
"license": "MIT License",
"lines": 1102,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/serializers/test_model_root.py | import json
import os
import platform
from pathlib import Path
from typing import Any, Union
import pytest
from pydantic_core import SchemaSerializer, core_schema
from ..conftest import plain_repr
on_pypy = platform.python_implementation() == 'PyPy'
# pypy doesn't seem to maintain order of `__dict__`
if on_pypy:
... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/serializers/test_model_root.py",
"license": "MIT License",
"lines": 164,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/serializers/test_none.py | import pytest
from pydantic_core import SchemaSerializer, core_schema
all_scalars = (
'int',
'bool',
'float',
'none',
'str',
'bytes',
'datetime',
'date',
'time',
'timedelta',
'url',
'multi-host-url',
)
all_types = all_scalars + ('list', 'dict', 'set', 'frozenset')
@py... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/serializers/test_none.py",
"license": "MIT License",
"lines": 29,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/serializers/test_nullable.py | import pytest
from pydantic_core import SchemaSerializer, core_schema
def test_nullable():
s = SchemaSerializer(core_schema.nullable_schema(core_schema.int_schema()))
assert s.to_python(None) is None
assert s.to_python(1) == 1
assert s.to_python(None, mode='json') is None
assert s.to_python(1, mo... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/serializers/test_nullable.py",
"license": "MIT License",
"lines": 15,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/serializers/test_other.py | import pytest
from pydantic_core import SchemaSerializer, SchemaValidator, core_schema
from ..conftest import plain_repr
def test_chain():
s = SchemaSerializer(core_schema.chain_schema([core_schema.str_schema(), core_schema.int_schema()]))
# insert_assert(plain_repr(s))
assert plain_repr(s) == 'SchemaS... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/serializers/test_other.py",
"license": "MIT License",
"lines": 77,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/serializers/test_pickling.py | import json
import pickle
from datetime import timedelta
import pytest
from pydantic_core import core_schema
from pydantic_core._pydantic_core import SchemaSerializer
def repr_function(value, _info):
return repr(value)
def test_basic_schema_serializer():
s = SchemaSerializer(core_schema.dict_schema())
... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/serializers/test_pickling.py",
"license": "MIT License",
"lines": 55,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/serializers/test_serialize_as_any.py | from dataclasses import dataclass
from typing import Callable, Optional
import pytest
from typing_extensions import TypedDict
from pydantic_core import SchemaSerializer, SchemaValidator, core_schema
class ParentModel:
x: int
class ChildModel(ParentModel):
y: str
ParentModel.__pydantic_core_schema__ = co... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/serializers/test_serialize_as_any.py",
"license": "MIT License",
"lines": 371,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/serializers/test_set_frozenset.py | import json
import pytest
from dirty_equals import IsList
from pydantic_core import SchemaSerializer, core_schema
def test_set_any():
v = SchemaSerializer(core_schema.set_schema(core_schema.any_schema()))
assert v.to_python({'a', 'b', 'c'}) == {'a', 'b', 'c'}
assert v.to_python({'a', 'b', 'c'}, mode='js... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/serializers/test_set_frozenset.py",
"license": "MIT License",
"lines": 49,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/serializers/test_simple.py | import json
from enum import IntEnum
import pytest
from pydantic_core import CoreConfig, SchemaSerializer, core_schema
try:
import numpy
except ImportError:
numpy = None
class IntSubClass(int):
pass
class MyIntEnum(IntEnum):
one = 1
two = 2
class FloatSubClass(float):
pass
# A number ... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/serializers/test_simple.py",
"license": "MIT License",
"lines": 136,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/serializers/test_string.py | import json
from enum import Enum
import pytest
from pydantic_core import PydanticSerializationError, SchemaSerializer, core_schema
def test_str():
v = SchemaSerializer(core_schema.str_schema())
assert v.to_python('foobar') == 'foobar'
assert v.to_python('emoji 💩') == 'emoji 💩'
assert v.to_json('f... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/serializers/test_string.py",
"license": "MIT License",
"lines": 154,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/serializers/test_timedelta.py | from datetime import timedelta
import pytest
from pydantic_core import SchemaSerializer, core_schema
try:
import pandas
except ImportError:
pandas = None
def test_timedelta():
v = SchemaSerializer(core_schema.timedelta_schema())
assert v.to_python(timedelta(days=2, hours=3, minutes=4)) == timedelta... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/serializers/test_timedelta.py",
"license": "MIT License",
"lines": 349,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/serializers/test_typed_dict.py | import json
from typing import Any
import pytest
from dirty_equals import IsStrictDict
from typing_extensions import TypedDict
from pydantic_core import SchemaSerializer, core_schema
@pytest.mark.parametrize('extra_behavior_kw', [{}, {'extra_behavior': 'ignore'}, {'extra_behavior': None}])
def test_typed_dict(extra... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/serializers/test_typed_dict.py",
"license": "MIT License",
"lines": 343,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/serializers/test_union.py | from __future__ import annotations
import dataclasses
import json
import uuid
import warnings
from decimal import Decimal
from typing import Any, ClassVar, Literal, Union
import pytest
from pydantic_core import PydanticSerializationUnexpectedValue, SchemaSerializer, core_schema
class BaseModel:
def __init__(se... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/serializers/test_union.py",
"license": "MIT License",
"lines": 964,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/serializers/test_url.py | import pickle
import pytest
from pydantic_core import MultiHostUrl, SchemaSerializer, SchemaValidator, Url, core_schema
def test_url():
v = SchemaValidator(core_schema.url_schema())
s = SchemaSerializer(core_schema.url_schema())
url = v.validate_python('https://example.com')
assert isinstance(url, ... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/serializers/test_url.py",
"license": "MIT License",
"lines": 81,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/serializers/test_uuid.py | from uuid import UUID
import pytest
from pydantic_core import SchemaSerializer, core_schema
def test_uuid():
v = SchemaSerializer(core_schema.uuid_schema())
assert v.to_python(UUID('12345678-1234-5678-1234-567812345678')) == UUID('12345678-1234-5678-1234-567812345678')
assert (
v.to_python(UUID... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/serializers/test_uuid.py",
"license": "MIT License",
"lines": 50,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/test_build.py | import pickle
import pytest
from pydantic_core import SchemaValidator
from pydantic_core import core_schema as cs
def test_schema_as_string():
v = SchemaValidator(cs.bool_schema())
assert v.validate_python('tRuE') is True
@pytest.mark.parametrize('pickle_protocol', range(1, pickle.HIGHEST_PROTOCOL + 1))
d... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/test_build.py",
"license": "MIT License",
"lines": 66,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/test_config.py | import math
import re
import pytest
from dirty_equals import FunctionCheck, HasAttributes, IsInstance
from pydantic_core import CoreConfig, SchemaValidator, ValidationError
from pydantic_core import core_schema as cs
from .conftest import Err, plain_repr
def test_on_field():
v = SchemaValidator(cs.str_schema(m... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/test_config.py",
"license": "MIT License",
"lines": 126,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/test_custom_errors.py | from typing import Any, Optional
from unittest import TestCase
from unittest.mock import ANY
import pytest
from typing_extensions import LiteralString, Self, override
from pydantic_core import ErrorDetails, InitErrorDetails, PydanticCustomError, ValidationError
def test_validation_error_subclassable():
"""Asser... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/test_custom_errors.py",
"license": "MIT License",
"lines": 129,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/test_docstrings.py | import sys
from pathlib import Path
import pytest
try:
from pytest_examples import CodeExample, EvalExample, find_examples
except ImportError:
# pytest_examples is not installed on emscripten
CodeExample = EvalExample = None
def find_examples(*_directories):
return []
PYDANTIC_CORE_DIR = Pa... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/test_docstrings.py",
"license": "MIT License",
"lines": 34,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/test_errors.py | import enum
import os
import pickle
import re
import subprocess
import sys
from decimal import Decimal
from typing import Any, Optional
import pytest
from dirty_equals import HasRepr, IsInstance, IsJson, IsStr
from pytest_mock import MockerFixture
from pydantic_core import (
CoreConfig,
PydanticCustomError,
... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/test_errors.py",
"license": "MIT License",
"lines": 989,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/test_garbage_collection.py | import platform
import sys
from collections.abc import Iterable
from typing import Any
from weakref import WeakValueDictionary
import pytest
from pydantic_core import SchemaSerializer, SchemaValidator, core_schema
from .conftest import assert_gc, is_free_threaded
GC_TEST_SCHEMA_INNER = core_schema.definitions_schem... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/test_garbage_collection.py",
"license": "MIT License",
"lines": 86,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/test_hypothesis.py | import json
import re
import sys
from datetime import datetime, timezone
from typing import Optional
import pytest
from dirty_equals import AnyThing, IsBytes, IsStr, IsTuple
from hypothesis import given, strategies
from typing_extensions import TypedDict
from pydantic_core import SchemaSerializer, SchemaValidator, Va... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/test_hypothesis.py",
"license": "MIT License",
"lines": 153,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/test_isinstance.py | import pytest
from pydantic_core import PydanticOmit, SchemaError, SchemaValidator, ValidationError, core_schema
from pydantic_core import core_schema as cs
from .conftest import PyAndJson
def test_isinstance():
v = SchemaValidator(cs.int_schema())
assert v.validate_python(123) == 123
assert v.isinstanc... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/test_isinstance.py",
"license": "MIT License",
"lines": 51,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/test_json.py | import json
import platform
import re
import pytest
from dirty_equals import IsFloatNan, IsList
import pydantic_core
from pydantic_core import (
CoreConfig,
PydanticSerializationError,
SchemaSerializer,
SchemaValidator,
ValidationError,
core_schema,
from_json,
to_json,
to_jsonable_... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/test_json.py",
"license": "MIT License",
"lines": 364,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/test_misc.py | import copy
import os
import pickle
import pytest
from typing_extensions import (
get_args,
get_origin,
get_type_hints,
)
from typing_inspection import typing_objects
from typing_inspection.introspection import UNKNOWN, AnnotationSource, inspect_annotation
from pydantic_core import CoreConfig, CoreSchema,... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/test_misc.py",
"license": "MIT License",
"lines": 197,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/test_prebuilt.py | from typing import Union
from pydantic_core import SchemaSerializer, SchemaValidator, core_schema
def test_prebuilt_val_and_ser_used() -> None:
class InnerModel:
x: int
inner_schema = core_schema.model_schema(
InnerModel,
schema=core_schema.model_fields_schema(
{'x': core... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/test_prebuilt.py",
"license": "MIT License",
"lines": 324,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/test_schema_functions.py | import dataclasses
from datetime import date
from enum import Enum
from typing import Any
import pytest
from typing_extensions import get_args, get_type_hints
from typing_inspection.introspection import UNKNOWN, AnnotationSource, inspect_annotation
from pydantic_core import SchemaError, SchemaSerializer, SchemaValida... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/test_schema_functions.py",
"license": "MIT License",
"lines": 354,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/test_strict.py | from __future__ import annotations
import re
from typing import Any
import pytest
from pydantic_core import ValidationError
from .conftest import Err, PyAndJson
@pytest.mark.parametrize(
'strict_to_validator,strict_in_schema,input_value,expected',
[
(False, False, 123, 123),
(False, False,... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/test_strict.py",
"license": "MIT License",
"lines": 43,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/test_typing.py | from __future__ import annotations as _annotations
from datetime import date, datetime, time
from typing import Any, Callable
from pydantic_core import (
CoreSchema,
ErrorDetails,
PydanticKnownError,
SchemaError,
SchemaSerializer,
SchemaValidator,
ValidationError,
core_schema,
)
clas... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/test_typing.py",
"license": "MIT License",
"lines": 230,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/test_tzinfo.py | import copy
import functools
import pickle
import sys
import unittest
from datetime import datetime, timedelta, timezone, tzinfo
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
from pydantic_core import SchemaValidator, TzInfo, core_schema
class _ALWAYS_EQ:
"""
Object that is equal to anything.
"""
... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/test_tzinfo.py",
"license": "MIT License",
"lines": 191,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/test_validate_strings.py | import dataclasses
import re
from datetime import date, datetime
import pytest
from pydantic_core import SchemaValidator, ValidationError, core_schema
from .conftest import Err
def test_bool():
v = SchemaValidator(core_schema.bool_schema())
assert v.validate_strings('true') is True
assert v.validate_s... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/test_validate_strings.py",
"license": "MIT License",
"lines": 112,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/test_validation_context.py | import pytest
from pydantic_core import SchemaValidator, ValidationError, core_schema
from .conftest import PyAndJson
def test_after(py_and_json: PyAndJson):
def f(input_value, info):
return input_value + f'| context: {info.context}'
v = py_and_json(core_schema.with_info_after_validator_function(f,... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/test_validation_context.py",
"license": "MIT License",
"lines": 84,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/arguments_v3/test_alias.py | from __future__ import annotations
import re
import pytest
from pydantic_core import ArgsKwargs, SchemaValidator, ValidationError
from pydantic_core import core_schema as cs
from ...conftest import Err, PyAndJson
@pytest.mark.parametrize(
['input_value', 'expected'],
(
[ArgsKwargs((1,)), ((1,), {}... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/arguments_v3/test_alias.py",
"license": "MIT License",
"lines": 136,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/arguments_v3/test_build_errors.py | import pytest
from pydantic_core import SchemaError, SchemaValidator
from pydantic_core import core_schema as cs
def test_build_non_default_follows_default() -> None:
with pytest.raises(SchemaError, match="Required parameter 'b' follows parameter with default"):
SchemaValidator(
schema=cs.arg... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/arguments_v3/test_build_errors.py",
"license": "MIT License",
"lines": 74,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/arguments_v3/test_extra.py | from typing import Any, Union
import pytest
from pydantic_core import ArgsKwargs, ValidationError
from pydantic_core import core_schema as cs
from ...conftest import PyAndJson
@pytest.mark.parametrize(
'schema_extra_behavior,validate_fn_extra_kw',
[
('forbid', None),
('ignore', 'forbid'),
... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/arguments_v3/test_extra.py",
"license": "MIT License",
"lines": 61,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/arguments_v3/test_general.py | import pytest
from pydantic_core import ArgsKwargs, SchemaValidator, ValidationError
from pydantic_core import core_schema as cs
from ...conftest import Err, PyAndJson, plain_repr
@pytest.mark.parametrize(
['input_value', 'expected'],
(
[ArgsKwargs(()), ((), {})],
[{}, ((), {})],
[Ar... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/arguments_v3/test_general.py",
"license": "MIT License",
"lines": 109,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/arguments_v3/test_keyword_only.py | import pytest
from pydantic_core import ArgsKwargs, ValidationError
from pydantic_core import core_schema as cs
from ...conftest import PyAndJson
@pytest.mark.parametrize(
'input_value',
[
ArgsKwargs((), {'a': 1, 'b': True}),
ArgsKwargs((), {'a': 1}),
{'a': 1, 'b': True},
{'a... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/arguments_v3/test_keyword_only.py",
"license": "MIT License",
"lines": 79,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/arguments_v3/test_positional_only.py | import pytest
from pydantic_core import ArgsKwargs, ValidationError
from pydantic_core import core_schema as cs
from ...conftest import PyAndJson
@pytest.mark.parametrize(
'input_value',
[
ArgsKwargs((1, True)),
ArgsKwargs((1,)),
{'a': 1, 'b': True},
{'a': 1},
],
)
def te... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/arguments_v3/test_positional_only.py",
"license": "MIT License",
"lines": 81,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/arguments_v3/test_positional_or_keyword.py | import pytest
from pydantic_core import ArgsKwargs, ValidationError
from pydantic_core import core_schema as cs
from ...conftest import PyAndJson
@pytest.mark.parametrize(
['input_value', 'expected'],
(
[ArgsKwargs((1, True)), ((1, True), {})],
[ArgsKwargs((1,)), ((1,), {'b': True})],
... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/arguments_v3/test_positional_or_keyword.py",
"license": "MIT License",
"lines": 87,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/arguments_v3/test_var_args.py | import pytest
from pydantic_core import ArgsKwargs, ValidationError
from pydantic_core import core_schema as cs
from ...conftest import PyAndJson
@pytest.mark.parametrize(
['input_value', 'expected'],
(
[ArgsKwargs(()), ((), {})],
[ArgsKwargs((1, 2, 3)), ((1, 2, 3), {})],
[{'args': (... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/arguments_v3/test_var_args.py",
"license": "MIT License",
"lines": 82,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/arguments_v3/test_var_kwargs_uniform.py | import pytest
from pydantic_core import ArgsKwargs, ValidationError
from pydantic_core import core_schema as cs
from ...conftest import PyAndJson
@pytest.mark.parametrize(
['input_value', 'expected'],
(
[ArgsKwargs(()), ((), {})],
[ArgsKwargs((), {'a': 1, 'b': 2}), ((), {'a': 1, 'b': 2})],
... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/arguments_v3/test_var_kwargs_uniform.py",
"license": "MIT License",
"lines": 71,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/arguments_v3/test_var_kwargs_unpacked_typed_dict.py | import pytest
from pydantic_core import ArgsKwargs, ValidationError
from pydantic_core import core_schema as cs
from ...conftest import Err, PyAndJson
@pytest.mark.parametrize(
['input_value', 'expected'],
(
[ArgsKwargs((), {'x': 1}), ((), {'x': 1})],
[ArgsKwargs((), {'x': 1, 'z': True}), ((... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/arguments_v3/test_var_kwargs_unpacked_typed_dict.py",
"license": "MIT License",
"lines": 106,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/test_allow_partial.py | from collections.abc import Mapping
import pytest
from dirty_equals import IsStrictDict
from inline_snapshot import snapshot
from pydantic_core import SchemaValidator, ValidationError, core_schema
def test_list():
v = SchemaValidator(
core_schema.list_schema(
core_schema.tuple_positional_sch... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/test_allow_partial.py",
"license": "MIT License",
"lines": 295,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/test_arguments.py | import os
import platform
import re
import sys
from functools import wraps
from inspect import Parameter, signature
from typing import Any, Union, get_type_hints
import pytest
from pydantic_core import ArgsKwargs, SchemaError, SchemaValidator, ValidationError, core_schema
from pydantic_core import core_schema as cs
... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/test_arguments.py",
"license": "MIT License",
"lines": 1134,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/test_bool.py | import os
import re
import pytest
from pydantic_core import SchemaValidator, ValidationError, core_schema
from pydantic_core import core_schema as cs
from ..conftest import Err, PyAndJson, plain_repr
@pytest.mark.parametrize(
'input_value,expected',
[
(False, False),
(True, True),
(... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/test_bool.py",
"license": "MIT License",
"lines": 98,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/test_bytes.py | import re
from typing import Any
import pytest
from pydantic_core import SchemaValidator, ValidationError
from pydantic_core import core_schema as cs
from ..conftest import Err, PyAndJson
def test_strict_bytes_validator():
v = SchemaValidator(cs.bytes_schema(strict=True))
assert v.validate_python(b'foo') ... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/test_bytes.py",
"license": "MIT License",
"lines": 102,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/test_call.py | import dataclasses
import re
from collections import namedtuple
from functools import partial
import pytest
from pydantic_core import ArgsKwargs, SchemaValidator, ValidationError
from pydantic_core import core_schema as cs
from ..conftest import Err, PyAndJson, plain_repr
@pytest.mark.parametrize(
'input_value... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/test_call.py",
"license": "MIT License",
"lines": 180,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/test_callable.py | import pytest
from pydantic_core import SchemaValidator, ValidationError
from pydantic_core import core_schema as cs
def func():
return 42
class Foo:
pass
class CallableClass:
def __call__(self, *args, **kwargs):
pass
def test_callable():
v = SchemaValidator(cs.callable_schema())
as... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/test_callable.py",
"license": "MIT License",
"lines": 46,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/test_chain.py | from decimal import Decimal
import pytest
from pydantic_core import SchemaError, SchemaValidator, ValidationError, core_schema
from pydantic_core import core_schema as cs
from ..conftest import PyAndJson
def test_chain():
validator = SchemaValidator(
cs.chain_schema(
steps=[cs.str_schema(),... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/test_chain.py",
"license": "MIT License",
"lines": 87,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/test_complex.py | import math
import platform
import re
import sys
import pytest
from pydantic_core import SchemaValidator, ValidationError
from pydantic_core import core_schema as cs
from ..conftest import Err
EXPECTED_PARSE_ERROR_MESSAGE = 'Input should be a valid complex string following the rules at https://docs.python.org/3/lib... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/test_complex.py",
"license": "MIT License",
"lines": 183,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/test_custom_error.py | import pytest
from pydantic_core import SchemaError, SchemaValidator, ValidationError, core_schema
from ..conftest import PyAndJson
def test_custom_error(py_and_json: PyAndJson):
v = py_and_json(
core_schema.custom_error_schema(core_schema.int_schema(), 'foobar', custom_error_message='Hello there')
... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/test_custom_error.py",
"license": "MIT License",
"lines": 31,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/test_dataclasses.py | import dataclasses
import platform
import re
import sys
import weakref
from typing import Any, ClassVar, Optional, Union
import pytest
from dirty_equals import IsListOrTuple, IsStr
from pydantic_core import ArgsKwargs, SchemaValidator, ValidationError, core_schema
from pydantic_core.core_schema import ExtraBehavior
... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/test_dataclasses.py",
"license": "MIT License",
"lines": 1610,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/test_date.py | from __future__ import annotations
import re
from datetime import date, datetime, time, timedelta, timezone
from decimal import Decimal
from typing import Any
import pytest
from pydantic_core import SchemaError, SchemaValidator, ValidationError, core_schema
from pydantic_core import core_schema as cs
from ..conftes... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/test_date.py",
"license": "MIT License",
"lines": 299,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/test_datetime.py | import copy
import json
import re
import types
import zoneinfo
from datetime import date, datetime, time, timedelta, timezone, tzinfo
from decimal import Decimal
import pytest
from pydantic_core import SchemaError, SchemaValidator, ValidationError, core_schema
from pydantic_core import core_schema as cs
from ..conft... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/test_datetime.py",
"license": "MIT License",
"lines": 449,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/test_decimal.py | from __future__ import annotations
import json
import math
import re
from decimal import Decimal
from typing import Any
import pytest
from dirty_equals import FunctionCheck, IsStr
from pydantic_core import SchemaError, SchemaValidator, ValidationError
from pydantic_core import core_schema as cs
from ..conftest impo... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/test_decimal.py",
"license": "MIT License",
"lines": 489,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/test_definitions.py | import pytest
from pydantic_core import SchemaError, SchemaValidator, core_schema
from ..conftest import plain_repr
def test_list_with_def():
v = SchemaValidator(
core_schema.definitions_schema(
core_schema.list_schema(core_schema.definition_reference_schema('foobar')),
[core_sch... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/test_definitions.py",
"license": "MIT License",
"lines": 126,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/test_definitions_recursive.py | import datetime
import platform
import sys
from dataclasses import dataclass
from typing import Optional
import pytest
from dirty_equals import AnyThing, HasAttributes, IsList, IsPartialDict, IsStr, IsTuple
import pydantic_core
from pydantic_core import CoreConfig, SchemaError, SchemaValidator, ValidationError, core_... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/test_definitions_recursive.py",
"license": "MIT License",
"lines": 975,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/test_dict.py | import re
import sys
from collections import OrderedDict
from collections.abc import Mapping
from typing import Any
import pytest
from dirty_equals import HasRepr, IsStr
from pydantic_core import SchemaValidator, ValidationError
from pydantic_core import core_schema as cs
from ..conftest import Err, PyAndJson
def ... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/test_dict.py",
"license": "MIT License",
"lines": 287,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/test_enums.py | import re
import sys
from decimal import Decimal
from enum import Enum, IntEnum, IntFlag
import pytest
from pydantic_core import SchemaError, SchemaValidator, ValidationError, core_schema
def test_plain_enum():
class MyEnum(Enum):
a = 1
b = 2
v = SchemaValidator(core_schema.enum_schema(MyEn... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/test_enums.py",
"license": "MIT License",
"lines": 368,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/test_float.py | import math
import re
import sys
from decimal import Decimal
from typing import Any
import pytest
from dirty_equals import FunctionCheck, IsFloatNan, IsStr
from pydantic_core import SchemaValidator, ValidationError, core_schema
from pydantic_core import core_schema as cs
from ..conftest import Err, PyAndJson, plain_... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/test_float.py",
"license": "MIT License",
"lines": 396,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/test_frozenset.py | import re
from collections import deque
from typing import Any
import pytest
from pydantic_core import SchemaValidator, ValidationError
from pydantic_core import core_schema as cs
from ..conftest import Err, PyAndJson, infinite_generator, plain_repr
@pytest.mark.parametrize(
'input_value,expected',
[([], f... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/test_frozenset.py",
"license": "MIT License",
"lines": 306,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/test_function.py | import datetime
import platform
import re
from copy import deepcopy
from dataclasses import dataclass
from typing import Any
import pytest
from dirty_equals import HasRepr
from pydantic_core import CoreConfig, SchemaValidator, ValidationError, core_schema
from pydantic_core import core_schema as cs
from ..conftest i... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/test_function.py",
"license": "MIT License",
"lines": 817,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/test_generator.py | import re
import pytest
from dirty_equals import HasRepr, IsStr
from pydantic_core import CoreConfig, SchemaValidator, ValidationError
from pydantic_core import core_schema as cs
from ..conftest import Err, PyAndJson
@pytest.mark.parametrize(
'input_value,expected',
[
([1, 2, 3], [1, 2, 3]),
... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/test_generator.py",
"license": "MIT License",
"lines": 170,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/test_int.py | import json
import os
import re
from decimal import Decimal
from fractions import Fraction
from typing import Any
import pytest
from dirty_equals import IsStr
from pydantic_core import SchemaError, SchemaValidator, ValidationError
from pydantic_core import core_schema as cs
from ..conftest import Err, PyAndJson, pla... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/test_int.py",
"license": "MIT License",
"lines": 513,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/test_is_instance.py | import typing
import pytest
from pydantic_core import SchemaError, SchemaValidator, ValidationError, core_schema
from pydantic_core import core_schema as cs
class Foo:
pass
class Bar(Foo):
pass
class Spam:
pass
def test_validate_json() -> None:
v = SchemaValidator(cs.is_instance_schema(cls=Foo... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/test_is_instance.py",
"license": "MIT License",
"lines": 143,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/test_is_subclass.py | import pytest
from pydantic_core import SchemaError, SchemaValidator, ValidationError, core_schema
class Foo:
pass
class Foobar(Foo):
pass
class Bar:
pass
def test_is_subclass_basic():
v = SchemaValidator(core_schema.is_subclass_schema(Foo))
assert v.validate_python(Foo) == Foo
with pyt... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/test_is_subclass.py",
"license": "MIT License",
"lines": 67,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/test_json.py | import re
from enum import Enum
import pytest
from pydantic_core import SchemaValidator, ValidationError, core_schema
from ..conftest import Err, PyAndJson, plain_repr
@pytest.mark.parametrize(
'input_value,expected',
[
('{"a": 1}', {'a': 1}),
('"a"', 'a'),
('1', 1),
('[1, 2... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/test_json.py",
"license": "MIT License",
"lines": 160,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/test_json_or_python.py | import pytest
from pydantic_core import SchemaValidator, ValidationError
from pydantic_core import core_schema as cs
def test_json_or_python():
class Foo(str):
def __eq__(self, o: object) -> bool:
if isinstance(o, Foo) and super().__eq__(o):
return True
return Fals... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/test_json_or_python.py",
"license": "MIT License",
"lines": 26,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/test_lax_or_strict.py | import pytest
from pydantic_core import SchemaValidator, ValidationError, core_schema
def test_lax_or_strict():
v = SchemaValidator(core_schema.lax_or_strict_schema(core_schema.str_schema(), core_schema.int_schema()))
# validator is default - lax so with no runtime arg, we're in lax mode, and we use the stri... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/test_lax_or_strict.py",
"license": "MIT License",
"lines": 31,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
pydantic/pydantic:pydantic-core/tests/validators/test_list.py | import collections.abc
import re
from collections import deque
from collections.abc import Iterator
from dataclasses import dataclass
from typing import Any, Union
import pytest
from dirty_equals import Contains, HasRepr, IsInstance, IsList, IsStr
from pydantic_core import SchemaValidator, ValidationError, core_schem... | {
"repo_id": "pydantic/pydantic",
"file_path": "pydantic-core/tests/validators/test_list.py",
"license": "MIT License",
"lines": 466,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.