mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
fix coverage for 'conset()' (#1704)
This commit is contained in:
@@ -190,9 +190,6 @@ class ConstrainedSet(set): # type: ignore
|
||||
|
||||
@classmethod
|
||||
def set_length_validator(cls, v: 'Optional[Set[T]]', field: 'ModelField') -> 'Optional[Set[T]]':
|
||||
if v is None and not field.required:
|
||||
return None
|
||||
|
||||
v = set_validator(v)
|
||||
v_len = len(v)
|
||||
|
||||
|
||||
@@ -405,6 +405,14 @@ def test_conset():
|
||||
assert exc_info.value.errors() == [{'loc': ('foo',), 'msg': 'value is not a valid set', 'type': 'type_error.set'}]
|
||||
|
||||
|
||||
def test_conset_not_required():
|
||||
class Model(BaseModel):
|
||||
foo: Set[int] = None
|
||||
|
||||
assert Model(foo=None).foo is None
|
||||
assert Model().foo is None
|
||||
|
||||
|
||||
class ConStringModel(BaseModel):
|
||||
v: constr(max_length=10) = 'foobar'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user