-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into workflow-updates
- Loading branch information
Showing
10 changed files
with
200 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from hdmf.build import BuildManager | ||
from hdmf.common import VectorData | ||
from hdmf.utils import docval, get_docval, popargs | ||
|
||
from pynwb import NWBFile | ||
from pynwb.spec import NWBDatasetSpec, NWBAttributeSpec | ||
from pynwb.testing import NWBH5IOFlexMixin, TestCase | ||
|
||
from ..helpers.utils import create_test_extension | ||
|
||
|
||
class TestDynamicTableCustomColumnWithArgs(NWBH5IOFlexMixin, TestCase): | ||
|
||
class SubVectorData(VectorData): | ||
__fields__ = ('extra_kwarg', ) | ||
|
||
@docval( | ||
*get_docval(VectorData.__init__, "name", "description", "data"), | ||
{'name': 'extra_kwarg', 'type': 'str', 'doc': 'An extra kwarg.'}, | ||
) | ||
def __init__(self, **kwargs): | ||
extra_kwarg = popargs('extra_kwarg', kwargs) | ||
super().__init__(**kwargs) | ||
self.extra_kwarg = extra_kwarg | ||
|
||
def setUp(self): | ||
"""Set up an extension with a custom VectorData column.""" | ||
|
||
spec = NWBDatasetSpec( | ||
neurodata_type_def='SubVectorData', | ||
neurodata_type_inc='VectorData', | ||
doc='A custom VectorData column.', | ||
dtype='text', | ||
shape=(None,), | ||
attributes=[ | ||
NWBAttributeSpec( | ||
name="extra_kwarg", | ||
doc='An extra kwarg.', | ||
dtype='text' | ||
), | ||
], | ||
) | ||
|
||
self.type_map = create_test_extension([spec], {"SubVectorData": self.SubVectorData}) | ||
self.manager = BuildManager(self.type_map) | ||
super().setUp() | ||
|
||
def get_manager(self): | ||
return self.manager | ||
|
||
def getContainerType(self): | ||
return "TrialsWithCustomColumnsWithArgs" | ||
|
||
def addContainer(self): | ||
""" Add the test DynamicTable to the given NWBFile """ | ||
self.nwbfile.add_trial_column( | ||
name="test", | ||
description="test", | ||
col_cls=self.SubVectorData, | ||
extra_kwarg="test_extra_kwarg" | ||
) | ||
self.nwbfile.add_trial(start_time=1.0, stop_time=2.0, test="test_data") | ||
|
||
def getContainer(self, nwbfile: NWBFile): | ||
return nwbfile.trials["test"] | ||
|
||
def test_roundtrip(self): | ||
super().test_roundtrip() | ||
assert isinstance(self.read_container, self.SubVectorData) | ||
assert self.read_container.extra_kwarg == "test_extra_kwarg" | ||
|
||
def test_roundtrip_export(self): | ||
super().test_roundtrip_export() | ||
assert isinstance(self.read_container, self.SubVectorData) | ||
assert self.read_container.extra_kwarg == "test_extra_kwarg" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import os | ||
from pynwb.base import TimeSeriesReference | ||
from pynwb import NWBHDF5IO | ||
from pynwb.testing import TestCase | ||
from pynwb.testing.mock.file import mock_NWBFile | ||
from pynwb.testing.mock.base import mock_TimeSeries | ||
|
||
|
||
class TestFileCopy(TestCase): | ||
|
||
def setUp(self): | ||
self.path1 = "test_a.h5" | ||
self.path2 = "test_b.h5" | ||
|
||
def tearDown(self): | ||
if os.path.exists(self.path1): | ||
os.remove(self.path1) | ||
if os.path.exists(self.path2): | ||
os.remove(self.path2) | ||
|
||
def test_copy_file_link_timeintervals_timeseries(self): | ||
"""Test copying a file with a TimeSeriesReference in a TimeIntervals object and reading that copy. | ||
Based on https://github.com/NeurodataWithoutBorders/pynwb/issues/1863 | ||
""" | ||
new_nwb = mock_NWBFile() | ||
test_ts = mock_TimeSeries(name="test_ts", timestamps=[1.0, 2.0, 3.0], data=[1.0, 2.0, 3.0]) | ||
new_nwb.add_acquisition(test_ts) | ||
new_nwb.add_trial(start_time=1.0, stop_time=2.0, timeseries=[test_ts]) | ||
|
||
with NWBHDF5IO(self.path1, 'w') as io: | ||
io.write(new_nwb) | ||
|
||
with NWBHDF5IO(self.path1, 'r') as base_io: | ||
# the TimeIntervals object is copied but the TimeSeriesReferenceVectorData is linked | ||
nwb_add = base_io.read().copy() | ||
with NWBHDF5IO(self.path2, 'w', manager=base_io.manager) as out_io: | ||
out_io.write(nwb_add) | ||
|
||
with NWBHDF5IO(self.path2, 'r') as io: | ||
nwb = io.read() | ||
ts_val = nwb.trials["timeseries"][0][0] | ||
assert isinstance(ts_val, TimeSeriesReference) | ||
assert ts_val.timeseries is nwb.acquisition["test_ts"] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"""Utilities for creating a custom TypeMap for testing so that we don't use the global type map.""" | ||
import tempfile | ||
from pynwb import get_type_map | ||
from pynwb.spec import NWBNamespaceBuilder, export_spec | ||
|
||
|
||
NAMESPACE_NAME = "test_core" | ||
|
||
|
||
def create_test_extension(specs, container_classes, mappers=None): | ||
ns_builder = NWBNamespaceBuilder( | ||
name=NAMESPACE_NAME, | ||
version="0.1.0", | ||
doc="test extension", | ||
) | ||
ns_builder.include_namespace("core") | ||
|
||
output_dir = tempfile.TemporaryDirectory() | ||
export_spec(ns_builder, specs, output_dir.name) | ||
|
||
# this will copy the global pynwb TypeMap and add the extension types to the copy | ||
type_map = get_type_map(f"{output_dir.name}/{NAMESPACE_NAME}.namespace.yaml") | ||
for type_name, container_cls in container_classes.items(): | ||
type_map.register_container_type(NAMESPACE_NAME, type_name, container_cls) | ||
if mappers: | ||
for type_name, mapper_cls in mappers.items(): | ||
container_cls = container_classes[type_name] | ||
type_map.register_map(container_cls, mapper_cls) | ||
|
||
output_dir.cleanup() | ||
return type_map |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters