Skip to content

Commit 534bd17

Browse files
committed
update tests to use kwargs
1 parent 2bb1111 commit 534bd17

File tree

11 files changed

+251
-102
lines changed

11 files changed

+251
-102
lines changed

tests/integration/hdf5/test_image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class TestImageSeriesIO(AcquisitionH5IOMixin, TestCase):
99

1010
def setUpContainer(self):
1111
""" Return a test ImageSeries to read/write """
12-
self.dev1 = Device('dev1')
12+
self.dev1 = Device(name='dev1')
1313
iS = ImageSeries(
1414
name='test_iS',
1515
unit='unit',
@@ -31,7 +31,7 @@ class TestOpticalSeriesIO(NWBH5IOMixin, TestCase):
3131

3232
def setUpContainer(self):
3333
""" Return a test OpticalSeries to read/write """
34-
self.dev1 = Device('dev1')
34+
self.dev1 = Device(name='dev1')
3535
self.optical_series = OpticalSeries(
3636
name='OpticalSeries',
3737
distance=8.,

tests/integration/hdf5/test_misc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class TestUnitsFileIO(NWBH5IOMixin, TestCase):
7575

7676
def setUpContainer(self):
7777
""" Return placeholder Units object. Tested units are added directly to the NWBFile in addContainer """
78-
return Units('placeholder') # this will get ignored
78+
return Units(name='placeholder') # this will get ignored
7979

8080
def addContainer(self, nwbfile):
8181
""" Add units to the given NWBFile """

tests/integration/hdf5/test_nwbfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ class TestEpochsIO(NWBH5IOMixin, TestCase):
261261

262262
def setUpContainer(self):
263263
""" Return placeholder epochs object. Tested epochs are added directly to the NWBFile in addContainer """
264-
return TimeIntervals('epochs')
264+
return TimeIntervals(name='epochs')
265265

266266
def addContainer(self, nwbfile):
267267
""" Add the test epochs to the given NWBFile """

tests/unit/test_ecephys.py

Lines changed: 67 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@
2525

2626
def make_electrode_table():
2727
table = ElectrodeTable()
28-
dev1 = Device('dev1')
29-
group = ElectrodeGroup('tetrode1', 'tetrode description', 'tetrode location', dev1)
28+
dev1 = Device(name='dev1')
29+
group = ElectrodeGroup(name='tetrode1',
30+
description='tetrode description',
31+
location='tetrode location',
32+
device=dev1)
3033
table.add_row(location='CA1', group=group, group_name='tetrode1')
3134
table.add_row(location='CA1', group=group, group_name='tetrode1')
3235
table.add_row(location='CA1', group=group, group_name='tetrode1')
@@ -70,9 +73,10 @@ def test_init(self):
7073

7174
def test_link(self):
7275
table, region = self._create_table_and_region()
73-
ts1 = ElectricalSeries('test_ts1', [0, 1, 2, 3, 4, 5], region, timestamps=[0.0, 0.1, 0.2, 0.3, 0.4, 0.5])
74-
ts2 = ElectricalSeries('test_ts2', ts1, region, timestamps=ts1)
75-
ts3 = ElectricalSeries('test_ts3', ts2, region, timestamps=ts2)
76+
ts1 = ElectricalSeries(name='test_ts1', data=[0, 1, 2, 3, 4, 5], electrodes=region,
77+
timestamps=[0.0, 0.1, 0.2, 0.3, 0.4, 0.5])
78+
ts2 = ElectricalSeries(name='test_ts2', data=ts1, electrodes=region, timestamps=ts1)
79+
ts3 = ElectricalSeries(name='test_ts3', data=ts2, electrodes=region, timestamps=ts2)
7680
self.assertEqual(ts2.data, [0, 1, 2, 3, 4, 5])
7781
self.assertEqual(ts2.timestamps, [0.0, 0.1, 0.2, 0.3, 0.4, 0.5])
7882
self.assertEqual(ts3.data, [0, 1, 2, 3, 4, 5])
@@ -82,7 +86,8 @@ def test_invalid_data_shape(self):
8286
table, region = self._create_table_and_region()
8387
with self.assertRaisesWith(ValueError, ("ElectricalSeries.__init__: incorrect shape for 'data' (got '(2, 2, 2, "
8488
"2)', expected '((None,), (None, None), (None, None, None))')")):
85-
ElectricalSeries('test_ts1', np.ones((2, 2, 2, 2)), region, timestamps=[0.0, 0.1, 0.2, 0.3, 0.4, 0.5])
89+
ElectricalSeries(name='test_ts1', data=np.ones((2, 2, 2, 2)), electrodes=region,
90+
timestamps=[0.0, 0.1, 0.2, 0.3, 0.4, 0.5])
8691

8792
def test_dimensions_warning(self):
8893
table, region = self._create_table_and_region()
@@ -177,7 +182,7 @@ def test_incorrect_timestamps(self):
177182
class ElectrodeGroupConstructor(TestCase):
178183

179184
def test_init(self):
180-
dev1 = Device('dev1')
185+
dev1 = Device(name='dev1')
181186
group = ElectrodeGroup(name='elec1',
182187
description='electrode description',
183188
location='electrode location',
@@ -191,17 +196,20 @@ def test_init(self):
191196

192197
def test_init_position_array(self):
193198
position = np.array((1, 2, 3), dtype=np.dtype([('x', float), ('y', float), ('z', float)]))
194-
dev1 = Device('dev1')
195-
group = ElectrodeGroup('elec1', 'electrode description', 'electrode location', dev1,
196-
position)
199+
dev1 = Device(name='dev1')
200+
group = ElectrodeGroup(name='elec1',
201+
description='electrode description',
202+
location='electrode location',
203+
device=dev1,
204+
position=position)
197205
self.assertEqual(group.name, 'elec1')
198206
self.assertEqual(group.description, 'electrode description')
199207
self.assertEqual(group.location, 'electrode location')
200208
self.assertEqual(group.device, dev1)
201209
self.assertEqual(group.position, position)
202210

203211
def test_init_position_none(self):
204-
dev1 = Device('dev1')
212+
dev1 = Device(name='dev1')
205213
group = ElectrodeGroup(name='elec1',
206214
description='electrode description',
207215
location='electrode location',
@@ -213,7 +221,7 @@ def test_init_position_none(self):
213221
self.assertIsNone(group.position)
214222

215223
def test_init_position_bad(self):
216-
dev1 = Device('dev1')
224+
dev1 = Device(name='dev1')
217225
with self.assertRaises(ValueError):
218226
ElectrodeGroup(name='elec1',
219227
description='electrode description',
@@ -256,8 +264,11 @@ def test_init(self):
256264
data = list(range(10))
257265
ts = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
258266
table, region = self._create_table_and_region()
259-
eS = ElectricalSeries('test_eS', data, region, timestamps=ts)
260-
eD = EventDetection('detection_method', eS, (1, 2, 3), (0.1, 0.2, 0.3))
267+
eS = ElectricalSeries(name='test_eS', data=data, electrodes=region, timestamps=ts)
268+
eD = EventDetection(detection_method='detection_method',
269+
source_electricalseries=eS,
270+
source_idx=(1, 2, 3),
271+
times=(0.1, 0.2, 0.3))
261272
self.assertEqual(eD.detection_method, 'detection_method')
262273
self.assertEqual(eD.source_electricalseries, eS)
263274
self.assertEqual(eD.source_idx, (1, 2, 3))
@@ -279,7 +290,10 @@ def _create_table_and_region(self):
279290

280291
def test_init(self):
281292
table, region = self._create_table_and_region()
282-
sES = SpikeEventSeries('test_sES', list(range(10)), list(range(10)), region)
293+
sES = SpikeEventSeries(name='test_sES',
294+
data=list(range(10)),
295+
timestamps=list(range(10)),
296+
electrodes=region)
283297

284298
pm = ProcessingModule(name='test_module', description='a test module')
285299
ew = EventWaveform()
@@ -344,7 +358,8 @@ def _create_table_and_region(self):
344358

345359
def test_init(self):
346360
_, region = self._create_table_and_region()
347-
eS = ElectricalSeries('test_eS', [0, 1, 2, 3], region, timestamps=[0.1, 0.2, 0.3, 0.4])
361+
eS = ElectricalSeries(name='test_eS', data=[0, 1, 2, 3],
362+
electrodes=region, timestamps=[0.1, 0.2, 0.3, 0.4])
348363
msg = (
349364
"The linked table for DynamicTableRegion 'electrodes' does not share "
350365
"an ancestor with the DynamicTableRegion."
@@ -357,7 +372,10 @@ def test_init(self):
357372
def test_add_electrical_series(self):
358373
lfp = LFP()
359374
table, region = self._create_table_and_region()
360-
eS = ElectricalSeries('test_eS', [0, 1, 2, 3], region, timestamps=[0.1, 0.2, 0.3, 0.4])
375+
eS = ElectricalSeries(name='test_eS',
376+
data=[0, 1, 2, 3],
377+
electrodes=region,
378+
timestamps=[0.1, 0.2, 0.3, 0.4])
361379
pm = ProcessingModule(name='test_module', description='a test module')
362380
pm.add(table)
363381
pm.add(lfp)
@@ -379,7 +397,10 @@ def _create_table_and_region(self):
379397

380398
def test_init(self):
381399
_, region = self._create_table_and_region()
382-
eS = ElectricalSeries('test_eS', [0, 1, 2, 3], region, timestamps=[0.1, 0.2, 0.3, 0.4])
400+
eS = ElectricalSeries(name='test_eS',
401+
data=[0, 1, 2, 3],
402+
electrodes=region,
403+
timestamps=[0.1, 0.2, 0.3, 0.4])
383404
msg = (
384405
"The linked table for DynamicTableRegion 'electrodes' does not share "
385406
"an ancestor with the DynamicTableRegion."
@@ -391,7 +412,10 @@ def test_init(self):
391412

392413
def test_add_electrical_series(self):
393414
table, region = self._create_table_and_region()
394-
eS = ElectricalSeries('test_eS', [0, 1, 2, 3], region, timestamps=[0.1, 0.2, 0.3, 0.4])
415+
eS = ElectricalSeries(name='test_eS',
416+
data=[0, 1, 2, 3],
417+
electrodes=region,
418+
timestamps=[0.1, 0.2, 0.3, 0.4])
395419
pm = ProcessingModule(name='test_module', description='a test module')
396420
fe = FilteredEphys()
397421
pm.add(table)
@@ -418,7 +442,10 @@ def test_init(self):
418442
table, region = self._create_table_and_region()
419443
description = ['desc1', 'desc2', 'desc3']
420444
features = [[[0, 1, 2], [3, 4, 5]], [[6, 7, 8], [9, 10, 11]]]
421-
fe = FeatureExtraction(region, description, event_times, features)
445+
fe = FeatureExtraction(electrodes=region,
446+
description=description,
447+
times=event_times,
448+
features=features)
422449
self.assertEqual(fe.description, description)
423450
self.assertEqual(fe.times, event_times)
424451
self.assertEqual(fe.features, features)
@@ -428,26 +455,42 @@ def test_invalid_init_mismatched_event_times(self):
428455
table, region = self._create_table_and_region()
429456
description = ['desc1', 'desc2', 'desc3']
430457
features = [[[0, 1, 2], [3, 4, 5]]]
431-
self.assertRaises(ValueError, FeatureExtraction, region, description, event_times, features)
458+
with self.assertRaises(ValueError):
459+
FeatureExtraction(electrodes=region,
460+
description=description,
461+
times=event_times,
462+
features=features)
432463

433464
def test_invalid_init_mismatched_electrodes(self):
434465
event_times = [1]
435466
table = make_electrode_table()
436467
region = DynamicTableRegion(name='electrodes', data=[0], description='the first electrode', table=table)
437468
description = ['desc1', 'desc2', 'desc3']
438469
features = [[[0, 1, 2], [3, 4, 5]]]
439-
self.assertRaises(ValueError, FeatureExtraction, region, description, event_times, features)
470+
with self.assertRaises(ValueError):
471+
FeatureExtraction(electrodes=region,
472+
description=description,
473+
times=event_times,
474+
features=features)
440475

441476
def test_invalid_init_mismatched_description(self):
442477
event_times = [1]
443478
table, region = self._create_table_and_region()
444479
description = ['desc1', 'desc2', 'desc3', 'desc4'] # Need 3 descriptions but give 4
445480
features = [[[0, 1, 2], [3, 4, 5]]]
446-
self.assertRaises(ValueError, FeatureExtraction, region, description, event_times, features)
481+
with self.assertRaises(ValueError):
482+
FeatureExtraction(electrodes=region,
483+
description=description,
484+
times=event_times,
485+
features=features)
447486

448487
def test_invalid_init_mismatched_description2(self):
449488
event_times = [1]
450489
table, region = self._create_table_and_region()
451490
description = ['desc1', 'desc2', 'desc3']
452491
features = [[0, 1, 2], [3, 4, 5]] # Need 3D feature array but give only 2D array
453-
self.assertRaises(ValueError, FeatureExtraction, region, description, event_times, features)
492+
with self.assertRaises(ValueError):
493+
FeatureExtraction(electrodes=region,
494+
description=description,
495+
times=event_times,
496+
features=features)

tests/unit/test_epoch_legacy.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class TestTimeIntervalsIO(NWBH5IOMixin, TestCase):
2121

2222
def setUpContainer(self):
2323
""" Return placeholder epochs object. Tested epochs are added directly to the NWBFile in addContainer """
24-
return TimeIntervals('epochs')
24+
return TimeIntervals(name='epochs')
2525

2626
def addContainer(self, nwbfile):
2727
""" Add the test epochs to the given NWBFile """
@@ -62,7 +62,8 @@ def getContainer(self, nwbfile):
6262
def test_legacy_format(self):
6363
description = 'a file to test writing and reading a %s' % self.container_type
6464
identifier = 'TEST_%s' % self.container_type
65-
nwbfile = NWBFile(description, identifier, self.start_time, file_create_date=self.create_date)
65+
nwbfile = NWBFile(session_description=description, identifier=identifier,
66+
session_start_time=self.start_time, file_create_date=self.create_date)
6667
self.addContainer(nwbfile)
6768

6869
# write the file

0 commit comments

Comments
 (0)