Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix log message printing the number of loaded composites #220

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion trollflow2/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def load_composites(job):
else:
composites_by_res.setdefault(res, set()).add(flat_prod_cfg['product'])

logger.info(f"Loading {len(composites_by_res)} composites.")
num_composites = sum([len(composites_by_res[d]) for d in composites_by_res])
logger.info(f"Loading {num_composites} composites.")

scn = job['scene']
generate = job['product_list']['product_list'].get('delay_composites', True) is False
Expand Down
21 changes: 17 additions & 4 deletions trollflow2/tests/test_trollflow2.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,11 @@ def test_create_scene(self):
class TestLoadComposites(TestCase):
"""Test case for loading composites."""

@pytest.fixture(autouse=True)
def inject_fixtures(self, caplog):
"""Inject fixtures."""
self._caplog = caplog
Comment on lines +847 to +850
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the benefit of storing a _caplog attribute and using that, rather than using the caplog attribute in the tests directly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only way to use fixtures in unittest.TestCase classes.


def setUp(self):
"""Set up the test case."""
super().setUp()
Expand All @@ -855,7 +860,9 @@ def test_load_composites(self):
from trollflow2.plugins import DEFAULT, load_composites
scn = _get_mocked_scene_with_properties()
job = {"product_list": self.product_list, "scene": scn}
load_composites(job)
with self._caplog.at_level(logging.INFO):
load_composites(job)
assert "Loading 3 composites." in self._caplog.text
scn.load.assert_called_with({'ct', 'cloudtype', 'cloud_top_height'}, resolution=DEFAULT, generate=False)

def test_load_composites_with_config(self):
Expand All @@ -865,7 +872,9 @@ def test_load_composites_with_config(self):
self.product_list['product_list']['resolution'] = 1000
self.product_list['product_list']['delay_composites'] = False
job = {"product_list": self.product_list, "scene": scn}
load_composites(job)
with self._caplog.at_level(logging.INFO):
load_composites(job)
assert "Loading 3 composites." in self._caplog.text
scn.load.assert_called_with({'ct', 'cloudtype', 'cloud_top_height'}, resolution=1000, generate=True)

def test_load_composites_with_different_resolutions(self):
Expand All @@ -876,7 +885,9 @@ def test_load_composites_with_different_resolutions(self):
self.product_list['product_list']['areas']['euron1']['resolution'] = 500
self.product_list['product_list']['delay_composites'] = False
job = {"product_list": self.product_list, "scene": scn}
load_composites(job)
with self._caplog.at_level(logging.INFO):
load_composites(job)
assert "Loading 4 composites." in self._caplog.text
scn.load.assert_any_call({'cloudtype', 'ct', 'cloud_top_height'}, resolution=1000, generate=True)
scn.load.assert_any_call({'cloud_top_height'}, resolution=500, generate=True)

Expand All @@ -886,7 +897,9 @@ def test_load_composites_with_custom_args(self):
scn = _get_mocked_scene_with_properties()
self.product_list['product_list']['scene_load_kwargs'] = {"upper_right_corner": "NE"}
job = {"product_list": self.product_list, "scene": scn}
load_composites(job)
with self._caplog.at_level(logging.INFO):
load_composites(job)
assert "Loading 3 composites." in self._caplog.text
scn.load.assert_called_with(
{'ct', 'cloudtype', 'cloud_top_height'},
resolution=DEFAULT, generate=False, upper_right_corner="NE")
Expand Down
Loading