From bb2d82da7f4edde53b83f5ebeea4a4d97a91e182 Mon Sep 17 00:00:00 2001 From: Steph Prince <40640337+stephprince@users.noreply.github.com> Date: Sat, 21 Dec 2024 15:03:35 -0800 Subject: [PATCH] remove warnings on construct for deprecations --- src/pynwb/core.py | 6 ++- src/pynwb/file.py | 13 ++++++- tests/integration/hdf5/test_ecephys.py | 37 +++++++------------ tests/integration/hdf5/test_icephys.py | 40 +++++++------------- tests/unit/test_base.py | 12 ++++-- tests/unit/test_ecephys.py | 12 +++--- tests/unit/test_file.py | 43 ++++++---------------- tests/unit/test_icephys.py | 34 ++--------------- tests/unit/test_icephys_metadata_tables.py | 38 ++++++------------- tests/unit/test_image.py | 16 ++++---- tests/unit/test_ophys.py | 12 +++--- tests/unit/test_scratch.py | 16 ++++---- 12 files changed, 108 insertions(+), 171 deletions(-) diff --git a/src/pynwb/core.py b/src/pynwb/core.py index deb3a8c22..73327f8f8 100644 --- a/src/pynwb/core.py +++ b/src/pynwb/core.py @@ -155,13 +155,15 @@ def __init__(self, **kwargs): @property def notes(self): - warn('Use of ScratchData.notes has been deprecated and will be removed in PyNWB 4.0. Use ScratchData.description instead.', DeprecationWarning) + warn(("Use of ScratchData.notes has been deprecated and will be removed in PyNWB 4.0. " + "Use ScratchData.description instead."), DeprecationWarning) return self.description @notes.setter def notes(self, value): self._error_on_new_pass_on_construct( - error_msg='Use of ScratchData.notes has been deprecated and will be removed in PyNWB 4.0. Use ScratchData.description instead.') + error_msg=("Use of ScratchData.notes has been deprecated and will be removed in PyNWB 4.0. " + "Use ScratchData.description instead.")) self.description = value diff --git a/src/pynwb/file.py b/src/pynwb/file.py index c5e6db889..b670b460b 100644 --- a/src/pynwb/file.py +++ b/src/pynwb/file.py @@ -561,6 +561,17 @@ def objects(self): def epoch_tags(self): return set(self.epochs.tags[:]) if self.epochs is not None else set() + @property + def icephys_filtering(self): + return self.fields.get('icephys_filtering') + + @icephys_filtering.setter + def icephys_filtering(self, val): + if val is not None: + self._error_on_new_warn_on_construct("Use of icephys_filtering is deprecated. " + "Use the IntracellularElectrode.filtering field instead") + self.fields['icephys_filtering'] = val + def __check_epochs(self): if self.epochs is None: self.epochs = TimeIntervals(name='epochs', description='experimental epochs') @@ -1017,7 +1028,7 @@ def add_scratch(self, **kwargs): data, name, notes, table_description, description = getargs('data', 'name', 'notes', 'table_description', 'description', kwargs) if notes is not None or table_description != '': - warn(('Use of the `notes` or `table_description` argument is deprecate and will be removed in PyNWB 4.0. ' + warn(('Use of the `notes` or `table_description` argument is deprecated and will be removed in PyNWB 4.0. ' 'Use the `description` argument instead.'), DeprecationWarning) if description is not None: raise ValueError('Cannot call add_scratch with (notes or table_description) and description') diff --git a/tests/integration/hdf5/test_ecephys.py b/tests/integration/hdf5/test_ecephys.py index 8f2bcdfb4..9bfdf3086 100644 --- a/tests/integration/hdf5/test_ecephys.py +++ b/tests/integration/hdf5/test_ecephys.py @@ -184,22 +184,19 @@ def setUpContainer(self): Clustering(**kwargs) # create object in construct mode, modeling the behavior of the ObjectMapper on read + # no warning should be raised obj = Clustering.__new__(Clustering, in_construct_mode=True) - with self.assertWarnsWith(warn_type=UserWarning, exc_msg=error_msg): - obj.__init__(**kwargs) + obj.__init__(**kwargs) return obj def roundtripContainer(self, cache_spec=False): - # catch the DeprecationWarning raised when reading the Clustering object from file - error_msg = "The Clustering neurodata type is deprecated. Use pynwb.misc.Units or NWBFile.units instead" - with self.assertWarnsWith(UserWarning, error_msg): - return super().roundtripContainer(cache_spec) + # no warning or error should be raised when reading the Clustering object from file + return super().roundtripContainer(cache_spec) def roundtripExportContainer(self, cache_spec=False): - error_msg = "The Clustering neurodata type is deprecated. Use pynwb.misc.Units or NWBFile.units instead" - with self.assertWarnsWith(UserWarning, error_msg): - return super().roundtripExportContainer(cache_spec) + # no warning or error should be raised when reading the Clustering object from file + return super().roundtripExportContainer(cache_spec) class SpikeEventSeriesConstructor(NWBH5IOFlexMixin, TestCase): @@ -240,11 +237,9 @@ def setUpContainer(self): peak_over_rms = [5.3, 6.3] # raise error on write - msg = "The Clustering neurodata type is deprecated. Use pynwb.misc.Units or NWBFile.units instead" clust = Clustering.__new__(Clustering, in_construct_mode=True) - with self.assertWarnsWith(warn_type=UserWarning, exc_msg=msg): - clust.__init__('description', num, peak_over_rms, times) - self.clustering = clust + clust.__init__('description', num, peak_over_rms, times) + self.clustering = clust means = [[7.3, 7.3]] stdevs = [[8.3, 8.3]] @@ -253,12 +248,12 @@ def setUpContainer(self): cw = ClusterWaveforms(self.clustering, 'filtering', means, stdevs) # create object in construct mode, modeling the behavior of the ObjectMapper on read + # no warning should be raised cw = ClusterWaveforms.__new__(ClusterWaveforms, container_source=None, parent=None, in_construct_mode=True) - with self.assertWarnsWith(warn_type=UserWarning, exc_msg=msg): - cw.__init__(self.clustering, 'filtering', means, stdevs) + cw.__init__(self.clustering, 'filtering', means, stdevs) return cw @@ -268,16 +263,12 @@ def addContainer(self, nwbfile): nwbfile.add_acquisition(self.container) def roundtripContainer(self, cache_spec=False): - # catch the DeprecationWarning raised when reading the Clustering object from file - msg = "The ClusterWaveforms neurodata type is deprecated. Use pynwb.misc.Units or NWBFile.units instead" - with self.assertWarnsWith(UserWarning, msg): - return super().roundtripContainer(cache_spec) + # no warning or error should be raised when reading the Clustering object from file + return super().roundtripContainer(cache_spec) def roundtripExportContainer(self, cache_spec=False): - # catch the DeprecationWarning raised when reading the Clustering object from file - msg = "The ClusterWaveforms neurodata type is deprecated. Use pynwb.misc.Units or NWBFile.units instead" - with self.assertWarnsWith(UserWarning, msg): - return super().roundtripExportContainer(cache_spec) + # no warning or error should be raised when reading the Clustering object from file + return super().roundtripExportContainer(cache_spec) class FeatureExtractionConstructor(NWBH5IOFlexMixin, TestCase): diff --git a/tests/integration/hdf5/test_icephys.py b/tests/integration/hdf5/test_icephys.py index 17281b7ec..c40a51b53 100644 --- a/tests/integration/hdf5/test_icephys.py +++ b/tests/integration/hdf5/test_icephys.py @@ -154,12 +154,11 @@ def setUpContainer(self): stimulus_description="gotcha ya!", sweep_number=np.uint(4711)) # create the sweeptable in construct mode, modeling the behavior of the ObjectMapper on read + # no user warning or error should be raised sweeptable = SweepTable.__new__(SweepTable) sweeptable._in_construct_mode = True - msg = ("SweepTable is deprecated. Use the IntracellularRecordingsTable instead. " - "See also the NWBFile.add_intracellular_recordings function.") - with self.assertWarnsWith(warn_type=UserWarning, exc_msg=msg): - sweeptable.__init__(name='sweep_table') + sweeptable.__init__(name='sweep_table') + sweeptable._in_construct_mode = False return sweeptable @@ -181,17 +180,13 @@ def getContainer(self, nwbfile): def roundtripContainer(self, cache_spec=False): # catch the DeprecationWarning raised when reading the SweepTable object from file - msg = ("SweepTable is deprecated. Use the IntracellularRecordingsTable instead. " - "See also the NWBFile.add_intracellular_recordings function.") - with self.assertWarnsWith(UserWarning, msg): - return super().roundtripContainer(cache_spec) + # no warning or error message should be raised + return super().roundtripContainer(cache_spec) def roundtripExportContainer(self, cache_spec=False): # catch the DeprecationWarning raised when reading the SweepTable object from file - msg = ("SweepTable is deprecated. Use the IntracellularRecordingsTable instead. " - "See also the NWBFile.add_intracellular_recordings function.") - with self.assertWarnsWith(UserWarning, msg): - return super().roundtripExportContainer(cache_spec) + # no warning or error message should be raised + return super().roundtripExportContainer(cache_spec) def test_container(self): """ Test properties of the SweepTable read from file """ @@ -229,12 +224,11 @@ def setUpContainer(self): stimulus_description="gotcha ya!", sweep_number=np.uint(4712)) # create the sweeptable in construct mode, modeling the behavior of the ObjectMapper on read + # no warning or error should be raised sweeptable = SweepTable.__new__(SweepTable) sweeptable._in_construct_mode = True - msg = ("SweepTable is deprecated. Use the IntracellularRecordingsTable instead. " - "See also the NWBFile.add_intracellular_recordings function.") - with self.assertWarnsWith(warn_type=UserWarning, exc_msg=msg): - sweeptable.__init__(name='sweep_table') + sweeptable.__init__(name='sweep_table') + sweeptable._in_construct_mode = False return sweeptable @@ -258,18 +252,12 @@ def getContainer(self, nwbfile): return nwbfile.sweep_table def roundtripContainer(self, cache_spec=False): - # catch the DeprecationWarning raised when reading the SweepTable object from file - msg = ("SweepTable is deprecated. Use the IntracellularRecordingsTable instead. " - "See also the NWBFile.add_intracellular_recordings function.") - with self.assertWarnsWith(UserWarning, msg): - return super().roundtripContainer(cache_spec) + # no warning or error should be raised when reading the SweepTable object from file + return super().roundtripContainer(cache_spec) def roundtripExportContainer(self, cache_spec=False): - # catch the DeprecationWarning raised when reading the SweepTable object from file - msg = ("SweepTable is deprecated. Use the IntracellularRecordingsTable instead. " - "See also the NWBFile.add_intracellular_recordings function.") - with self.assertWarnsWith(UserWarning, msg): - return super().roundtripExportContainer(cache_spec) + # no warning or error should be raised when reading the SweepTable object from file + return super().roundtripExportContainer(cache_spec) def test_container(self): """ Test properties of the SweepTable read from file """ diff --git a/tests/unit/test_base.py b/tests/unit/test_base.py index 28c4e91d4..a1afe1d15 100644 --- a/tests/unit/test_base.py +++ b/tests/unit/test_base.py @@ -45,15 +45,17 @@ def test_add_data_interface(self): def test_deprecated_add_data_interface(self): ts = self._create_time_series() + msg = 'add_data_interface is deprecated and will be removed in PyNWB 4.0. Use add instead.' with self.assertWarnsWith(warn_type=DeprecationWarning, - exc_msg="add_data_interface is deprecated. Use add instead." + exc_msg=msg ): self.pm.add_data_interface(ts) def test_deprecated_add_container(self): ts = self._create_time_series() + msg = 'add_container is deprecated and will be removed in PyNWB 4.0. Use add instead.' with self.assertWarnsWith(warn_type=DeprecationWarning, - exc_msg="add_container is deprecated. Use add instead." + exc_msg=msg ): self.pm.add_container(ts) @@ -68,8 +70,9 @@ def test_get_data_interface(self): def test_deprecated_get_data_interface(self): ts = self._create_time_series() self.pm.add(ts) + msg = 'get_data_interface is deprecated and will be removed in PyNWB 4.0. Use get instead.' with self.assertWarnsWith(warn_type=DeprecationWarning, - exc_msg="get_data_interface is deprecated. Use get instead." + exc_msg=msg ): tmp = self.pm.get_data_interface("test_ts") self.assertIs(tmp, ts) @@ -77,8 +80,9 @@ def test_deprecated_get_data_interface(self): def test_deprecated_get_container(self): ts = self._create_time_series() self.pm.add(ts) + msg = 'get_container is deprecated and will be removed in PyNWB 4.0. Use get instead.' with self.assertWarnsWith(warn_type=DeprecationWarning, - exc_msg="get_container is deprecated. Use get instead." + exc_msg=msg ): tmp = self.pm.get_container("test_ts") self.assertIs(tmp, ts) diff --git a/tests/unit/test_ecephys.py b/tests/unit/test_ecephys.py index 147268931..f54a56996 100644 --- a/tests/unit/test_ecephys.py +++ b/tests/unit/test_ecephys.py @@ -288,9 +288,9 @@ def test_init(self): cc = Clustering(**kwargs) # create object in construct mode, modeling the behavior of the ObjectMapper on read + # no error or warning should be raised cc = Clustering.__new__(Clustering, in_construct_mode=True) - with self.assertWarnsWith(warn_type=UserWarning, exc_msg=error_msg): - cc.__init__(**kwargs) + cc.__init__(**kwargs) self.assertEqual(cc.description, 'description') self.assertEqual(cc.num, num) @@ -306,13 +306,11 @@ def test_init(self): peak_over_rms = [5.3, 6.3] # create object in construct mode, modeling the behavior of the ObjectMapper on read - error_msg = "The Clustering neurodata type is deprecated. Use pynwb.misc.Units or NWBFile.units instead" cc = Clustering.__new__(Clustering, container_source=None, parent=None, in_construct_mode=True) - with self.assertWarnsWith(warn_type=UserWarning, exc_msg=error_msg): - cc.__init__('description', num, peak_over_rms, times) + cc.__init__('description', num, peak_over_rms, times) means = [[7.3, 7.3]] stdevs = [[8.3, 8.3]] @@ -321,12 +319,12 @@ def test_init(self): cw = ClusterWaveforms(cc, 'filtering', means, stdevs) # create object in construct mode, modeling the behavior of the ObjectMapper on read + # no error or warning should be raised cw = ClusterWaveforms.__new__(ClusterWaveforms, container_source=None, parent=None, in_construct_mode=True) - with self.assertWarnsWith(warn_type=UserWarning, exc_msg=error_msg): - cw.__init__(cc, 'filtering', means, stdevs) + cw.__init__(cc, 'filtering', means, stdevs) self.assertEqual(cw.clustering_interface, cc) self.assertEqual(cw.waveform_filtering, 'filtering') diff --git a/tests/unit/test_file.py b/tests/unit/test_file.py index e2feb1930..9e4bf1a28 100644 --- a/tests/unit/test_file.py +++ b/tests/unit/test_file.py @@ -126,23 +126,14 @@ def test_access_group_after_io(self): remove_test_file("electrodes_mwe.nwb") - def test_access_processing(self): + def test_access_processing_with_modules(self): self.nwbfile.create_processing_module('test_mod', 'test_description') - msg = 'NWBFile.modules is deprecated. Use NWBFile.processing instead.' # create object with deprecated argument - with self.assertRaisesWith(ValueError, msg): + msg = "'NWBFile' object has no attribute 'modules'" + with self.assertRaisesWith(AttributeError, msg): self.nwbfile.modules['test_mod'] - # create object in construct mode, modeling the behavior of the ObjectMapper on read - self.nwbfile._in_construct_mode = True - with self.assertWarnsWith(warn_type=UserWarning, exc_msg=msg): - modules = self.nwbfile.modules['test_mod'] - self.assertIs(self.nwbfile.processing['test_mod'], modules) - - # reset construct mode for other tests - self.nwbfile._in_construct_mode = False - def test_epoch_tags(self): tags1 = ['t1', 't2'] tags2 = ['t3', 't4'] @@ -178,7 +169,7 @@ def test_add_stimulus(self): def test_add_stimulus_timeseries_arg(self): """Test nwbfile.add_stimulus using the deprecated 'timeseries' keyword argument""" - msg = ("NWBFile.add_stimulus: unrecognized argument: 'timeseries'") + msg = ("NWBFile.add_stimulus: missing argument 'stimulus', unrecognized argument: 'timeseries'") with self.assertRaisesWith(TypeError, msg): self.nwbfile.add_stimulus( timeseries=TimeSeries( @@ -191,9 +182,9 @@ def test_add_stimulus_timeseries_arg(self): def test_add_stimulus_no_stimulus_arg(self): """Test nwbfile.add_stimulus using the deprecated 'timeseries' keyword argument""" - msg = ("The 'stimulus' keyword argument is required.") - with self.assertRaisesWith(ValueError, msg): - self.nwbfile.add_stimulus(None) + msg = ("NWBFile.add_stimulus: missing argument 'stimulus'") + with self.assertRaisesWith(TypeError, msg): + self.nwbfile.add_stimulus() self.assertEqual(len(self.nwbfile.stimulus), 0) def test_add_stimulus_dynamic_table(self): @@ -525,26 +516,14 @@ def test_ec_electrodes_deprecation(self): nwbfile.add_electrode(location='loc1', group=elecgrp, id=0) # test that NWBFile.ec_electrodes property warns or errors - msg = "NWBFile.ec_electrodes is deprecated. Use NWBFile.electrodes instead." - with self.assertRaisesWith(ValueError, msg): + msg = "'NWBFile' object has no attribute 'ec_electrodes'" + with self.assertRaisesWith(AttributeError, msg): nwbfile.ec_electrodes - nwbfile._in_construct_mode = True - with self.assertWarnsWith(warn_type=UserWarning, exc_msg=msg): - nwbfile.ec_electrodes - self.assertEqual(nwbfile.ec_electrodes.location[0], 'loc1') - nwbfile._in_construct_mode = False - # test that NWBFile.ec_electrode_groups warns or errors - msg = "NWBFile.ec_electrode_groups is deprecated. Use NWBFile.electrode_groups instead." - with self.assertRaisesWith(ValueError, msg): - nwbfile.ec_electrode_groups - - nwbfile._in_construct_mode = True - with self.assertWarnsWith(warn_type=UserWarning, exc_msg=msg): + msg = "'NWBFile' object has no attribute 'ec_electrode_groups'" + with self.assertRaisesWith(AttributeError, msg): nwbfile.ec_electrode_groups - self.assertEqual(nwbfile.ec_electrode_groups['name'].description, 'desc') - nwbfile._in_construct_mode = False class SubjectTest(TestCase): def setUp(self): diff --git a/tests/unit/test_icephys.py b/tests/unit/test_icephys.py index ec0d68e77..5b77a1e94 100644 --- a/tests/unit/test_icephys.py +++ b/tests/unit/test_icephys.py @@ -47,9 +47,9 @@ def test_sweep_table_deprecation_warn(self): SweepTable() # create object in construct mode, modeling the behavior of the ObjectMapper on read + # should not raise error or warning sweepT = SweepTable.__new__(SweepTable, in_construct_mode=True) - with self.assertWarnsWith(warn_type=UserWarning, exc_msg=msg): - sweepT.__init__() + sweepT.__init__() kwargs = dict(session_description='NWBFile icephys test', identifier='NWB123', # required @@ -61,25 +61,9 @@ def test_sweep_table_deprecation_warn(self): NWBFile(**kwargs) # create object in construct mode, modeling the behavior of the ObjectMapper on read + # should not warn or error nwbfile = NWBFile.__new__(NWBFile, in_construct_mode=True) - - with self.assertWarnsWith(warn_type=UserWarning, exc_msg=msg): - nwbfile.__init__(**kwargs) - - def test_ic_electrodes_parameter_deprecation(self): - # Make sure we warn when using the ic_electrodes parameter on NWBFile - msg = "Use of the ic_electrodes parameter is deprecated. Use the icephys_electrodes parameter instead" - kwargs = dict(session_description='NWBFile icephys test', - identifier='NWB123', # required - session_start_time=datetime(2017, 4, 3, 11, tzinfo=tzlocal()), - ic_electrodes=[self.icephys_electrode, ]) - with self.assertRaisesWith(ValueError, msg): - NWBFile(**kwargs) - - # create object in construct mode, modeling the behavior of the ObjectMapper on read - nwbfile = NWBFile.__new__(NWBFile, in_construct_mode=True) - with self.assertWarnsWith(warn_type=UserWarning, exc_msg=msg): - nwbfile.__init__(**kwargs) + nwbfile.__init__(**kwargs) def test_icephys_electrodes_parameter(self): nwbfile = NWBFile( @@ -95,16 +79,6 @@ def test_ic_electrodes_attribute_deprecation(self): identifier='NWB123', # required session_start_time=datetime(2017, 4, 3, 11, tzinfo=tzlocal()), icephys_electrodes=[self.icephys_electrode, ]) - - # make sure NWBFile.ic_electrodes property warns or errors - msg = "NWBFile.ic_electrodes is deprecated. Use NWBFile.icephys_electrodes instead." - with self.assertRaisesWith(ValueError, msg): - nwbfile.ic_electrodes - - nwbfile._in_construct_mode = True - with self.assertWarnsWith(warn_type=UserWarning, exc_msg=msg): - nwbfile.ic_electrodes - nwbfile._in_construct_mode = False # make sure NWBFile.get_ic_electrode warns msg = "'NWBFile' object has no attribute 'get_ic_electrode'" diff --git a/tests/unit/test_icephys_metadata_tables.py b/tests/unit/test_icephys_metadata_tables.py index ba8d866fb..e73a95c29 100644 --- a/tests/unit/test_icephys_metadata_tables.py +++ b/tests/unit/test_icephys_metadata_tables.py @@ -1117,9 +1117,9 @@ def test_deprecate_simultaneous_recordings_on_add_stimulus(self): with self.assertRaisesWith(ValueError, msg): nwbfile.add_stimulus(stimulus, use_sweep_table=True) + # shoudl not error when in construct mode nwbfile._in_construct_mode = True - with self.assertWarnsWith(warn_type=UserWarning, exc_msg=msg): - nwbfile.add_stimulus(stimulus2, use_sweep_table=True) + nwbfile.add_stimulus(stimulus2, use_sweep_table=True) # make sure we don't trigger the same deprecation warning twice nwbfile.add_acquisition(response, use_sweep_table=True) @@ -1153,15 +1153,6 @@ def test_deprecate_sweeptable_on_add_stimulus_template(self): gain=0.02, sweep_number=np.uint64(15) ) - local_stimulus3 = VoltageClampStimulusSeries( - name="ccss3", - data=[1, 2, 3, 4, 5], - starting_time=123.6, - rate=10e3, - electrode=local_electrode, - gain=0.02, - sweep_number=np.uint64(15) - ) msg = ("SweepTable is deprecated. Use the IntracellularRecordingsTable instead. " "See also the NWBFile.add_intracellular_recordings function.") @@ -1170,12 +1161,9 @@ def test_deprecate_sweeptable_on_add_stimulus_template(self): # NOTE - the sweep table creation will error but the stimulus template will still be added # create object in construct mode, modeling the behavior of the ObjectMapper on read + # should not trigger any warnings or errors nwbfile._in_construct_mode = True - with self.assertWarnsWith(warn_type=UserWarning, exc_msg=msg): - nwbfile.add_stimulus_template(local_stimulus2, use_sweep_table=True) - - # make sure we don't trigger the same warning twice (should only be triggered on table creation) - nwbfile.add_stimulus_template(local_stimulus3, use_sweep_table=True) + nwbfile.add_stimulus_template(local_stimulus2, use_sweep_table=True) nwbfile._in_construct_mode = False def test_deprecate_sweepstable_on_add_acquistion(self): @@ -1209,9 +1197,9 @@ def test_deprecate_sweepstable_on_add_acquistion(self): nwbfile.add_acquisition(response, use_sweep_table=True) # NOTE - the sweep table creation will error but the acquisition will still be added + # should not trigger error or warning in construct mode nwbfile._in_construct_mode = True - with self.assertWarnsWith(warn_type=UserWarning, exc_msg=msg): - nwbfile.add_acquisition(response2, use_sweep_table=True) + nwbfile.add_acquisition(response2, use_sweep_table=True) # make sure we don't trigger the same deprecation warning twice nwbfile.add_stimulus(stimulus, use_sweep_table=True) @@ -1223,12 +1211,8 @@ def test_deprecate_sweepstable_on_init(self): Test that warnings are raised if the user tries to use a sweeps table """ from pynwb.icephys import SweepTable - msg = ("SweepTable is deprecated. Use the IntracellularRecordingsTable instead. " - "See also the NWBFile.add_intracellular_recordings function.") - - with self.assertWarnsWith(warn_type=UserWarning, exc_msg=msg): - sweepT = SweepTable.__new__(SweepTable, in_construct_mode=True) - sweepT.__init__() + sweepT = SweepTable.__new__(SweepTable, in_construct_mode=True) + sweepT.__init__() kwargs = dict(session_description='my first synthetic recording', identifier='EXAMPLE_ID', @@ -1236,13 +1220,15 @@ def test_deprecate_sweepstable_on_init(self): sweep_table=sweepT) # check we raise an error when using the sweeptable argument on init + msg = ("SweepTable is deprecated. Use the IntracellularRecordingsTable instead. " + "See also the NWBFile.add_intracellular_recordings function.") with self.assertRaisesWith(ValueError, msg): nwbfile = NWBFile(**kwargs) # create object in construct mode, modeling the behavior of the ObjectMapper on read + # should not trigger warning or error nwbfile = NWBFile.__new__(NWBFile, in_construct_mode=True) - with self.assertWarnsWith(warn_type=UserWarning, exc_msg=msg): - nwbfile.__init__(**kwargs) + nwbfile.__init__(**kwargs) # make sure we don't trigger the same deprecation warning twice device = self.__add_device(nwbfile) diff --git a/tests/unit/test_image.py b/tests/unit/test_image.py index 70bd01043..a2e24a209 100644 --- a/tests/unit/test_image.py +++ b/tests/unit/test_image.py @@ -243,7 +243,8 @@ def test_external_file_default_format(self): """Test that format is set to 'external' if not provided, when external_file is provided.""" msg = ( "ImageSeries 'test_iS': The value for 'format' has been changed to 'external'. " - "Setting a default value for 'format' is deprecated." + "If an external file is detected, setting a value for " + "'format' other than 'external' is deprecated." ) kwargs = dict(name="test_iS", external_file=["external_file", "external_file2"], @@ -326,9 +327,10 @@ def test_bits_per_pixel_deprecation(self): with self.assertRaisesWith(ValueError, msg): ImageSeries(**kwargs) + # create object in construct mode, modeling the behavior of the ObjectMapper on read + # no warning or error should be raised iS = ImageSeries.__new__(ImageSeries, in_construct_mode=True) - with self.assertWarnsWith(UserWarning, msg): - iS.__init__(**kwargs) + iS.__init__(**kwargs) class IndexSeriesConstructor(TestCase): @@ -369,9 +371,9 @@ def test_init_bad_unit(self): IndexSeries(**kwargs) # create object in construct mode, modeling the behavior of the ObjectMapper on read + # no warning or error should be raised iS = IndexSeries.__new__(IndexSeries, in_construct_mode=True) - with self.assertWarnsWith(warn_type=UserWarning, exc_msg=msg): - iS.__init__(**kwargs) + iS.__init__(**kwargs) self.assertEqual(iS.unit, 'N/A') @@ -395,9 +397,9 @@ def test_init_indexed_ts(self): IndexSeries(**kwargs) # create object in construct mode, modeling the behavior of the ObjectMapper on read + # no warning or error should be raised iS = IndexSeries.__new__(IndexSeries, in_construct_mode=True) - with self.assertWarnsWith(warn_type=UserWarning, exc_msg=msg): - iS.__init__(**kwargs) + iS.__init__(**kwargs) self.assertIs(iS.indexed_timeseries, ts) diff --git a/tests/unit/test_ophys.py b/tests/unit/test_ophys.py index 9d4bf5ee6..d484d9e01 100644 --- a/tests/unit/test_ophys.py +++ b/tests/unit/test_ophys.py @@ -147,9 +147,9 @@ def test_manifold_deprecated(self): ImagingPlane(**kwargs) # create object in construct mode, modeling the behavior of the ObjectMapper on read + # no warning or error should be raised obj = ImagingPlane.__new__(ImagingPlane, in_construct_mode=True) - with self.assertWarnsWith(warn_type=UserWarning, exc_msg=msg): - obj.__init__(**kwargs) + obj.__init__(**kwargs) def test_conversion_deprecated(self): oc, device = self.set_up_dependencies() @@ -169,9 +169,9 @@ def test_conversion_deprecated(self): ImagingPlane(**kwargs) # create object in construct mode, modeling the behavior of the ObjectMapper on read + # no warning or error should be raised obj = ImagingPlane.__new__(ImagingPlane, in_construct_mode=True) - with self.assertWarnsWith(warn_type=UserWarning, exc_msg=msg): - obj.__init__(**kwargs) + obj.__init__(**kwargs) def test_unit_deprecated(self): oc, device = self.set_up_dependencies() @@ -192,9 +192,9 @@ def test_unit_deprecated(self): ImagingPlane(**kwargs) # create object in construct mode, modeling the behavior of the ObjectMapper on read + # no warning or error should be raised obj = ImagingPlane.__new__(ImagingPlane, in_construct_mode=True) - with self.assertWarnsWith(warn_type=UserWarning, exc_msg=msg): - obj.__init__(**kwargs) + obj.__init__(**kwargs) class OnePhotonSeriesConstructor(TestCase): diff --git a/tests/unit/test_scratch.py b/tests/unit/test_scratch.py index 8de6be7df..e17c0b518 100644 --- a/tests/unit/test_scratch.py +++ b/tests/unit/test_scratch.py @@ -29,18 +29,20 @@ def test_constructor_list(self): self.assertEqual(sd.description, 'test scratch') def test_scratch_notes_deprecation(self): - msg = "The `notes` argument of ScratchData.__init__ has been deprecated. Use description instead." + msg = ("The `notes` argument of ScratchData.__init__ has been deprecated and will " + "be removed in PyNWB 4.0. Use description instead.") with self.assertRaisesWith(ValueError, msg): ScratchData(name='test', data=[1, 2, 3, 4, 5], notes='test notes') # create object in construct mode, modeling the behavior of the ObjectMapper on read + # should not raise error or warning data = ScratchData.__new__(ScratchData, in_construct_mode=True) - with self.assertWarnsWith(UserWarning, msg): - data.__init__(name='test', data=[1, 2, 3, 4, 5], notes='test notes') + data.__init__(name='test', data=[1, 2, 3, 4, 5], notes='test notes') self.assertEqual(data.description, 'test notes') # test notes property - msg = "Use of ScratchData.notes has been deprecated. Use ScratchData.description instead." + msg = ("Use of ScratchData.notes has been deprecated and will be removed in PyNWB 4.0. " + "Use ScratchData.description instead.") with self.assertWarnsWith(DeprecationWarning, msg): data.notes @@ -146,15 +148,15 @@ def test_add_scratch_dynamictable(self): self.assertIs(self.nwbfile.scratch['test'], data) def test_add_scratch_notes_deprecation(self): - msg = ("Use of the `notes` or `table_description` argument is deprecated. " + msg = ("Use of the `notes` or `table_description` argument is deprecated and will be removed in PyNWB 4.0. " "Use the `description` argument instead.") with self.assertWarnsWith(DeprecationWarning, msg): self.nwbfile.add_scratch(name='test', data=[1, 2, 3, 4, 5], notes='test notes') self.assertEqual(self.nwbfile.scratch['test'].description, 'test notes') def test_add_scratch_table_description_deprecation(self): - msg = ("Use of the `notes` or `table_description` argument is deprecated. " - "Use the `description` argument instead.") + msg = ('Use of the `notes` or `table_description` argument is deprecated and will be removed in PyNWB 4.0. ' + 'Use the `description` argument instead.') df = pd.DataFrame(data={'col1': [1, 2, 3, 4], 'col2': ['a', 'b', 'c', 'd']}) with self.assertWarnsWith(DeprecationWarning, msg): self.nwbfile.add_scratch(name='test', data=df,