nwb-linkml/nwb_linkml/tests/test_includes.py

21 lines
480 B
Python
Raw Normal View History

from pydantic import BaseModel
2024-07-29 23:28:48 +00:00
from nwb_linkml.includes import Named
2024-07-29 23:28:48 +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
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"