|
1 | 1 | import os |
2 | | -from unittest.mock import Mock |
| 2 | +from datetime import datetime |
3 | 3 |
|
4 | 4 | import pynwb |
5 | | -from pynwb import NWBHDF5IO, ProcessingModule |
6 | | - |
7 | | -from datetime import datetime |
8 | 5 | from dateutil.tz import tzlocal |
9 | 6 | from pynwb import NWBFile |
10 | | -from pynwb.behavior import BehavioralTimeSeries |
| 7 | +from pynwb import NWBHDF5IO, ProcessingModule |
| 8 | +from pynwb.behavior import BehavioralEvents |
11 | 9 | from pynwb.device import Device |
12 | 10 | from pynwb.testing import TestCase |
13 | 11 |
|
@@ -139,34 +137,41 @@ def test_read_nwb_camera_device_successfully(self): |
139 | 137 | self.delete_nwb('camera_device') |
140 | 138 |
|
141 | 139 | def test_read_nwb_nwb_image_series_successfully(self): |
142 | | - mock_device_1 = Mock(spec=Device) |
143 | | - mock_device_2 = Mock(spec=Device) |
| 140 | + device_1 = Device('device1') |
| 141 | + device_2 = Device('device2') |
144 | 142 | mock_timestamps = [1, 2, 3] |
145 | | - mock_external_file = [] |
| 143 | + mock_external_file = ['some file'] |
146 | 144 |
|
147 | 145 | nwb_image_series = NwbImageSeries( |
148 | 146 | name='NwbImageSeries1', |
149 | 147 | timestamps=mock_timestamps, |
150 | 148 | external_file=mock_external_file, |
151 | | - devices=[mock_device_1, mock_device_2] |
| 149 | + devices=[device_1, device_2] |
152 | 150 | ) |
153 | | - behavioral_time_series = BehavioralTimeSeries(name="ImageSeries") |
| 151 | + |
| 152 | + behavioral_time_series = BehavioralEvents(name="BehavioralTimeSeries") |
154 | 153 | behavioral_time_series.add_timeseries(nwb_image_series) |
155 | | - processing_module = ProcessingModule(name='PM_ImageSeries', description='') |
| 154 | + processing_module = ProcessingModule(name='ProcessingModule', description='') |
| 155 | + processing_module.add_data_interface(behavioral_time_series) |
156 | 156 | self.nwb_file_content.add_processing_module(processing_module) |
157 | | - self.nwb_file_content.processing['PM_ImageSeries'].add(behavioral_time_series) |
| 157 | + |
| 158 | + self.nwb_file_content.add_stimulus_template(nwb_image_series) |
158 | 159 |
|
159 | 160 | nwb_file_handler = NWBHDF5IO('nwb_image_series.nwb', mode='w') |
160 | 161 | nwb_file_handler.write(self.nwb_file_content) |
161 | | - # nwb_file_handler.close() |
162 | | - # |
163 | | - # self.assertTrue(os.path.exists('nwb_image_series.nwb')) |
164 | | - # with pynwb.NWBHDF5IO('nwb_image_series.nwb', 'r', load_namespaces=True) as nwb_file_handler: |
165 | | - # nwb_file = nwb_file_handler.read() |
166 | | - # print(nwb_file.processing['PM_ImageSeries']) |
167 | | - # self.assertContainerEqual(nwb_file.processing['PM_ImageSeries'], nwb_image_series) |
168 | | - # |
169 | | - # self.delete_nwb('nwb_image_series') |
| 162 | + nwb_file_handler.close() |
| 163 | + |
| 164 | + self.assertTrue(os.path.exists('nwb_image_series.nwb')) |
| 165 | + with pynwb.NWBHDF5IO('nwb_image_series.nwb', 'r', load_namespaces=True) as nwb_file_handler: |
| 166 | + nwb_file = nwb_file_handler.read() |
| 167 | + self.assertContainerEqual(nwb_file.stimulus_template['NwbImageSeries1'], nwb_image_series) |
| 168 | + self.assertContainerEqual( |
| 169 | + nwb_file.processing['ProcessingModule'].data_interfaces['BehavioralTimeSeries']. |
| 170 | + time_series['NwbImageSeries1'], |
| 171 | + nwb_image_series |
| 172 | + ) |
| 173 | + |
| 174 | + self.delete_nwb('nwb_image_series') |
170 | 175 |
|
171 | 176 | def test_read_nwb_nwb_electrode_group_successfully(self): |
172 | 177 | device = Device('device_0') |
|
0 commit comments