Skip to content
Merged
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
33 changes: 33 additions & 0 deletions tests/utils/test_patterns.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python3

# (C) Copyright 2020 ECMWF.
#
# 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

import pytest

from earthkit.data.utils.patterns import Pattern


@pytest.mark.parametrize(
"pattern,values,expected_value",
[
("test.{format}", {"format": ["nc", "grib"]}, ["test.nc", "test.grib"]),
("test_{id}.grib", {"id": [2, 3, "AA"]}, ["test_2.grib", "test_3.grib", "test_AA.grib"]),
(
"test_{my_date:date(%Y-%m-%d)}_{name}.grib",
{"my_date": datetime.datetime(2020, 5, 13), "name": ["t2", "msl"]},
["test_2020-05-13_t2.grib", "test_2020-05-13_msl.grib"],
),
],
)
def test_pattern_core(pattern, values, expected_value):
p = Pattern(pattern)
assert p.substitute(values) == expected_value
Loading