| 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 |
"""Test cycling utils.""" |
| 18 |
import pytest |
| 19 |
|
| 20 |
from cylc.flow.cycling.util import add_offset |
| 21 |
|
| 22 |
|
| 23 |
def test_add_offset(): |
| 24 |
"""Test socket start.""" |
| 25 |
orig_point = '20200202T0000Z' |
| 26 |
plus_offset = '+PT02H02M' |
| 27 |
assert str(add_offset(orig_point, plus_offset)) == '20200202T0202Z' |
| 28 |
minus_offset = '-P1MT22H59M' |
| 29 |
assert str(add_offset(orig_point, minus_offset)) == '20200101T0101Z' |
| 30 |
assert str( |
| 31 |
add_offset(orig_point, minus_offset, dmp_fmt="CCYY-MM-DDThh:mmZ") |
| 32 |
) == '2020-01-01T01:01Z' |
| 33 |
bad_offset = '+foo' |
| 34 |
with pytest.raises(ValueError, match=r'ERROR, bad offset format'): |
| 35 |
add_offset(orig_point, bad_offset) |