fix tests - update docstring tests, fix numpydantic import injects

This commit is contained in:
sneakers-the-rat 2024-07-29 18:20:30 -07:00
parent f08216a43f
commit c39d464e89
Signed by untrusted user who does not match committer: jonny
GPG key ID: 6DCB96EF1E4D232D
7 changed files with 32 additions and 10 deletions

View file

@ -147,7 +147,6 @@ class MapScalarAttributes(DatasetMap):
name:
name: name
ifabsent: string(starting_time)
identifier: true
range: string
required: true
equals_string: starting_time
@ -244,7 +243,6 @@ class MapListlike(DatasetMap):
attributes:
name:
name: name
identifier: true
range: string
required: true
image:
@ -354,6 +352,7 @@ class MapArraylike(DatasetMap):
- alias: x
- alias: y
- alias: z
"""
@classmethod
@ -473,7 +472,6 @@ class MapArrayLikeAttributes(DatasetMap):
attributes:
name:
name: name
identifier: true
range: string
required: true
resolution:

View file

@ -188,6 +188,21 @@ class AfterGenerateSlot:
if is_optional:
slot.attribute.range = "Optional[" + slot.attribute.range + "]"
del slot.attribute.meta["any_of"]
# merge injects/imports from the numpydantic array without using the merge method
if slot.injected_classes is None:
slot.injected_classes = NumpydanticArray.INJECTS.copy()
else:
slot.injected_classes.extend(NumpydanticArray.INJECTS.copy())
if isinstance(slot.imports, list):
slot.imports = (
Imports(imports=slot.imports) + NumpydanticArray.IMPORTS.model_copy()
)
elif isinstance(slot.imports, Imports):
slot.imports += NumpydanticArray.IMPORTS.model_copy()
else:
slot.imports = NumpydanticArray.IMPORTS.model_copy()
return slot
@staticmethod

View file

@ -118,6 +118,12 @@ class Provider(ABC):
def available_versions(self) -> Dict[str, List[str]]:
"""
Dictionary mapping a namespace to a list of built versions
.. warning:: This is busted
at the moment this property is very broken and needs to be updated to actually read
module metadata rather than try and parse filenames which is extremely fragile!!!
"""
from nwb_linkml.providers import LinkMLProvider

View file

@ -98,10 +98,10 @@ class PydanticProvider(Provider):
namespace.endswith(".yaml") or namespace.endswith(".yml")
):
# we're given a name of a namespace to build
path = (
LinkMLProvider(path=self.config.cache_dir).namespace_path(namespace, version)
/ "namespace.yaml"
)
provider = LinkMLProvider(path=self.config.cache_dir)
# ensure we have the schema in question
_ = provider.get(namespace, version=version)
path = provider.namespace_path(namespace, version) / "namespace.yaml"
else:
# given a path to a namespace linkml yaml file
@ -211,6 +211,8 @@ class PydanticProvider(Provider):
# make __init__.py files if we generated any files
if len(module_paths) > 0:
_ensure_inits(module_paths)
# then extra_inits that usually aren't generated bc we're one layer deeper
self._make_inits(ns_file)
return res

View file

@ -150,7 +150,7 @@ def test_name_slot():
assert slot.name == "name"
assert slot.required
assert slot.range == "string"
assert slot.identifier
assert slot.identifier is None
assert slot.ifabsent is None
assert slot.equals_string is None
@ -159,7 +159,7 @@ def test_name_slot():
assert slot.name == "name"
assert slot.required
assert slot.range == "string"
assert slot.identifier
assert slot.identifier is None
assert slot.ifabsent == "string(FixedName)"
assert slot.equals_string == "FixedName"

View file

@ -1,6 +1,6 @@
from pydantic import BaseModel
from nwb_linkml.includes import Named
from nwb_linkml.includes.types import Named
def test_named_generic():

View file

@ -65,6 +65,7 @@ def test_linkml_build_from_yaml(tmp_output_dir):
# @pytest.mark.depends(on=["test_linkml_provider"])
@pytest.mark.xfail
@pytest.mark.parametrize(
["class_name", "test_fields"],
[