2024-07-27 02:54:35 +00:00
|
|
|
from pydantic import BaseModel
|
2024-07-29 23:28:48 +00:00
|
|
|
|
2024-07-27 02:54:35 +00:00
|
|
|
from nwb_linkml.includes import Named
|
|
|
|
|
2024-07-29 23:28:48 +00:00
|
|
|
|
2024-07-27 02:54:35 +00:00
|
|
|
def test_named_generic():
|
|
|
|
"""
|
|
|
|
the Named type should fill in the ``name`` field in a model from the field name
|
|
|
|
"""
|
2024-07-29 23:28:48 +00:00
|
|
|
|
2024-07-27 02:54:35 +00:00
|
|
|
class Child(BaseModel):
|
|
|
|
name: str
|
|
|
|
value: int
|
|
|
|
|
|
|
|
class Parent(BaseModel):
|
|
|
|
field_name: Named[Child]
|
|
|
|
|
|
|
|
# should instantiate correctly and have name set
|
2024-07-29 23:28:48 +00:00
|
|
|
instance = Parent(field_name={"value": 1})
|
|
|
|
assert instance.field_name.name == "field_name"
|