Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rly committed Apr 25, 2024
1 parent f344646 commit 9bfff85
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 25 deletions.
2 changes: 0 additions & 2 deletions src/pynwb/io/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ def parse_datetime(datestr):
:param datestr: str
:return: datetime.datetime or datetime.date
"""
if datestr is None:
return None
if isinstance(datestr, bytes):
datestr = datestr.decode("utf-8")
dt = datetime.datetime.fromisoformat(datestr)
Expand Down
2 changes: 1 addition & 1 deletion src/pynwb/testing/mock/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def mock_NWBFile(
session_description: str = 'session_description',
identifier: Optional[str] = None,
session_start_time: datetime = datetime(1970, 1, 1, tzinfo=tzlocal()),
session_start_time: datetime = datetime(1970, 1, 1),
**kwargs
):
return NWBFile(
Expand Down
6 changes: 3 additions & 3 deletions src/pynwb/testing/testh5io.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def getContainer(self, nwbfile):

def setUp(self):
self.container = self.setUpContainer()
self.start_time = datetime(1971, 1, 1, 12, tzinfo=tzutc())
self.create_date = datetime(2018, 4, 15, 12, tzinfo=tzlocal())
self.start_time = datetime(1971, 1, 1, 12)
self.create_date = datetime(2018, 4, 15, 12)
self.container_type = self.container.__class__.__name__
self.filename = 'test_%s.nwb' % self.container_type
self.export_filename = 'test_export_%s.nwb' % self.container_type
Expand Down Expand Up @@ -226,7 +226,7 @@ def setUp(self):
container_type = self.getContainerType().replace(" ", "_")
session_description = 'A file to test writing and reading a %s' % container_type
identifier = 'TEST_%s' % container_type
session_start_time = datetime(1971, 1, 1, 12, tzinfo=tzutc())
session_start_time = datetime(1971, 1, 1, 12)
self.nwbfile = NWBFile(
session_description=session_description,
identifier=identifier,
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/hdf5/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_timestamps_linking(self):
tsa = TimeSeries(name='a', data=np.linspace(0, 1, 1000), timestamps=np.arange(1000.), unit='m')
tsb = TimeSeries(name='b', data=np.linspace(0, 1, 1000), timestamps=tsa, unit='m')
nwbfile = NWBFile(identifier='foo',
session_start_time=datetime(2017, 5, 1, 12, 0, 0, tzinfo=tzlocal()),
session_start_time=datetime(2017, 5, 1, 12, 0, 0),
session_description='bar')
nwbfile.add_acquisition(tsa)
nwbfile.add_acquisition(tsb)
Expand All @@ -52,7 +52,7 @@ def test_data_linking(self):
tsb = TimeSeries(name='b', data=tsa, timestamps=np.arange(1000.), unit='m')
tsc = TimeSeries(name='c', data=tsb, timestamps=np.arange(1000.), unit='m')
nwbfile = NWBFile(identifier='foo',
session_start_time=datetime(2017, 5, 1, 12, 0, 0, tzinfo=tzlocal()),
session_start_time=datetime(2017, 5, 1, 12, 0, 0),
session_description='bar')
nwbfile.add_acquisition(tsa)
nwbfile.add_acquisition(tsb)
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/hdf5/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class TestAppend(TestCase):
def setUp(self):
self.nwbfile = NWBFile(session_description='hi',
identifier='hi',
session_start_time=datetime(1970, 1, 1, 12, tzinfo=tzutc()))
session_start_time=datetime(1970, 1, 1, 12))
self.path = "test_append.nwb"

def tearDown(self):
Expand Down Expand Up @@ -312,7 +312,7 @@ class TestH5DataIO(TestCase):
def setUp(self):
self.nwbfile = NWBFile(session_description='a',
identifier='b',
session_start_time=datetime(1970, 1, 1, 12, tzinfo=tzutc()))
session_start_time=datetime(1970, 1, 1, 12))
self.path = "test_pynwb_io_hdf5_h5dataIO.h5"

def tearDown(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/hdf5/test_modular_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def setUp(self):
self.link_filename = os.path.join(os.getcwd(), 'test_time_series_modular_link.nwb')

# Make the data container file write
self.start_time = datetime(1971, 1, 1, 12, tzinfo=tzutc())
self.start_time = datetime(1971, 1, 1, 12)
self.data = np.arange(2000).reshape((1000, 2))
self.timestamps = np.linspace(0, 1, 1000)
# The container before roundtrip
Expand Down
31 changes: 30 additions & 1 deletion tests/integration/hdf5/test_nwbfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ def setUp(self):
""" Set up an NWBFile object with an acquisition TimeSeries, analysis TimeSeries, and a processing module """
self.start_time = datetime(1970, 1, 1, 12, tzinfo=tzutc())
self.ref_time = datetime(1979, 1, 1, 0, tzinfo=tzutc())
self.create_date = datetime(2017, 4, 15, 12, tzinfo=tzlocal())
# try some dates with/without timezone and time
self.create_date = [
datetime(2017, 5, 1, 12, tzinfo=tzlocal()),
datetime(2017, 5, 2, 13),
datetime(2017, 5, 2),
]
self.manager = get_manager()
self.filename = 'test_nwbfileio.h5'
self.nwbfile = NWBFile(session_description='a test NWB File',
Expand Down Expand Up @@ -327,6 +332,30 @@ def getContainer(self, nwbfile):
return nwbfile.subject


class TestSubjectMinimalSetIO(NWBH5IOMixin, TestCase):

def setUpContainer(self):
""" Return the test Subject """
return Subject(
age="P90D",
description="An unfortunate rat",
genotype="WT",
sex="M",
species="Rattus norvegicus",
subject_id="RAT123",
weight="2 kg",
strain="my_strain",
)

def addContainer(self, nwbfile):
""" Add the test Subject to the given NWBFile """
nwbfile.subject = self.container

def getContainer(self, nwbfile):
""" Return the test Subject from the given NWBFile """
return nwbfile.subject


class TestEmptySubjectIO(TestSubjectIO):

def setUpContainer(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_epoch.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_dataframe_roundtrip_drop_ts(self):
self.assertEqual(obtained.loc[2, 'foo'], df.loc[2, 'foo'])

def test_no_tags(self):
nwbfile = NWBFile("a file with header data", "NB123A", datetime(1970, 1, 1, tzinfo=tz.tzutc()))
nwbfile = NWBFile("a file with header data", "NB123A", datetime(1970, 1, 1))
df = self.get_dataframe()
for i, row in df.iterrows():
nwbfile.add_epoch(start_time=row['start_time'], stop_time=row['stop_time'])
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def __init__(self, **kwargs):
super().__init__(**kwargs)
self.test_attr = test_attr

nwbfile = NWBFile("a file with header data", "NB123A", datetime(2017, 5, 1, 12, 0, 0, tzinfo=tzlocal()))
nwbfile = NWBFile("a file with header data", "NB123A", datetime(2017, 5, 1, 12, 0, 0))

nwbfile.add_lab_meta_data(MyTestMetaData(name='test_name', test_attr=5.))

Expand All @@ -128,7 +128,7 @@ def test_lab_meta_auto(self):

MyTestMetaData = get_class('MyTestMetaData', self.prefix)

nwbfile = NWBFile("a file with header data", "NB123A", datetime(2017, 5, 1, 12, 0, 0, tzinfo=tzlocal()))
nwbfile = NWBFile("a file with header data", "NB123A", datetime(2017, 5, 1, 12, 0, 0))

nwbfile.add_lab_meta_data(MyTestMetaData(name='test_name', test_attr=5.))

Expand Down
7 changes: 4 additions & 3 deletions tests/unit/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ class NWBFileTest(TestCase):
def setUp(self):
self.start = datetime(2017, 5, 1, 12, 0, 0, tzinfo=tzlocal())
self.ref_time = datetime(1979, 1, 1, 0, tzinfo=tzutc())
# try some dates with/without timezone and time
self.create = [datetime(2017, 5, 1, 12, tzinfo=tzlocal()),
datetime(2017, 5, 2, 13, 0, 0, 1, tzinfo=tzutc()),
datetime(2017, 5, 2, 14, tzinfo=tzutc())]
datetime(2017, 5, 2, 13),
datetime(2017, 5, 2)]
self.path = 'nwbfile_test.h5'
self.nwbfile = NWBFile(session_description='a test session description for a test NWBFile',
identifier='FILE123',
Expand Down Expand Up @@ -533,7 +534,7 @@ def setUp(self):
date_of_birth=datetime(2017, 5, 1, 12, tzinfo=tzlocal()),
strain='my_strain',
)
self.start = datetime(2017, 5, 1, 12, tzinfo=tzlocal())
self.start = datetime(2017, 5, 1, 12)
self.path = 'nwbfile_test.h5'
self.nwbfile = NWBFile(
'a test session description for a test NWBFile',
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/test_icephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_sweep_table_depractation_warn(self):
_ = NWBFile(
session_description='NWBFile icephys test',
identifier='NWB123', # required
session_start_time=datetime(2017, 4, 3, 11, tzinfo=tzlocal()),
session_start_time=datetime(2017, 4, 3, 11),
ic_electrodes=[self.icephys_electrode, ],
sweep_table=SweepTable())

Expand All @@ -57,14 +57,14 @@ def test_ic_electrodes_parameter_deprecation(self):
_ = NWBFile(
session_description='NWBFile icephys test',
identifier='NWB123', # required
session_start_time=datetime(2017, 4, 3, 11, tzinfo=tzlocal()),
session_start_time=datetime(2017, 4, 3, 11),
ic_electrodes=[self.icephys_electrode, ])

def test_icephys_electrodes_parameter(self):
nwbfile = NWBFile(
session_description='NWBFile icephys test',
identifier='NWB123', # required
session_start_time=datetime(2017, 4, 3, 11, tzinfo=tzlocal()),
session_start_time=datetime(2017, 4, 3, 11),
icephys_electrodes=[self.icephys_electrode, ])
self.assertEqual(nwbfile.get_icephys_electrode('test_iS'), self.icephys_electrode)

Expand All @@ -73,7 +73,7 @@ def test_add_ic_electrode_deprecation(self):
nwbfile = NWBFile(
session_description='NWBFile icephys test',
identifier='NWB123', # required
session_start_time=datetime(2017, 4, 3, 11, tzinfo=tzlocal()))
session_start_time=datetime(2017, 4, 3, 11))

msg = "NWBFile.add_ic_electrode has been replaced by NWBFile.add_icephys_electrode."
with self.assertWarnsWith(DeprecationWarning, msg):
Expand All @@ -83,7 +83,7 @@ def test_ic_electrodes_attribute_deprecation(self):
nwbfile = NWBFile(
session_description='NWBFile icephys test',
identifier='NWB123', # required
session_start_time=datetime(2017, 4, 3, 11, tzinfo=tzlocal()),
session_start_time=datetime(2017, 4, 3, 11),
icephys_electrodes=[self.icephys_electrode, ])
# make sure NWBFile.ic_electrodes property warns

Expand All @@ -100,7 +100,7 @@ def test_create_ic_electrode_deprecation(self):
nwbfile = NWBFile(
session_description='NWBFile icephys test',
identifier='NWB123', # required
session_start_time=datetime(2017, 4, 3, 11, tzinfo=tzlocal()))
session_start_time=datetime(2017, 4, 3, 11))
device = Device(name='device_name')
msg = "NWBFile.create_ic_electrode has been replaced by NWBFile.create_icephys_electrode."
with self.assertWarnsWith(DeprecationWarning, msg):
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_scratch.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def setUp(self):
self.nwbfile = NWBFile(
session_description='a file to test writing and reading scratch data',
identifier='TEST_scratch',
session_start_time=datetime(2017, 5, 1, 12, 0, 0, tzinfo=tzlocal())
session_start_time=datetime(2017, 5, 1, 12, 0, 0)
)

def test_constructor_list(self):
Expand Down

0 comments on commit 9bfff85

Please sign in to comment.