Skip to content

Commit

Permalink
Merge pull request #597 from djhoese/deprecate-old-reader-exception
Browse files Browse the repository at this point in the history
Deprecate old reader names so they produce an exception
  • Loading branch information
djhoese committed Mar 14, 2019
2 parents ae288c0 + 40b0c93 commit ee02de0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 21 deletions.
10 changes: 3 additions & 7 deletions satpy/readers/__init__.py
Expand Up @@ -556,13 +556,9 @@ def configs_for_reader(reader=None, ppp_config_dir=None):

new_name = OLD_READER_NAMES[reader_name]
# SatPy 0.11 only displays a warning
warnings.warn("Reader name '{}' has been deprecated, use '{}' instead.".format(reader_name, new_name),
DeprecationWarning)
# SatPy 0.12 will raise an exception
# raise ValueError("Reader name '{}' has been deprecated, use '{}' instead.".format(reader_name, new_name))
# SatPy 0.13 or 1.0, remove exception and mapping

new_readers.append(new_name)
# SatPy 0.13 will raise an exception
raise ValueError("Reader name '{}' has been deprecated, use '{}' instead.".format(reader_name, new_name))
# SatPy 0.15 or 1.0, remove exception and mapping

reader = new_readers
# given a config filename or reader name
Expand Down
17 changes: 3 additions & 14 deletions satpy/tests/test_readers.py
Expand Up @@ -287,9 +287,7 @@ def test_missing_requirements(self, *mocks):
epi_miss = epi_pro_miss + ['H-000-MSG4__-MSG4________-_________-PRO______-201809050900-__']
pro_miss = epi_pro_miss + ['H-000-MSG4__-MSG4________-_________-EPI______-201809050900-__']
for filenames in [epi_miss, pro_miss, epi_pro_miss]:
with mock.patch('warnings.warn') as warn_mock:
self.assertRaises(ValueError, load_readers, reader='hrit_msg', filenames=filenames)
warn_mock.assert_called()
self.assertRaises(ValueError, load_readers, reader='seviri_l1b_hrit', filenames=filenames)

# Filenames from multiple scans
at_least_one_complete = [
Expand All @@ -301,9 +299,7 @@ def test_missing_requirements(self, *mocks):
'H-000-MSG4__-MSG4________-IR_108___-000006___-201809051000-__',
]
try:
with mock.patch('warnings.warn') as warn_mock:
load_readers(filenames=at_least_one_complete, reader='hrit_msg')
warn_mock.assert_called()
load_readers(filenames=at_least_one_complete, reader='seviri_l1b_hrit')
except ValueError:
self.fail('If at least one set of filenames is complete, no '
'exception should be raised')
Expand Down Expand Up @@ -538,15 +534,8 @@ def test_reader_load_failed(self):

def test_old_reader_name_mapping(self):
"""Test that requesting old reader names raises a warning."""
import warnings
from satpy.readers import configs_for_reader
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
configs = list(configs_for_reader('hrit_jma'))[0]
self.assertIn('ahi_hrit', configs[0])
self.assertNotIn('hrit_jma', configs[0])
self.assertEqual(len(w), 1)
self.assertTrue(issubclass(w[0].category, DeprecationWarning))
self.assertRaises(ValueError, list, configs_for_reader('hrit_jma'))


class TestYAMLFiles(unittest.TestCase):
Expand Down

0 comments on commit ee02de0

Please sign in to comment.