fix tests, cant assign to tuple

This commit is contained in:
sneakers-the-rat 2023-10-09 18:59:53 -07:00
parent 6f32a5bfd3
commit a7b0f8880e
9 changed files with 77 additions and 11 deletions

View file

@ -76,9 +76,15 @@ addopts = [
"--cov=nwb_linkml", "--cov=nwb_linkml",
"--cov-append", "--cov-append",
"--cov-config=.coveragerc", "--cov-config=.coveragerc",
"--doctest-modules" "--doctest-modules",
"--ignore=tests/__tmp__"
] ]
testpaths = [ testpaths = [
"tests", "tests",
'nwb_linkml/tests' 'nwb_linkml/tests'
] ]
doctest_optionflags = "NORMALIZE_WHITESPACE"
filterwarnings = [
"ignore:Deprecated NumPy 1.24:DeprecationWarning",
"ignore:parse_obj:pydantic.PydanticDeprecatedSince20"
]

View file

@ -2,5 +2,6 @@ from nwb_linkml.adapters.adapter import Adapter, BuildResult
from nwb_linkml.adapters.namespaces import NamespacesAdapter from nwb_linkml.adapters.namespaces import NamespacesAdapter
from nwb_linkml.adapters.classes import ClassAdapter from nwb_linkml.adapters.classes import ClassAdapter
from nwb_linkml.adapters.group import GroupAdapter from nwb_linkml.adapters.group import GroupAdapter
from nwb_linkml.adapters.dataset import DatasetAdapter
from nwb_linkml.adapters.schema import SchemaAdapter from nwb_linkml.adapters.schema import SchemaAdapter

View file

@ -61,7 +61,7 @@ class BuildResult:
return out_str return out_str
T = TypeVar('T', Dataset, Attribute, Schema, Group) T = TypeVar('T', Dataset, Attribute, Schema, Group, BaseModel)
Ts = TypeVarTuple('Ts') Ts = TypeVarTuple('Ts')
class Adapter(BaseModel): class Adapter(BaseModel):

View file

@ -21,7 +21,7 @@ from nwb_schema_language import Namespaces
from nwb_linkml.adapters.adapter import Adapter, BuildResult from nwb_linkml.adapters.adapter import Adapter, BuildResult
from nwb_linkml.adapters.schema import SchemaAdapter from nwb_linkml.adapters.schema import SchemaAdapter
from nwb_linkml.lang_elements import NwbLangSchema from nwb_linkml.lang_elements import NwbLangSchema
from nwb_linkml.providers.git import DEFAULT_REPOS
from nwb_linkml.ui import AdapterProgress from nwb_linkml.ui import AdapterProgress
@ -47,6 +47,7 @@ class NamespacesAdapter(Adapter):
with hdmf-common) with hdmf-common)
""" """
from nwb_linkml.io import schema as schema_io 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) ns_adapter = schema_io.load_namespace_adapter(path)
# try and find imported schema # try and find imported schema

View file

@ -209,8 +209,7 @@ class GitRepo:
try: try:
# check our commit, this also checks if we're a git repo # check our commit, this also checks if we're a git repo
if self.active_commit != self.commit and self.commit is not None: if self.active_commit != self.commit and self.commit is not None:
warnings.warn('At wrong commit') self.commit = self.commit
return False
except GitError: except GitError:
return False return False

View file

@ -1,11 +1,13 @@
import pytest import pytest
import os 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 linkml_runtime.dumpers import yaml_dumper
from nwb_linkml.io import schema as io from nwb_linkml.io import schema as io
from nwb_linkml.adapters.namespaces import NamespacesAdapter 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 from linkml_runtime.linkml_model import SchemaDefinition, ClassDefinition, SlotDefinition, Prefix, TypeDefinition
import shutil import shutil
from pathlib import Path from pathlib import Path
@ -65,7 +67,9 @@ def data_dir() -> Path:
path = Path(__file__).parent.resolve() / 'data' path = Path(__file__).parent.resolve() / 'data'
return path return path
class TestSchemas(NamedTuple): @dataclass
class TestSchemas():
__test__ = False
core: SchemaDefinition core: SchemaDefinition
imported: SchemaDefinition imported: SchemaDefinition
namespace: 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' imported_path = test_schema_path / 'imported.yaml'
namespace_path = test_schema_path / 'namespace.yaml' namespace_path = test_schema_path / 'namespace.yaml'
schema.core_path = core_path, schema.core_path = core_path
schema.imported_path = imported_path, schema.imported_path = imported_path
schema.namespace_path = namespace_path, schema.namespace_path = namespace_path
yaml_dumper.dump(schema.core, schema.core_path) yaml_dumper.dump(schema.core, schema.core_path)
yaml_dumper.dump(schema.imported, schema.imported_path) yaml_dumper.dump(schema.imported, schema.imported_path)
yaml_dumper.dump(schema.namespace, schema.namespace_path) yaml_dumper.dump(schema.namespace, schema.namespace_path)
return schema 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])

View file

@ -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

View file

@ -1,4 +1,10 @@
import pdb
import pytest import pytest
def test_nothing(): from ..fixtures import nwb_core_fixture
from nwb_linkml.adapters import DatasetAdapter
def test_nothing(nwb_core_fixture):
pass pass

View file

@ -27,6 +27,7 @@ class TestModules(TypedDict):
namespace: ModuleType namespace: ModuleType
split: bool split: bool
TestModules.__test__ = False
def generate_and_import(linkml_schema:TestSchemas, split:bool, generator_kwargs:Optional[dict]=None) -> TestModules: def generate_and_import(linkml_schema:TestSchemas, split:bool, generator_kwargs:Optional[dict]=None) -> TestModules:
if generator_kwargs is None: if generator_kwargs is None: