Coverage for /pythoncovmergedfiles/medio/medio/src/airflow/tests/macros/test_macros.py: 0%
18 statements
« prev ^ index » next coverage.py v7.0.1, created at 2022-12-25 06:11 +0000
« prev ^ index » next coverage.py v7.0.1, created at 2022-12-25 06:11 +0000
1#
2# Licensed to the Apache Software Foundation (ASF) under one
3# or more contributor license agreements. See the NOTICE file
4# distributed with this work for additional information
5# regarding copyright ownership. The ASF licenses this file
6# to you under the Apache License, Version 2.0 (the
7# "License"); you may not use this file except in compliance
8# with the License. You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing,
13# software distributed under the License is distributed on an
14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15# KIND, either express or implied. See the License for the
16# specific language governing permissions and limitations
17# under the License.
18from __future__ import annotations
20import lazy_object_proxy
21import pendulum
22import pytest
24from airflow import macros
25from airflow.utils import timezone
28@pytest.mark.parametrize(
29 "ds, days, expected",
30 [
31 ("2015-01-01", 5, "2015-01-06"),
32 ("2015-01-02", 0, "2015-01-02"),
33 ("2015-01-06", -5, "2015-01-01"),
34 (lazy_object_proxy.Proxy(lambda: "2015-01-01"), 5, "2015-01-06"),
35 (lazy_object_proxy.Proxy(lambda: "2015-01-02"), 0, "2015-01-02"),
36 (lazy_object_proxy.Proxy(lambda: "2015-01-06"), -5, "2015-01-01"),
37 ],
38)
39def test_ds_add(ds, days, expected):
40 result = macros.ds_add(ds, days)
41 assert result == expected
44@pytest.mark.parametrize(
45 "ds, input_format, output_format, expected",
46 [
47 ("2015-01-02", "%Y-%m-%d", "%m-%d-%y", "01-02-15"),
48 ("2015-01-02", "%Y-%m-%d", "%Y-%m-%d", "2015-01-02"),
49 ("1/5/2015", "%m/%d/%Y", "%m-%d-%y", "01-05-15"),
50 ("1/5/2015", "%m/%d/%Y", "%Y-%m-%d", "2015-01-05"),
51 (lazy_object_proxy.Proxy(lambda: "2015-01-02"), "%Y-%m-%d", "%m-%d-%y", "01-02-15"),
52 (lazy_object_proxy.Proxy(lambda: "2015-01-02"), "%Y-%m-%d", "%Y-%m-%d", "2015-01-02"),
53 (lazy_object_proxy.Proxy(lambda: "1/5/2015"), "%m/%d/%Y", "%m-%d-%y", "01-05-15"),
54 (lazy_object_proxy.Proxy(lambda: "1/5/2015"), "%m/%d/%Y", "%Y-%m-%d", "2015-01-05"),
55 ],
56)
57def test_ds_format(ds, input_format, output_format, expected):
58 result = macros.ds_format(ds, input_format, output_format)
59 assert result == expected
62@pytest.mark.parametrize(
63 "dt, since, expected",
64 [
65 (
66 timezone.datetime(2017, 1, 2),
67 None,
68 pendulum.instance(timezone.datetime(2017, 1, 2)).diff_for_humans(),
69 ),
70 (timezone.datetime(2017, 1, 2), timezone.datetime(2017, 1, 3), "1 day before"),
71 (timezone.datetime(2017, 1, 2), timezone.datetime(2017, 1, 1), "1 day after"),
72 (
73 lazy_object_proxy.Proxy(lambda: timezone.datetime(2017, 1, 2)),
74 None,
75 pendulum.instance(timezone.datetime(2017, 1, 2)).diff_for_humans(),
76 ),
77 (
78 lazy_object_proxy.Proxy(lambda: timezone.datetime(2017, 1, 2)),
79 timezone.datetime(2017, 1, 3),
80 "1 day before",
81 ),
82 (
83 lazy_object_proxy.Proxy(lambda: timezone.datetime(2017, 1, 2)),
84 timezone.datetime(2017, 1, 1),
85 "1 day after",
86 ),
87 ],
88)
89def test_datetime_diff_for_humans(dt, since, expected):
90 result = macros.datetime_diff_for_humans(dt, since)
91 assert result == expected