Skip to content

Commit

Permalink
Merge pull request #139 from mraspaud/fix-warning-multiple-sensors
Browse files Browse the repository at this point in the history
Fix warning issued when multiple sensors are provided
  • Loading branch information
pnuu authored Mar 1, 2022
2 parents e0f0211 + fd2649d commit 98e2c59
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
5 changes: 3 additions & 2 deletions trollflow2/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
35 changes: 35 additions & 0 deletions trollflow2/tests/test_trollflow2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 98e2c59

Please sign in to comment.