Skip to content

Commit

Permalink
Add test for add_trial_column
Browse files Browse the repository at this point in the history
  • Loading branch information
rly authored Mar 14, 2024
1 parent 953290d commit 809b4e6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# PyNWB Changelog

## PyNWB 2.6.1 (Upcoming)

### Bug fixes
- Fix bug where extra keyword arguments could not be passed to `NWBFile.add_{x}_column`` for use in custom `VectorData`` classes. @rly [#1861](https://github.com/NeurodataWithoutBorders/pynwb/pull/1861)

## PyNWB 2.6.0 (February 21, 2024)

### Enhancements and minor changes
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from datetime import datetime, timedelta
from dateutil.tz import tzlocal, tzutc

from hdmf.common import VectorData
from pynwb import NWBFile, TimeSeries, NWBHDF5IO
from pynwb.base import Image, Images
from pynwb.file import Subject, ElectrodeTable, _add_missing_timezone
Expand Down Expand Up @@ -222,6 +223,27 @@ def test_add_trial_column(self):
self.nwbfile.add_trial_column('trial_type', 'the type of trial')
self.assertEqual(self.nwbfile.trials.colnames, ('start_time', 'stop_time', 'trial_type'))

def test_add_trial_column_custom_class(self):
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

self.nwbfile.add_trial_column(
name="test",
description="test",
col_cls=SubVectorData,
extra_kwarg="test_extra_kwarg"
)
self.assertEqual(self.nwbfile.trials["test"].extra_kwarg, "test_extra_kwarg")

def test_add_trial(self):
self.nwbfile.add_trial(start_time=10.0, stop_time=20.0)
self.assertEqual(len(self.nwbfile.trials), 1)
Expand Down

0 comments on commit 809b4e6

Please sign in to comment.