From a7b0f8880e26f871dff3877238d9406a1231399d Mon Sep 17 00:00:00 2001 From: sneakers-the-rat Date: Mon, 9 Oct 2023 18:59:53 -0700 Subject: [PATCH] fix tests, cant assign to tuple --- nwb_linkml/pyproject.toml | 8 ++- .../src/nwb_linkml/adapters/__init__.py | 1 + nwb_linkml/src/nwb_linkml/adapters/adapter.py | 2 +- .../src/nwb_linkml/adapters/namespaces.py | 3 +- nwb_linkml/src/nwb_linkml/providers/git.py | 3 +- nwb_linkml/tests/fixtures.py | 53 +++++++++++++++++-- .../test_adapters/test_adapter_classes.py | 9 ++++ .../test_adapters/test_adapter_dataset.py | 8 ++- .../test_generator_pydantic.py | 1 + 9 files changed, 77 insertions(+), 11 deletions(-) create mode 100644 nwb_linkml/tests/test_adapters/test_adapter_classes.py diff --git a/nwb_linkml/pyproject.toml b/nwb_linkml/pyproject.toml index 0706f84..9c34015 100644 --- a/nwb_linkml/pyproject.toml +++ b/nwb_linkml/pyproject.toml @@ -76,9 +76,15 @@ addopts = [ "--cov=nwb_linkml", "--cov-append", "--cov-config=.coveragerc", - "--doctest-modules" + "--doctest-modules", + "--ignore=tests/__tmp__" ] testpaths = [ "tests", 'nwb_linkml/tests' ] +doctest_optionflags = "NORMALIZE_WHITESPACE" +filterwarnings = [ + "ignore:Deprecated NumPy 1.24:DeprecationWarning", + "ignore:parse_obj:pydantic.PydanticDeprecatedSince20" +] \ No newline at end of file diff --git a/nwb_linkml/src/nwb_linkml/adapters/__init__.py b/nwb_linkml/src/nwb_linkml/adapters/__init__.py index 9ce6c4b..f1284b6 100644 --- a/nwb_linkml/src/nwb_linkml/adapters/__init__.py +++ b/nwb_linkml/src/nwb_linkml/adapters/__init__.py @@ -2,5 +2,6 @@ from nwb_linkml.adapters.adapter import Adapter, BuildResult from nwb_linkml.adapters.namespaces import NamespacesAdapter from nwb_linkml.adapters.classes import ClassAdapter from nwb_linkml.adapters.group import GroupAdapter +from nwb_linkml.adapters.dataset import DatasetAdapter from nwb_linkml.adapters.schema import SchemaAdapter diff --git a/nwb_linkml/src/nwb_linkml/adapters/adapter.py b/nwb_linkml/src/nwb_linkml/adapters/adapter.py index 7c10f60..8fcf29a 100644 --- a/nwb_linkml/src/nwb_linkml/adapters/adapter.py +++ b/nwb_linkml/src/nwb_linkml/adapters/adapter.py @@ -61,7 +61,7 @@ class BuildResult: return out_str -T = TypeVar('T', Dataset, Attribute, Schema, Group) +T = TypeVar('T', Dataset, Attribute, Schema, Group, BaseModel) Ts = TypeVarTuple('Ts') class Adapter(BaseModel): diff --git a/nwb_linkml/src/nwb_linkml/adapters/namespaces.py b/nwb_linkml/src/nwb_linkml/adapters/namespaces.py index 66615ce..20dc335 100644 --- a/nwb_linkml/src/nwb_linkml/adapters/namespaces.py +++ b/nwb_linkml/src/nwb_linkml/adapters/namespaces.py @@ -21,7 +21,7 @@ from nwb_schema_language import Namespaces from nwb_linkml.adapters.adapter import Adapter, BuildResult from nwb_linkml.adapters.schema import SchemaAdapter from nwb_linkml.lang_elements import NwbLangSchema -from nwb_linkml.providers.git import DEFAULT_REPOS + from nwb_linkml.ui import AdapterProgress @@ -47,6 +47,7 @@ class NamespacesAdapter(Adapter): with hdmf-common) """ from nwb_linkml.io import schema as schema_io + from nwb_linkml.providers.git import DEFAULT_REPOS ns_adapter = schema_io.load_namespace_adapter(path) # try and find imported schema diff --git a/nwb_linkml/src/nwb_linkml/providers/git.py b/nwb_linkml/src/nwb_linkml/providers/git.py index 8130882..4cc3490 100644 --- a/nwb_linkml/src/nwb_linkml/providers/git.py +++ b/nwb_linkml/src/nwb_linkml/providers/git.py @@ -209,8 +209,7 @@ class GitRepo: try: # check our commit, this also checks if we're a git repo if self.active_commit != self.commit and self.commit is not None: - warnings.warn('At wrong commit') - return False + self.commit = self.commit except GitError: return False diff --git a/nwb_linkml/tests/fixtures.py b/nwb_linkml/tests/fixtures.py index 162257e..2242a3c 100644 --- a/nwb_linkml/tests/fixtures.py +++ b/nwb_linkml/tests/fixtures.py @@ -1,11 +1,13 @@ import pytest import os -from typing import NamedTuple, Optional +from typing import NamedTuple, Optional, List, Dict +from dataclasses import dataclass, field from linkml_runtime.dumpers import yaml_dumper from nwb_linkml.io import schema as io from nwb_linkml.adapters.namespaces import NamespacesAdapter +from nwb_schema_language import Schema, Group, Dataset, Attribute from linkml_runtime.linkml_model import SchemaDefinition, ClassDefinition, SlotDefinition, Prefix, TypeDefinition import shutil from pathlib import Path @@ -65,7 +67,9 @@ def data_dir() -> Path: path = Path(__file__).parent.resolve() / 'data' return path -class TestSchemas(NamedTuple): +@dataclass +class TestSchemas(): + __test__ = False core: SchemaDefinition imported: SchemaDefinition namespace: SchemaDefinition @@ -243,12 +247,51 @@ def linkml_schema(tmp_output_dir_mod, linkml_schema_bare) -> TestSchemas: imported_path = test_schema_path / 'imported.yaml' namespace_path = test_schema_path / 'namespace.yaml' - schema.core_path = core_path, - schema.imported_path = imported_path, - schema.namespace_path = namespace_path, + schema.core_path = core_path + schema.imported_path = imported_path + schema.namespace_path = namespace_path yaml_dumper.dump(schema.core, schema.core_path) yaml_dumper.dump(schema.imported, schema.imported_path) yaml_dumper.dump(schema.namespace, schema.namespace_path) return schema + +@dataclass +class NWBSchemaTest(): + datasets: Dict[str, Dataset] = field(default_factory=dict) + groups: Dict[str, Group] = field(default_factory=dict) + +@pytest.fixture() +def nwb_schema() -> NWBSchemaTest: + """Minimal NWB schema for testing""" + image = Dataset( + neurodata_type_def="Image", + dtype="numeric", + neurodata_type_inc="NWBData", + dims=[['x', 'y'], ['x', 'y', 'r, g, b'], ['x', 'y', 'r, g, b, a']], + shape=[[None, None], [None, None, 3], [None, None, 4]], + doc="An image!", + attributes = [ + Attribute(dtype="float32", name="resolution", doc="resolution!"), + Attribute(dtype="text", name="description", doc='Description!') + ] + ) + images = Group( + neurodata_type_def='Images', + neurodata_type_inc='NWBDataInterface', + default_name="Images", + doc='Images!', + attributes=[ + Attribute(dtype="text", name='description', doc="description!") + ], + datasets=[ + Dataset(neurodata_type_inc='Image', quantity="+", doc="images!"), + Dataset(neurodata_type_inc='ImageReferences', + name='order_of_images', + doc="Image references!", + quantity='?' + ) + ] + ) + return NWBSchemaTest(datasets=[image], groups=[images]) diff --git a/nwb_linkml/tests/test_adapters/test_adapter_classes.py b/nwb_linkml/tests/test_adapters/test_adapter_classes.py new file mode 100644 index 0000000..a4bd8d2 --- /dev/null +++ b/nwb_linkml/tests/test_adapters/test_adapter_classes.py @@ -0,0 +1,9 @@ +import pytest + +from ..fixtures import linkml_schema_bare, linkml_schema, nwb_schema + +from nwb_linkml.adapters import DatasetAdapter, ClassAdapter + +def test_build_base(nwb_schema): + + pass \ No newline at end of file diff --git a/nwb_linkml/tests/test_adapters/test_adapter_dataset.py b/nwb_linkml/tests/test_adapters/test_adapter_dataset.py index d835e88..be35b6c 100644 --- a/nwb_linkml/tests/test_adapters/test_adapter_dataset.py +++ b/nwb_linkml/tests/test_adapters/test_adapter_dataset.py @@ -1,4 +1,10 @@ +import pdb + import pytest -def test_nothing(): +from ..fixtures import nwb_core_fixture + +from nwb_linkml.adapters import DatasetAdapter + +def test_nothing(nwb_core_fixture): pass \ No newline at end of file diff --git a/nwb_linkml/tests/test_generators/test_generator_pydantic.py b/nwb_linkml/tests/test_generators/test_generator_pydantic.py index 58a808c..3dcb1ba 100644 --- a/nwb_linkml/tests/test_generators/test_generator_pydantic.py +++ b/nwb_linkml/tests/test_generators/test_generator_pydantic.py @@ -27,6 +27,7 @@ class TestModules(TypedDict): namespace: ModuleType split: bool +TestModules.__test__ = False def generate_and_import(linkml_schema:TestSchemas, split:bool, generator_kwargs:Optional[dict]=None) -> TestModules: if generator_kwargs is None: