-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into chore/multiple-fix…
…es-ci-pre-commit
- Loading branch information
Showing
4 changed files
with
283 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# (C) Copyright 2023 European Centre for Medium-Range Weather Forecasts. | ||
# This software is licensed under the terms of the Apache Licence Version 2.0 | ||
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. | ||
# In applying this licence, ECMWF does not waive the privileges and immunities | ||
# granted to it by virtue of its status as an intergovernmental organisation | ||
# nor does it submit to any jurisdiction. | ||
|
||
import datetime | ||
|
||
from anemoi.utils.dates import frequency_to_string | ||
from anemoi.utils.dates import frequency_to_timedelta | ||
|
||
|
||
def test_frequency_to_string(): | ||
assert frequency_to_string(datetime.timedelta(hours=1)) == "1h" | ||
assert frequency_to_string(datetime.timedelta(hours=1, minutes=30)) == "1:30:00" | ||
assert frequency_to_string(datetime.timedelta(days=10)) == "10d" | ||
assert frequency_to_string(datetime.timedelta(minutes=10)) == "10m" | ||
assert frequency_to_string(datetime.timedelta(minutes=90)) == "1:30:00" | ||
|
||
|
||
def test_frequency_to_timedelta(): | ||
assert frequency_to_timedelta("1s") == datetime.timedelta(seconds=1) | ||
assert frequency_to_timedelta("3m") == datetime.timedelta(minutes=3) | ||
assert frequency_to_timedelta("1h") == datetime.timedelta(hours=1) | ||
assert frequency_to_timedelta("3d") == datetime.timedelta(days=3) | ||
assert frequency_to_timedelta("90m") == datetime.timedelta(hours=1, minutes=30) | ||
assert frequency_to_timedelta("0:30") == datetime.timedelta(minutes=30) | ||
assert frequency_to_timedelta("0:30:10") == datetime.timedelta(minutes=30, seconds=10) | ||
assert frequency_to_timedelta("1:30:10") == datetime.timedelta(hours=1, minutes=30, seconds=10) | ||
|
||
assert frequency_to_timedelta("PT10M") == datetime.timedelta(minutes=10) | ||
|
||
|
||
if __name__ == "__main__": | ||
test_frequency_to_string() | ||
test_frequency_to_timedelta() |