From 2d26ded42030696f7126467514a9fd746b15be88 Mon Sep 17 00:00:00 2001 From: Martin Raspaud Date: Tue, 1 Mar 2022 11:03:17 +0100 Subject: [PATCH 1/2] Fix warning issued when multiple sensors are provided --- trollflow2/plugins/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/trollflow2/plugins/__init__.py b/trollflow2/plugins/__init__.py index 6e3a593b..66e2e4b7 100644 --- a/trollflow2/plugins/__init__.py +++ b/trollflow2/plugins/__init__.py @@ -421,9 +421,10 @@ def covers(job): end_time = scn_mda['end_time'] sensor = scn_mda['sensor'] if isinstance(sensor, (list, tuple, set)): + if len(sensor) > 1: + LOG.warning("Multiple sensors given, taking the first one for " + "coverage calculations: %s", sensor) sensor = list(sensor)[0] - LOG.warning("Possibly many sensors given, taking only one for " - "coverage calculations: %s", sensor) areas = list(product_list['product_list']['areas'].keys()) for area in areas: From fd2649dbb2ce390c9a2dda5a81544c333064af37 Mon Sep 17 00:00:00 2001 From: Martin Raspaud Date: Tue, 1 Mar 2022 11:32:22 +0100 Subject: [PATCH 2/2] Add tests for warning issued when multiple sensors are provided --- trollflow2/tests/test_trollflow2.py | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/trollflow2/tests/test_trollflow2.py b/trollflow2/tests/test_trollflow2.py index 2ff0d06b..f695aa4b 100644 --- a/trollflow2/tests/test_trollflow2.py +++ b/trollflow2/tests/test_trollflow2.py @@ -1110,6 +1110,41 @@ def test_covers_no_trollsched(self): covers(job) self.assertEqual(job, job_orig) + def test_covers_complains_when_multiple_sensors_are_provided(self): + """Test that the plugin complains when multiple sensors are provided.""" + from trollflow2.plugins import covers + + with mock.patch('trollflow2.plugins.get_scene_coverage') as get_scene_coverage, \ + mock.patch('trollflow2.plugins.Pass'): + get_scene_coverage.return_value = 10.0 + scn = _get_mocked_scene_with_properties() + job = {"product_list": self.product_list, + "input_mda": {"platform_name": "platform", + "sensor": ["avhrr-3", "mhs"]}, + "scene": scn} + with self.assertLogs("trollflow2.plugins", logging.WARNING) as log: + covers(job) + assert len(log.output) == 1 + assert ("Multiple sensors given, taking the first one for coverage calculations" in log.output[0]) + + def test_covers_does_not_complain_when_one_sensor_is_provided_as_a_sequence(self): + """Test that the plugin complains when multiple sensors are provided.""" + from trollflow2.plugins import covers + + with mock.patch('trollflow2.plugins.get_scene_coverage') as get_scene_coverage, \ + mock.patch('trollflow2.plugins.Pass'): + get_scene_coverage.return_value = 10.0 + scn = _get_mocked_scene_with_properties() + job = {"product_list": self.product_list, + "input_mda": {"platform_name": "platform", + "sensor": ["avhrr-3"]}, + "scene": scn} + with self.assertLogs("trollflow2.plugins", logging.WARNING) as log: + covers(job) + logger = logging.getLogger("trollflow2.plugins") + logger.warning("Dummy warning") + assert len(log.output) == 1 + def test_metadata_is_read_from_scene(self): """Test that the scene and message metadata are merged correctly.""" from trollflow2.plugins import covers