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

View file

@ -188,6 +188,21 @@ class AfterGenerateSlot:
if is_optional: if is_optional:
slot.attribute.range = "Optional[" + slot.attribute.range + "]" slot.attribute.range = "Optional[" + slot.attribute.range + "]"
del slot.attribute.meta["any_of"] 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 return slot
@staticmethod @staticmethod

View file

@ -118,6 +118,12 @@ class Provider(ABC):
def available_versions(self) -> Dict[str, List[str]]: def available_versions(self) -> Dict[str, List[str]]:
""" """
Dictionary mapping a namespace to a list of built versions 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 from nwb_linkml.providers import LinkMLProvider

View file

@ -98,10 +98,10 @@ class PydanticProvider(Provider):
namespace.endswith(".yaml") or namespace.endswith(".yml") namespace.endswith(".yaml") or namespace.endswith(".yml")
): ):
# we're given a name of a namespace to build # we're given a name of a namespace to build
path = ( provider = LinkMLProvider(path=self.config.cache_dir)
LinkMLProvider(path=self.config.cache_dir).namespace_path(namespace, version) # ensure we have the schema in question
/ "namespace.yaml" _ = provider.get(namespace, version=version)
) path = provider.namespace_path(namespace, version) / "namespace.yaml"
else: else:
# given a path to a namespace linkml yaml file # 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 # make __init__.py files if we generated any files
if len(module_paths) > 0: if len(module_paths) > 0:
_ensure_inits(module_paths) _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 return res

View file

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

View file

@ -1,6 +1,6 @@
from pydantic import BaseModel from pydantic import BaseModel
from nwb_linkml.includes import Named from nwb_linkml.includes.types import Named
def test_named_generic(): 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.depends(on=["test_linkml_provider"])
@pytest.mark.xfail
@pytest.mark.parametrize( @pytest.mark.parametrize(
["class_name", "test_fields"], ["class_name", "test_fields"],
[ [