From 8f938004de7bb08c6e9497de11d77054f3ff99c5 Mon Sep 17 00:00:00 2001 From: Philippe Theroux Date: Mon, 9 May 2022 12:23:12 +0000 Subject: [PATCH] Added checks for loggers and repr + updated setup.py test commands --- setup.py | 18 ++++---- tests/test_base.py | 26 +++++++++--- tests/test_cansips.py | 18 +++++++- tests/test_cgsl.py | 18 +++++++- tests/test_gdwps.py | 18 +++++++- tests/test_geps.py | 18 +++++++- tests/test_hrdpa.py | 18 +++++++- tests/test_model_gem_global.py | 20 +++++++-- tests/test_model_gem_regional.py | 21 ++++++++-- tests/test_model_giops.py | 34 +++++++++++---- tests/test_model_hrdps_continental.py | 23 +++++++--- tests/test_model_raqdps.py | 20 +++++++-- tests/test_model_raqdps_fw.py | 20 +++++++-- tests/test_model_raqdps_fw_ce.py | 60 ++++++++++++++++++++------- tests/test_model_rdaqa_ce.py | 52 +++++++++++++++++++---- tests/test_model_riops.py | 28 ++++++++++--- tests/test_radar_1km.py | 39 +++++++++++++---- tests/test_rdpa.py | 19 +++++++-- tests/test_rdwps.py | 18 +++++++- tests/test_reps.py | 18 +++++++- tests/test_wcps.py | 15 ++++++- 21 files changed, 423 insertions(+), 98 deletions(-) diff --git a/setup.py b/setup.py index 052de2f..563387e 100644 --- a/setup.py +++ b/setup.py @@ -20,8 +20,10 @@ import io import os import re -from setuptools import Command, find_packages, setup import shutil +import sys + +from setuptools import Command, find_packages, setup class PyCleanBuild(Command): @@ -63,7 +65,7 @@ def run(self): os.remove('../{}'.format(file_)) -class PyTest(Command): +class Unittest(Command): user_options = [] def initialize_options(self): @@ -74,7 +76,8 @@ def finalize_options(self): def run(self): import subprocess - errno = subprocess.call(['pytest']) + errno = subprocess.call([sys.executable, + '-m', 'unittest', 'discover']) raise SystemExit(errno) @@ -91,10 +94,9 @@ def run(self): import subprocess errno = subprocess.call(['coverage', 'run', - '--source=geomet_data_registry', - '-m', 'unittest', - 'geomet_data_registry.tests.run_tests']) - errno = subprocess.call(['coverage', 'report', '-m']) + '-m', 'unittest', 'discover']) + errno = subprocess.call(['coverage', 'report', '-m', + '--include=geomet_data_registry/layer/*.py']) raise SystemExit(errno) @@ -156,7 +158,7 @@ def get_package_version(): 'Programming Language :: Python' ], cmdclass={ - 'test': PyTest, + 'test': Unittest, 'coverage': PyCoverage, 'cleanbuild': PyCleanBuild } diff --git a/tests/test_base.py b/tests/test_base.py index 3fe35da..7576553 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -175,6 +175,12 @@ def test_is_valid_interval(self): self.assertListEqual(return_list, [True, True, False]) + def test_repr(self): + self.assertEqual( + repr(self.base_layer), + ' model_gem_global' + ) + class TestRegister(unittest.TestCase, Setup): def setUp(self): @@ -191,10 +197,15 @@ def tearDown(self): def test_register_no_items(self): """ Test that when no items are identified - geomet_data_registry.layer.base.register() returns False. + geomet_data_registry.layer.base.register() + returns False and an error is logged. """ - - self.assertFalse(self.base_layer.register()) + with self.assertLogs( + 'geomet_data_registry.layer.base', level='ERROR' + ) as err: + self.assertFalse(self.base_layer.register()) + # assert a single LOGGER.error was called + self.assertEqual(len(err.records), 1) def test_register_one_item(self): """ @@ -354,7 +365,7 @@ def test_update_count_expected_81(self): def test_update_count_incomplete_mr(self): """ Test that the appropriate model run count is reset when an imcomplete - model run is identified. + model run is identified and an error is logged. """ # store.get_key() will return these values in sequence like a generator @@ -372,7 +383,12 @@ def test_update_count_incomplete_mr(self): call('model_gem_global_TMP_TGL_2_12Z_count', 0), ] - self.base_layer.update_count(self.item, 201) + with self.assertLogs( + 'geomet_data_registry.layer.base', level='ERROR' + ) as err: + self.base_layer.update_count(self.item, 201) + # assert a single LOGGER.error was called + self.assertEqual(len(err.records), 1) self.mocked_load_plugin.return_value.set_key.assert_has_calls(calls) diff --git a/tests/test_cansips.py b/tests/test_cansips.py index 453b77f..63b5da4 100644 --- a/tests/test_cansips.py +++ b/tests/test_cansips.py @@ -73,6 +73,12 @@ def test_super_init(self): # assert super().__init__() was called with the correct provider def self.mocked_base_init.assert_called_with({'name': 'cansips'}) + def test_repr(self): + self.assertEqual( + repr(self.layer_handler['cansips']), + ' cansips' + ) + class TestIdentify(unittest.TestCase, Setup): def setUp(self): @@ -161,9 +167,17 @@ def test_items_identify(self): ) def test_unsuccessful_identify(self): - # assert identify returns False when the wx_variable isn't correct + # assert identify returns False when the wx_variable + # isn't correct and a warning is logged. self.filepath = self.filepath.replace('PRATE_SFC_0', 'Not_wx_variable') - self.assertFalse(self.layer_handler['cansips'].identify(self.filepath)) + with self.assertLogs( + 'geomet_data_registry.layer.cansips', level='WARNING' + ) as warn: + self.assertFalse( + self.layer_handler['cansips'].identify(self.filepath) + ) + # assert a single LOGGER.warning was called + self.assertEqual(len(warn.records), 1) class TestAddTimeKey(unittest.TestCase, Setup): diff --git a/tests/test_cgsl.py b/tests/test_cgsl.py index e6e9221..008a7a2 100644 --- a/tests/test_cgsl.py +++ b/tests/test_cgsl.py @@ -69,6 +69,12 @@ def test_super_init(self): # assert super().__init__() was called with the correct provider def self.mocked_base_init.assert_called_with({'name': 'cgsl'}) + def test_repr(self): + self.assertEqual( + repr(self.layer_handler['cgsl']), + ' cgsl' + ) + class TestIdentify(unittest.TestCase, Setup): def setUp(self): @@ -174,9 +180,17 @@ def test_invalid_interval_identify(self): ) def test_unsuccessful_identify(self): - # assert identify returns False when the wx_variable isn't correct + # assert identify returns False when the wx_variable + # isn't correct and a warning is logged. self.filepath = self.filepath.replace('ocean', 'Not_wx_variable') - self.assertFalse(self.layer_handler['cgsl'].identify(self.filepath)) + with self.assertLogs( + 'geomet_data_registry.layer.cgsl', level='WARNING' + ) as warn: + self.assertFalse( + self.layer_handler['cgsl'].identify(self.filepath) + ) + # assert a single LOGGER.warning was called + self.assertEqual(len(warn.records), 1) if __name__ == '__main__': diff --git a/tests/test_gdwps.py b/tests/test_gdwps.py index f08ad21..66b2a90 100644 --- a/tests/test_gdwps.py +++ b/tests/test_gdwps.py @@ -69,6 +69,12 @@ def test_super_init(self): # assert super().__init__() was called with the correct provider def self.mocked_base_init.assert_called_with({'name': 'gdwps'}) + def test_repr(self): + self.assertEqual( + repr(self.layer_handler['gdwps']), + ' gdwps' + ) + class TestIdentify(unittest.TestCase, Setup): def setUp(self): @@ -258,9 +264,17 @@ def test_invalid_interval_identify(self): ) def test_unsuccessful_identify(self): - # assert identify returns False when the wx_variable isn't correct + # assert identify returns False when the wx_variable + # isn't correct and a warning is logged. self.filepath = self.filepath.replace('HTSGW_Sfc', 'Not_wx_variable') - self.assertFalse(self.layer_handler['gdwps'].identify(self.filepath)) + with self.assertLogs( + 'geomet_data_registry.layer.gdwps', level='WARNING' + ) as warn: + self.assertFalse( + self.layer_handler['gdwps'].identify(self.filepath) + ) + # assert a single LOGGER.warning was called + self.assertEqual(len(warn.records), 1) if __name__ == '__main__': diff --git a/tests/test_geps.py b/tests/test_geps.py index 8ef1c88..e698fa5 100644 --- a/tests/test_geps.py +++ b/tests/test_geps.py @@ -71,6 +71,12 @@ def test_super_init(self): # assert super().__init__() was called with the correct provider def self.mocked_base_init.assert_called_with({'name': 'geps'}) + def test_repr(self): + self.assertEqual( + repr(self.layer_handler['geps']), + ' geps' + ) + class TestIdentify(unittest.TestCase, Setup): def setUp(self): @@ -226,11 +232,19 @@ def test_invalid_interval_identify(self): ) def test_unsuccessful_identify(self): - # assert identify returns False when the wx_variable isn't correct + # assert identify returns False when the wx_variable + # isn't correct and a warning is logged. self.filepath = self.filepath.replace( 'HEATX_TGL_2m', 'Not_wx_variable' ) - self.assertFalse(self.layer_handler['geps'].identify(self.filepath)) + with self.assertLogs( + 'geomet_data_registry.layer.geps', level='WARNING' + ) as warn: + self.assertFalse( + self.layer_handler['geps'].identify(self.filepath) + ) + # assert a single LOGGER.warning was called + self.assertEqual(len(warn.records), 1) if __name__ == '__main__': diff --git a/tests/test_hrdpa.py b/tests/test_hrdpa.py index 29a372c..9da79d3 100644 --- a/tests/test_hrdpa.py +++ b/tests/test_hrdpa.py @@ -71,6 +71,12 @@ def test_super_init(self): # assert super().__init__() was called with the correct provider def self.mocked_base_init.assert_called_with({'name': 'hrdpa'}) + def test_repr(self): + self.assertEqual( + repr(self.layer_handler['hrdpa']), + ' hrdpa' + ) + class TestIdentify(unittest.TestCase, Setup): def setUp(self): @@ -154,11 +160,19 @@ def test_items_identify(self): self.assertListEqual(expected_items, self.layer_handler['hrdpa'].items) def test_unsuccessful_identify(self): - # assert identify returns False when the wx_variable isn't correct + # assert identify returns False when the wx_variable + # isn't correct and a warning is logged. self.filepath = self.filepath.replace( 'APCP-006-0100cutoff_SFC_0', 'Not_wx_variable' ) - self.assertFalse(self.layer_handler['hrdpa'].identify(self.filepath)) + with self.assertLogs( + 'geomet_data_registry.layer.hrdpa', level='WARNING' + ) as warn: + self.assertFalse( + self.layer_handler['hrdpa'].identify(self.filepath) + ) + # assert a single LOGGER.warning was called + self.assertEqual(len(warn.records), 1) class TestAddTimeKey(unittest.TestCase, Setup): diff --git a/tests/test_model_gem_global.py b/tests/test_model_gem_global.py index db20442..064e37f 100644 --- a/tests/test_model_gem_global.py +++ b/tests/test_model_gem_global.py @@ -73,6 +73,12 @@ def test_super_init(self): # assert super().__init__() was called with the correct provider def self.mocked_base_init.assert_called_with({'name': 'model_gem_global'}) + def test_repr(self): + self.assertEqual( + repr(self.layer_handler['model_gem_global']), + ' model_gem_global' + ) + class TestIdentify(unittest.TestCase, Setup): def setUp(self): @@ -253,11 +259,17 @@ def test_invalid_interval_identify(self): ) def test_unsuccessful_identify(self): - # assert identify returns False when the wx_variable isn't correct + # assert identify returns False when the wx_variable + # isn't correct and a warning is logged. self.filepath = self.filepath.replace('UGRD_ISBL_1015', 'Not wx_var') - self.assertFalse( - self.layer_handler['model_gem_global'].identify(self.filepath) - ) + with self.assertLogs( + 'geomet_data_registry.layer.model_gem_global', level='WARNING' + ) as warn: + self.assertFalse( + self.layer_handler['model_gem_global'].identify(self.filepath) + ) + # assert a single LOGGER.warning was called + self.assertEqual(len(warn.records), 1) if __name__ == '__main__': diff --git a/tests/test_model_gem_regional.py b/tests/test_model_gem_regional.py index 6186da5..8309c94 100644 --- a/tests/test_model_gem_regional.py +++ b/tests/test_model_gem_regional.py @@ -75,6 +75,12 @@ def test_super_init(self): {'name': 'model_gem_regional'} ) + def test_repr(self): + self.assertEqual( + repr(self.layer_handler['model_gem_regional']), + ' model_gem_regional' + ) + class TestIdentify(unittest.TestCase, Setup): def setUp(self): @@ -253,13 +259,20 @@ def test_invalid_interval_identify(self): ) def test_unsuccessful_identify(self): - # assert identify returns False when the wx_variable isn't correct + # assert identify returns False when the wx_variable + # isn't correct and a warning is logged. self.filepath = self.filepath.replace( 'ABSV_ISBL_250', 'Not_wx_variable' ) - self.assertFalse( - self.layer_handler['model_gem_regional'].identify(self.filepath) - ) + with self.assertLogs( + 'geomet_data_registry.layer.model_gem_regional', level='WARNING' + ) as warn: + self.assertFalse( + self.layer_handler['model_gem_regional'] + .identify(self.filepath) + ) + # assert a single LOGGER.warning was called + self.assertEqual(len(warn.records), 1) if __name__ == '__main__': diff --git a/tests/test_model_giops.py b/tests/test_model_giops.py index f8132b4..9efc101 100644 --- a/tests/test_model_giops.py +++ b/tests/test_model_giops.py @@ -71,6 +71,12 @@ def test_super_init(self): # assert super().__init__() was called with the correct provider def self.mocked_base_init.assert_called_with({'name': 'giops'}) + def test_repr(self): + self.assertEqual( + repr(self.layer_handler['model_giops']), + ' model_giops' + ) + class TestIdentify(unittest.TestCase, Setup): def setUp(self): @@ -305,11 +311,17 @@ def test_invalid_interval_identify2d(self): ) def test_unsuccessful_identify2d(self): - # assert identify returns False when the wx_variable isn't correct + # assert identify returns False when the wx_variable + # isn't correct and a warning is logged. self.filepath = self.filepath.replace('iiceconc', 'Not_wx_variable') - self.assertFalse( - self.layer_handler['model_giops'].identify(self.filepath) - ) + with self.assertLogs( + 'geomet_data_registry.layer.model_giops', level='WARNING' + ) as warn: + self.assertFalse( + self.layer_handler['model_giops'].identify(self.filepath) + ) + # assert a single LOGGER.warning was called + self.assertEqual(len(warn.records), 1) def test_successful_identify3d(self): @@ -399,11 +411,17 @@ def test_invalid_interval_identify3d(self): ) def test_unsuccessful_identify3d(self): - # assert identify returns False when the wx_variable isn't correct + # assert identify returns False when the wx_variable + # isn't correct and a warning is logged. self.filepath = self.filepath.replace('vosaline', 'Not wx_variable') - self.assertFalse( - self.layer_handler['model_giops'].identify(self.filepath) - ) + with self.assertLogs( + 'geomet_data_registry.layer.model_giops', level='WARNING' + ) as warn: + self.assertFalse( + self.layer_handler['model_giops'].identify(self.filepath) + ) + # assert a single LOGGER.warning was called + self.assertEqual(len(warn.records), 1) if __name__ == '__main__': diff --git a/tests/test_model_hrdps_continental.py b/tests/test_model_hrdps_continental.py index 560ad68..b872c0c 100644 --- a/tests/test_model_hrdps_continental.py +++ b/tests/test_model_hrdps_continental.py @@ -77,6 +77,12 @@ def test_super_init(self): {'name': 'model_hrdps_continental'} ) + def test_repr(self): + self.assertEqual( + repr(self.layer_handler['model_hrdps_continental']), + ' model_hrdps_continental' + ) + class TestIdentify(unittest.TestCase, Setup): def setUp(self): @@ -265,14 +271,21 @@ def test_invalid_interval_identify(self): ) def test_unsuccessful_identify(self): - # assert identify returns False when the wx_variable isn't correct + # assert identify returns False when the wx_variable + # isn't correct and a warning is logged. self.filepath = self.filepath.replace( 'ABSV_ISBL_0250', 'Not_wx_variable' ) - self.assertFalse( - self.layer_handler['model_hrdps_continental'] - .identify(self.filepath) - ) + with self.assertLogs( + 'geomet_data_registry.layer.model_hrdps_continental', + level='WARNING' + ) as warn: + self.assertFalse( + self.layer_handler['model_hrdps_continental'] + .identify(self.filepath) + ) + # assert a single LOGGER.warning was called + self.assertEqual(len(warn.records), 1) if __name__ == '__main__': diff --git a/tests/test_model_raqdps.py b/tests/test_model_raqdps.py index 91ad5f4..f123c27 100644 --- a/tests/test_model_raqdps.py +++ b/tests/test_model_raqdps.py @@ -72,6 +72,12 @@ def test_super_init(self): # assert super().__init__() was called with the correct provider def self.mocked_base_init.assert_called_with({'name': 'model_raqdps'}) + def test_repr(self): + self.assertEqual( + repr(self.layer_handler['model_raqdps']), + ' model_raqdps' + ) + class TestIdentify(unittest.TestCase, Setup): def setUp(self): @@ -180,11 +186,17 @@ def test_invalid_interval_identify(self): ) def test_unsuccessful_identify(self): - # assert identify returns False when the wx_variable isn't correct + # assert identify returns False when the wx_variable + # isn't correct and a warning is logged. self.filepath = self.filepath.replace('PM2.5_EAtm', 'Not_wx_variable') - self.assertFalse( - self.layer_handler['model_raqdps'].identify(self.filepath) - ) + with self.assertLogs( + 'geomet_data_registry.layer.model_raqdps', level='WARNING' + ) as warn: + self.assertFalse( + self.layer_handler['model_raqdps'].identify(self.filepath) + ) + # assert a single LOGGER.warning was called + self.assertEqual(len(warn.records), 1) if __name__ == '__main__': diff --git a/tests/test_model_raqdps_fw.py b/tests/test_model_raqdps_fw.py index ef16f47..1345d52 100644 --- a/tests/test_model_raqdps_fw.py +++ b/tests/test_model_raqdps_fw.py @@ -77,6 +77,12 @@ def test_super_init(self): # assert super().__init__() was called with the correct provider def self.mocked_base_init.assert_called_with({'name': 'model_raqdps-fw'}) + def test_repr(self): + self.assertEqual( + repr(self.layer_handler['model_raqdps_fw']), + ' model_raqdps-fw' + ) + class TestIdentify(unittest.TestCase, Setup): def setUp(self): @@ -187,11 +193,17 @@ def test_invalidInterval_identify(self): ) def test_unsuccessful_identify(self): - # assert identify returns False when the wx_variable isn't correct + # assert identify returns False when the wx_variable + # isn't correct and a warning is logged. self.filepath = self.filepath.replace('PM2.5_EAtm', 'Not_wx_variable') - self.assertFalse( - self.layer_handler['model_raqdps_fw'].identify(self.filepath) - ) + with self.assertLogs( + 'geomet_data_registry.layer.model_raqdps_fw', level='WARNING' + ) as warn: + self.assertFalse( + self.layer_handler['model_raqdps_fw'].identify(self.filepath) + ) + # assert a single LOGGER.warning was called + self.assertEqual(len(warn.records), 1) if __name__ == '__main__': diff --git a/tests/test_model_raqdps_fw_ce.py b/tests/test_model_raqdps_fw_ce.py index 109cb81..d043aca 100644 --- a/tests/test_model_raqdps_fw_ce.py +++ b/tests/test_model_raqdps_fw_ce.py @@ -84,6 +84,12 @@ def test_super_init(self): {'name': 'model_raqdps-fw-ce'} ) + def test_repr(self): + self.assertEqual( + repr(self.layer_handler['model_raqdps_fw_ce']), + ' model_raqdps-fw-ce' + ) + class TestIdentify(unittest.TestCase, Setup): def setUp(self): @@ -171,14 +177,20 @@ def test_items_identify(self): ) def test_unsuccessful_identify(self): - - # assert identify returns False when the wx_variable isn't correct + # assert identify returns False when the wx_variable + # isn't correct and a warning is logged. self.filepath = self.filepath.replace( 'PM2.5-DIFF-MAvg-DMax_SFC', 'Not_wx_variable' ) - self.assertFalse( - self.layer_handler['model_raqdps_fw_ce'].identify(self.filepath) - ) + with self.assertLogs( + 'geomet_data_registry.layer.model_raqdps_fw_ce', level='WARNING' + ) as warn: + self.assertFalse( + self.layer_handler['model_raqdps_fw_ce'] + .identify(self.filepath) + ) + # assert a single LOGGER.warning was called + self.assertEqual(len(warn.records), 1) class TestAddTimeKey(unittest.TestCase, Setup): @@ -248,9 +260,15 @@ def test_add_time_key_none(self): '{}/{}/P1M'.format(self.date_formatted, self.date_formatted), ), ] - self.assertTrue( - self.layer_handler['model_raqdps_fw_ce'].add_time_key() - ) + with self.assertLogs( + 'geomet_data_registry.layer.model_raqdps_fw_ce', level='WARNING' + ) as warn: + self.assertTrue( + self.layer_handler['model_raqdps_fw_ce'].add_time_key() + ) + # assert a single LOGGER.warning was called + self.assertEqual(len(warn.records), 1) + self.mocked_load_plugin.return_value.set_key.assert_has_calls( calls, any_order=True ) @@ -273,10 +291,16 @@ def test_add_time_key_prev_begin(self): '{}/{}/P1M'.format(self.date_formatted, prev_int_end_formatted), ) + with self.assertLogs( + 'geomet_data_registry.layer.model_raqdps_fw_ce', level='WARNING' + ) as warn: + self.assertTrue( + self.layer_handler['model_raqdps_fw_ce'].add_time_key() + ) + # assert a single LOGGER.warning was called + self.assertEqual(len(warn.records), 1) + # assert store.set_key called only once with the args above - self.assertTrue( - self.layer_handler['model_raqdps_fw_ce'].add_time_key() - ) self.mocked_load_plugin.return_value.set_key.assert_called_once_with( *call_args ) @@ -307,11 +331,17 @@ def test_add_time_key_prev_default_prev_end(self): ), ] - self.assertTrue( - self.layer_handler['model_raqdps_fw_ce'].add_time_key() - ) + with self.assertLogs( + 'geomet_data_registry.layer.model_raqdps_fw_ce', level='WARNING' + ) as warn: + self.assertTrue( + self.layer_handler['model_raqdps_fw_ce'].add_time_key() + ) + # assert a single LOGGER.warning was called + self.assertEqual(len(warn.records), 1) + self.mocked_load_plugin.return_value.set_key.assert_has_calls( - calls, any_order=True # noqa + calls, any_order=True ) diff --git a/tests/test_model_rdaqa_ce.py b/tests/test_model_rdaqa_ce.py index 83fb430..4246e6e 100644 --- a/tests/test_model_rdaqa_ce.py +++ b/tests/test_model_rdaqa_ce.py @@ -79,6 +79,12 @@ def test_super_init(self): # assert super().__init__() was called with the correct provider def self.mocked_base_init.assert_called_with({'name': 'model_rdaqa-ce'}) + def test_repr(self): + self.assertEqual( + repr(self.layer_handler['model_rdaqa_ce']), + ' model_rdaqa-ce' + ) + class TestIdentify(unittest.TestCase, Setup): def setUp(self): @@ -160,12 +166,17 @@ def test_items_identify(self): ) def test_unsuccessful_identify(self): - - # assert identify returns False when the wx_variable isn't correct + # assert identify returns False when the wx_variable + # isn't correct and a warning is logged. self.filepath = self.filepath.replace('O3-MAvg_SFC', 'Not_wx_variable') - self.assertFalse( - self.layer_handler['model_rdaqa_ce'].identify(self.filepath) - ) + with self.assertLogs( + 'geomet_data_registry.layer.model_rdaqa_ce', level='WARNING' + ) as warn: + self.assertFalse( + self.layer_handler['model_rdaqa_ce'].identify(self.filepath) + ) + # assert a single LOGGER.warning was called + self.assertEqual(len(warn.records), 1) class TestAddTimeKey(unittest.TestCase, Setup): @@ -227,7 +238,16 @@ def test_add_time_key_none(self): '{}/{}/P1M'.format(self.date_formatted, self.date_formatted), ), ] - self.assertTrue(self.layer_handler['model_rdaqa_ce'].add_time_key()) + + with self.assertLogs( + 'geomet_data_registry.layer.model_rdaqa_ce', level='WARNING' + ) as warn: + self.assertTrue( + self.layer_handler['model_rdaqa_ce'].add_time_key() + ) + # assert a single LOGGER.warning was called + self.assertEqual(len(warn.records), 1) + self.mocked_load_plugin.return_value.set_key.assert_has_calls( calls, any_order=True ) @@ -250,8 +270,16 @@ def test_add_time_key_prev_begin(self): '{}/{}/P1M'.format(self.date_formatted, prev_int_end_formatted), ) + with self.assertLogs( + 'geomet_data_registry.layer.model_rdaqa_ce', level='WARNING' + ) as warn: + self.assertTrue( + self.layer_handler['model_rdaqa_ce'].add_time_key() + ) + # assert a single LOGGER.warning was called + self.assertEqual(len(warn.records), 1) + # assert store.set_key called only once with the args above - self.assertTrue(self.layer_handler['model_rdaqa_ce'].add_time_key()) self.mocked_load_plugin.return_value.set_key.assert_called_once_with( *call_args ) @@ -281,7 +309,15 @@ def test_add_time_key_prev_default_prev_end(self): call('RDAQA.CE_O3-MAvg_default_time', self.date_formatted), ] - self.assertTrue(self.layer_handler['model_rdaqa_ce'].add_time_key()) + with self.assertLogs( + 'geomet_data_registry.layer.model_rdaqa_ce', level='WARNING' + ) as warn: + self.assertTrue( + self.layer_handler['model_rdaqa_ce'].add_time_key() + ) + # assert a single LOGGER.warning was called + self.assertEqual(len(warn.records), 1) + self.mocked_load_plugin.return_value.set_key.assert_has_calls( calls, any_order=True # noqa ) diff --git a/tests/test_model_riops.py b/tests/test_model_riops.py index 03a90c1..73907c3 100644 --- a/tests/test_model_riops.py +++ b/tests/test_model_riops.py @@ -71,6 +71,12 @@ def test_super_init(self): # assert super().__init__() was called with the correct provider def self.mocked_base_init.assert_called_with({'name': 'riops'}) + def test_repr(self): + self.assertEqual( + repr(self.layer_handler['model_riops']), + ' model_riops' + ) + class TestIdentify(unittest.TestCase, Setup): def setUp(self): @@ -305,9 +311,14 @@ def test_invalid_interval_identify2d(self): def test_unsuccessful_identify2d(self): # assert identify returns False when the wx_variable isn't correct self.filepath = self.filepath.replace('IICECONC', 'Not_wx_variable') - self.assertFalse( - self.layer_handler['model_riops'].identify(self.filepath) - ) + with self.assertLogs( + 'geomet_data_registry.layer.model_riops', level='WARNING' + ) as warn: + self.assertFalse( + self.layer_handler['model_riops'].identify(self.filepath) + ) + # assert a single LOGGER.warning was called + self.assertEqual(len(warn.records), 1) def test_successful_identify3d(self): @@ -399,9 +410,14 @@ def test_invalid_interval_identify3d(self): def test_unsuccessful_identify3d(self): # assert identify returns False when the wx_variable isn't correct self.filepath = self.filepath.replace('VOMECRTY', 'Not_wx_variable') - self.assertFalse( - self.layer_handler['model_riops'].identify(self.filepath) - ) + with self.assertLogs( + 'geomet_data_registry.layer.model_riops', level='WARNING' + ) as warn: + self.assertFalse( + self.layer_handler['model_riops'].identify(self.filepath) + ) + # assert a single LOGGER.warning was called + self.assertEqual(len(warn.records), 1) if __name__ == '__main__': diff --git a/tests/test_radar_1km.py b/tests/test_radar_1km.py index 6bdb886..3c93e67 100644 --- a/tests/test_radar_1km.py +++ b/tests/test_radar_1km.py @@ -73,6 +73,12 @@ def test_super_init(self): # assert super().__init__() was called with the correct provider def self.mocked_base_init.assert_called_with({'name': 'Radar_1km'}) + def test_repr(self): + self.assertEqual( + repr(self.layer_handler['radar_1km']), + ' Radar_1km' + ) + class TestIdentify(unittest.TestCase, Setup): def setUp(self): @@ -155,12 +161,17 @@ def test_items_identify(self): ) def test_unsuccessful_identify(self): - - # assert identify returns False when the wx_variable isn't correct + # assert identify returns False when the wx_variable + # isn't correct and a warning is logged. self.filepath = self.filepath.replace('MMHR', 'Not_wx_variable') - self.assertFalse( - self.layer_handler['radar_1km'].identify(self.filepath) - ) + with self.assertLogs( + 'geomet_data_registry.layer.radar_1km', level='WARNING' + ) as warn: + self.assertFalse( + self.layer_handler['radar_1km'].identify(self.filepath) + ) + # assert a single LOGGER.warning was called + self.assertEqual(len(warn.records), 1) class TestAddTimeKey(unittest.TestCase, Setup): @@ -230,8 +241,13 @@ def test_successful_add_time_key_none(self): # make last_key equal to None self.mocked_load_plugin.return_value.get_key.return_value = None - # assert time key was successfully added - self.assertTrue(self.layer_handler['radar_1km'].add_time_key()) + with self.assertLogs( + 'geomet_data_registry.layer.radar_1km', level='WARNING' + ) as warn: + # assert time key was successfully added + self.assertTrue(self.layer_handler['radar_1km'].add_time_key()) + # assert a single LOGGER.warning was called + self.assertEqual(len(warn.records), 1) # assert these 2 calls were made with store.set_key calls = [ @@ -251,8 +267,13 @@ def test_successful_add_time_key_missed_timestep(self): '2021-11-30T13:40:00Z' ) - # assert time key was successfully added - self.assertTrue(self.layer_handler['radar_1km'].add_time_key()) + with self.assertLogs( + 'geomet_data_registry.layer.radar_1km', level='ERROR' + ) as err: + # assert time key was successfully added + self.assertTrue(self.layer_handler['radar_1km'].add_time_key()) + # assert a single LOGGER.error was called + self.assertEqual(len(err.records), 1) # assert these 2 calls were made with store.set_key calls = [ diff --git a/tests/test_rdpa.py b/tests/test_rdpa.py index 3599079..a0de25b 100644 --- a/tests/test_rdpa.py +++ b/tests/test_rdpa.py @@ -73,6 +73,12 @@ def test_super_init(self): # assert super().__init__() was called with the correct provider def self.mocked_base_init.assert_called_with({'name': 'rdpa'}) + def test_repr(self): + self.assertEqual( + repr(self.layer_handler['rdpa']), + ' rdpa' + ) + class TestIdentify(unittest.TestCase, Setup): def setUp(self): @@ -223,12 +229,19 @@ def test_items_ps15km2011_identify(self): self.assertListEqual(expected_items, self.layer_handler['rdpa'].items) def test_unsuccessful_identify(self): - - # assert identify returns False when the wx_variable isn't correct + # assert identify returns False when the wx_variable + # isn't correct and a warning is logged. self.filepath = self.filepath.replace( 'APCP-006-0700cutoff_SFC_0', 'Not_wx_variable' ) - self.assertFalse(self.layer_handler['rdpa'].identify(self.filepath)) + with self.assertLogs( + 'geomet_data_registry.layer.rdpa', level='WARNING' + ) as warn: + self.assertFalse( + self.layer_handler['rdpa'].identify(self.filepath) + ) + # assert a single LOGGER.warning was called + self.assertEqual(len(warn.records), 1) class TestAddTimeKey(unittest.TestCase, Setup): diff --git a/tests/test_rdwps.py b/tests/test_rdwps.py index ac0ed2d..089e178 100644 --- a/tests/test_rdwps.py +++ b/tests/test_rdwps.py @@ -71,6 +71,12 @@ def test_super_init(self): # assert super().__init__() was called with the correct provider def self.mocked_base_init.assert_called_with({'name': 'rdwps'}) + def test_repr(self): + self.assertEqual( + repr(self.layer_handler['rdwps']), + ' rdwps' + ) + class TestIdentify(unittest.TestCase, Setup): def setUp(self): @@ -256,9 +262,17 @@ def test_invalid_interval_identify(self): ) def test_unsuccessful_identify(self): - # assert identify returns False when the wx_variable isn't correct + # assert identify returns False when the wx_variable + # isn't correct and a warning is logged. self.filepath = self.filepath.replace('HTSGW_Sfc', 'Not_wx_variable') - self.assertFalse(self.layer_handler['rdwps'].identify(self.filepath)) + with self.assertLogs( + 'geomet_data_registry.layer.rdwps', level='WARNING' + ) as warn: + self.assertFalse( + self.layer_handler['rdwps'].identify(self.filepath) + ) + # assert a single LOGGER.warning was called + self.assertEqual(len(warn.records), 1) if __name__ == '__main__': diff --git a/tests/test_reps.py b/tests/test_reps.py index b55e800..10b398e 100644 --- a/tests/test_reps.py +++ b/tests/test_reps.py @@ -71,6 +71,12 @@ def test_super_init(self): # assert super().__init__() was called with the correct provider def self.mocked_base_init.assert_called_with({'name': 'reps'}) + def test_repr(self): + self.assertEqual( + repr(self.layer_handler['reps']), + ' reps' + ) + class TestIdentify(unittest.TestCase, Setup): def setUp(self): @@ -229,11 +235,19 @@ def test_invalid_interval_identify(self): ) def test_unsuccessful_identify(self): - # assert identify returns False when the wx_variable isn't correct + # assert identify returns False when the wx_variable + # isn't correct and a warning is logged. self.filepath = self.filepath.replace( 'TPRATE-Accum-3h_SFC_0', 'Not_wx_variable' ) - self.assertFalse(self.layer_handler['reps'].identify(self.filepath)) + with self.assertLogs( + 'geomet_data_registry.layer.reps', level='WARNING' + ) as warn: + self.assertFalse( + self.layer_handler['reps'].identify(self.filepath) + ) + # assert a single LOGGER.warning was called + self.assertEqual(len(warn.records), 1) if __name__ == '__main__': diff --git a/tests/test_wcps.py b/tests/test_wcps.py index 26aa70b..6d8f827 100644 --- a/tests/test_wcps.py +++ b/tests/test_wcps.py @@ -69,6 +69,12 @@ def test_super_init(self): # assert super().__init__() was called with the correct provider def self.mocked_base_init.assert_called_with({'name': 'wcps'}) + def test_repr(self): + self.assertEqual( + repr(self.layer_handler['wcps']), + ' wcps' + ) + class TestIdentify(unittest.TestCase, Setup): def setUp(self): @@ -244,7 +250,14 @@ def test_unsuccessful_identify(self): self.filepath = self.filepath.replace( 'itmecrty_sfc_0', 'Not_wx_variable' ) - self.assertFalse(self.layer_handler['wcps'].identify(self.filepath)) + with self.assertLogs( + 'geomet_data_registry.layer.wcps', level='WARNING' + ) as warn: + self.assertFalse( + self.layer_handler['wcps'].identify(self.filepath) + ) + # assert a single LOGGER.warning was called + self.assertEqual(len(warn.records), 1) if __name__ == '__main__':