mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
renaming Module > PyObect, fix #9
This commit is contained in:
+2
-2
@@ -13,7 +13,7 @@ __all__ = [
|
||||
'constr',
|
||||
'EmailStr',
|
||||
'NameEmail',
|
||||
'Module',
|
||||
'PyObject',
|
||||
'DSN',
|
||||
'ConstrainedInt',
|
||||
'conint',
|
||||
@@ -95,7 +95,7 @@ def constr(*, min_length=0, max_length=2**16, curtail_length=None, regex=None) -
|
||||
return type('ConstrainedStrValue', (ConstrainedStr,), namespace)
|
||||
|
||||
|
||||
class Module:
|
||||
class PyObject:
|
||||
validate_always = True
|
||||
|
||||
@classmethod
|
||||
|
||||
+5
-5
@@ -5,7 +5,7 @@ from enum import Enum, IntEnum
|
||||
|
||||
import pytest
|
||||
|
||||
from pydantic import (DSN, BaseModel, EmailStr, Module, NameEmail, NegativeInt, PositiveInt, ValidationError,
|
||||
from pydantic import (DSN, BaseModel, EmailStr, NameEmail, NegativeInt, PositiveInt, PyObject, ValidationError,
|
||||
conint, constr)
|
||||
|
||||
|
||||
@@ -69,15 +69,15 @@ def test_dsn_no_driver():
|
||||
assert '"db_driver" field may not be missing or None' in str(exc_info.value)
|
||||
|
||||
|
||||
class ModuleModel(BaseModel):
|
||||
module: Module = 'os.path'
|
||||
class PyObjectModel(BaseModel):
|
||||
module: PyObject = 'os.path'
|
||||
|
||||
|
||||
def test_module_import():
|
||||
m = ModuleModel()
|
||||
m = PyObjectModel()
|
||||
assert m.module == os.path
|
||||
with pytest.raises(ValidationError) as exc_info:
|
||||
ModuleModel(module='foobar')
|
||||
PyObjectModel(module='foobar')
|
||||
assert '"foobar" doesn\'t look like a module path' in str(exc_info.value)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user