MCPcopy
hub / github.com/pydantic/pydantic / test_deprecated_module

Function test_deprecated_module

tests/test_deprecated.py:776–819  ·  view source on GitHub ↗
(tmp_path: Path)

Source from the content-addressed store, hash-verified

774
775
776def test_deprecated_module(tmp_path: Path) -> None:
777 class Model(BaseModel):
778 x: int
779
780 with pytest.warns(PydanticDeprecatedSince20) as all_warnings:
781 assert hasattr(parse_obj_as, '__deprecated__')
782 parse_obj_as(Model, {'x': 1})
783 assert hasattr(schema_json_of, '__deprecated__')
784 schema_json_of(Model)
785 assert hasattr(schema_of, '__deprecated__')
786 schema_of(Model)
787 assert hasattr(load_str_bytes, '__deprecated__')
788 load_str_bytes('{"x": 1}')
789 assert hasattr(load_file, '__deprecated__')
790 file = tmp_path / 'main.py'
791 file.write_text('{"x": 1}')
792 load_file(file)
793 assert hasattr(pydantic_encoder, '__deprecated__')
794 pydantic_encoder(Model(x=1))
795 assert hasattr(custom_pydantic_encoder, '__deprecated__')
796 custom_pydantic_encoder({int: lambda x: str(x)}, Model(x=1))
797 assert hasattr(timedelta_isoformat, '__deprecated__')
798 timedelta_isoformat(timedelta(seconds=1))
799
800 def test(a: int, b: int):
801 pass
802
803 validate_arguments()(test)
804 assert len(all_warnings) == 12
805 expected_warnings = [
806 '`parse_obj_as` is deprecated. Use `pydantic.TypeAdapter.validate_python` instead',
807 '`schema_json_of` is deprecated. Use `pydantic.TypeAdapter.json_schema` instead',
808 '`schema_of` is deprecated. Use `pydantic.TypeAdapter.json_schema` instead',
809 '`schema_of` is deprecated. Use `pydantic.TypeAdapter.json_schema` instead',
810 '`load_str_bytes` is deprecated',
811 '`load_file` is deprecated',
812 '`load_str_bytes` is deprecated',
813 '`pydantic_encoder` is deprecated, use `pydantic_core.to_jsonable_python` instead',
814 '`custom_pydantic_encoder` is deprecated, use `BaseModel.model_dump` instead',
815 '`pydantic_encoder` is deprecated, use `pydantic_core.to_jsonable_python` instead',
816 '`timedelta_isoformat` is deprecated',
817 'The `validate_arguments` method is deprecated; use `validate_call` instead',
818 ]
819 assert [w.message.message for w in all_warnings] == expected_warnings
820
821
822def test_deprecated_color():

Callers

nothing calls this directly

Calls 10

parse_obj_asFunction · 0.90
schema_json_ofFunction · 0.90
schema_ofFunction · 0.90
load_str_bytesFunction · 0.90
load_fileFunction · 0.90
pydantic_encoderFunction · 0.90
custom_pydantic_encoderFunction · 0.90
timedelta_isoformatFunction · 0.90
validate_argumentsFunction · 0.90
ModelClass · 0.70

Tested by

no test coverage detected