MCPcopy
hub / github.com/pydantic/pydantic / test_config_key_deprecation

Function test_config_key_deprecation

tests/test_config.py:404–462  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

402
403
404def test_config_key_deprecation():
405 config_dict = {
406 'allow_mutation': None,
407 'error_msg_templates': None,
408 'fields': None,
409 'getter_dict': None,
410 'schema_extra': None,
411 'smart_union': None,
412 'underscore_attrs_are_private': None,
413 'allow_population_by_field_name': None,
414 'anystr_lower': None,
415 'anystr_strip_whitespace': None,
416 'anystr_upper': None,
417 'keep_untouched': None,
418 'max_anystr_length': None,
419 'min_anystr_length': None,
420 'orm_mode': None,
421 'validate_all': None,
422 }
423
424 warning_message = """
425Valid config keys have changed in V2:
426* 'allow_population_by_field_name' has been renamed to 'validate_by_name'
427* 'anystr_lower' has been renamed to 'str_to_lower'
428* 'anystr_strip_whitespace' has been renamed to 'str_strip_whitespace'
429* 'anystr_upper' has been renamed to 'str_to_upper'
430* 'keep_untouched' has been renamed to 'ignored_types'
431* 'max_anystr_length' has been renamed to 'str_max_length'
432* 'min_anystr_length' has been renamed to 'str_min_length'
433* 'orm_mode' has been renamed to 'from_attributes'
434* 'schema_extra' has been renamed to 'json_schema_extra'
435* 'validate_all' has been renamed to 'validate_default'
436* 'allow_mutation' has been removed
437* 'error_msg_templates' has been removed
438* 'fields' has been removed
439* 'getter_dict' has been removed
440* 'smart_union' has been removed
441* 'underscore_attrs_are_private' has been removed
442 """.strip()
443
444 with pytest.warns(UserWarning, match=re.escape(warning_message)):
445
446 class MyModel(BaseModel):
447 model_config = config_dict
448
449 with pytest.warns(UserWarning, match=re.escape(warning_message)):
450 create_model('MyCreatedModel', __config__=config_dict)
451
452 with pytest.warns(UserWarning, match=re.escape(warning_message)):
453
454 @pydantic_dataclass(config=config_dict)
455 class MyDataclass:
456 pass
457
458 with pytest.warns(UserWarning, match=re.escape(warning_message)):
459
460 @validate_call(config=config_dict)
461 def my_function():

Callers

nothing calls this directly

Calls 1

create_modelFunction · 0.90

Tested by

no test coverage detected