| 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 copy import deepcopy |
| 18 |
from time import time |
| 19 |
|
| 20 |
from cylc.flow.data_store_mgr import ( |
| 21 |
task_mean_elapsed_time, |
| 22 |
apply_delta, |
| 23 |
WORKFLOW, |
| 24 |
DELTAS_MAP, |
| 25 |
ALL_DELTAS, |
| 26 |
DATA_TEMPLATE |
| 27 |
) |
| 28 |
|
| 29 |
|
| 30 |
def int_id(): |
| 31 |
return '20130808T00/foo/03' |
| 32 |
|
| 33 |
|
| 34 |
class FakeTDef: |
| 35 |
elapsed_times = (0.0, 10.0) |
| 36 |
|
| 37 |
|
| 38 |
def test_task_mean_elapsed_time(): |
| 39 |
tdef = FakeTDef() |
| 40 |
result = task_mean_elapsed_time(tdef) |
| 41 |
assert result == 5 |
| 42 |
assert isinstance(result, int) |
| 43 |
|
| 44 |
|
| 45 |
def test_apply_delta(): |
| 46 |
"""Test delta application. |
| 47 |
|
| 48 |
Some functionality is not used at the Scheduler, so is not covered |
| 49 |
by integration testing. |
| 50 |
|
| 51 |
""" |
| 52 |
w_id = 'workflow_id' |
| 53 |
delta = DELTAS_MAP[ALL_DELTAS]() |
| 54 |
delta.workflow.time = time() |
| 55 |
flow = delta.workflow.updated |
| 56 |
flow.id = 'workflow_id' |
| 57 |
flow.stamp = f'{w_id}@{delta.workflow.time}' |
| 58 |
delta.workflow.pruned = w_id |
| 59 |
|
| 60 |
data = deepcopy(DATA_TEMPLATE) |
| 61 |
|
| 62 |
assert data[WORKFLOW].id != w_id |
| 63 |
assert data[WORKFLOW].pruned is False |
| 64 |
|
| 65 |
for field, sub_delta in delta.ListFields(): |
| 66 |
apply_delta(field.name, sub_delta, data) |
| 67 |
|
| 68 |
assert data[WORKFLOW].id == w_id |
| 69 |
assert data[WORKFLOW].pruned is True |