| 1 |
# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE. |
| 2 |
# Copyright (C) NIWA & British Crown (Met Office) & Contributors. |
| 3 |
# |
| 4 |
# This program is free software: you can redistribute it and/or modify |
| 5 |
# it under the terms of the GNU General Public License as published by |
| 6 |
# the Free Software Foundation, either version 3 of the License, or |
| 7 |
# (at your option) any later version. |
| 8 |
# |
| 9 |
# This program is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License |
| 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
|
| 17 |
from collections import deque |
| 18 |
from pathlib import Path |
| 19 |
|
| 20 |
import pytest |
| 21 |
|
| 22 |
from cylc.flow.main_loop.log_main_loop import ( |
| 23 |
_normalise, |
| 24 |
_dump, |
| 25 |
_plot |
| 26 |
) |
| 27 |
|
| 28 |
|
| 29 |
@pytest.fixture() |
| 30 |
def test_data(): |
| 31 |
return { |
| 32 |
# (plugin_name, coro_name): deque([(start_time, duration), ...]) |
| 33 |
('foo', 'bar'): deque([(2, 1), (3, 2), (4, 3)]), |
| 34 |
('baz', 'pub'): deque([(1, 4), (2, 5), (3, 6)]), |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
def test_normalise(test_data): |
| 39 |
"""Ensure we correctly normalise the timings against the earliest time.""" |
| 40 |
assert _normalise(test_data) == { |
| 41 |
'foo': [(1, 1), (2, 2), (3, 3)], |
| 42 |
'baz': [(0, 4), (1, 5), (2, 6)], |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
def test_dump(test_data, tmp_path): |
| 47 |
"""Ensure the data is serialisable.""" |
| 48 |
assert _dump(_normalise(test_data), tmp_path) |
| 49 |
assert list(tmp_path.iterdir()) == [ |
| 50 |
Path(tmp_path, 'cylc.flow.main_loop.log_main_loop.json') |
| 51 |
] |
| 52 |
|
| 53 |
|
| 54 |
def test_plot(test_data, tmp_path): |
| 55 |
"""Ensure the plotting mechanism doesn't raise errors.""" |
| 56 |
assert _plot(_normalise(test_data), tmp_path) |
| 57 |
assert list(tmp_path.iterdir()) == [ |
| 58 |
Path(tmp_path, 'cylc.flow.main_loop.log_main_loop.pdf') |
| 59 |
] |