Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for bugs #25

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
10 changes: 8 additions & 2 deletions tests/dags/good/example_bash_operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ dags:
runme_{{ item }}:
class: airflow.operators.bash_operator:BashOperator
args:
bash_command: '{% raw %} echo "{{ task_instance_key_str }}" && sleep 1 {% endraw%}'
bash_command: |
{% raw %}
echo "The following will not be interpreted by jinja:"
echo "{{ task_instance_key_str }}" && sleep 1
{% endraw%}
flow:
runme_{{ item }}:
- run_after_loop
Expand All @@ -46,7 +50,9 @@ dags:
also_run_this:
class: airflow.operators.bash_operator:BashOperator
args:
bash_command: echo "run_id={{ run_id }} | dag_run={{ dag_run }}"
bash_command: |
echo "A bash command:"
echo "run_id={{ run_id }} | dag_run={{ dag_run }}"
run_after_loop:
class: airflow.operators.bash_operator:BashOperator
args:
Expand Down
45 changes: 45 additions & 0 deletions tests/dags/good/timedelta-sensor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#
# Copyright 2019, Rambler Digital Solutions
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#


dags:
time_delta_sensor:
args:
start_date: 2017-07-27
schedule_interval: 1d
operators:
dummy_operator:
class: airflow.operators.dummy_operator:DummyOperator
sensors:
timedelta_sensor:
class: airflow.operators.sensors:TimeDeltaSensor
args:
delta: 6h
flow:
timedelta_sensor:
- dummy_operator
do:
- sensors:
dynamic_timedelta_sensor_{{ item.name }}:
class: airflow.operators.sensors:TimeDeltaSensor
args:
delta: '{{ item.sensor_delta }}'
flow:
dynamic_timedelta_sensor_{{ item.name }}:
- dummy_operator
with_items:
- name: 1h
sensor_delta: 1h
8 changes: 8 additions & 0 deletions tests/test_example_bash_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ def test_example_bash_operator(good_dag_path):
}
assert set(yml_dag.task_ids) == expected_tasks

also_run_this = yml_dag.task_dict["also_run_this"]
assert isinstance(also_run_this, BaseOperator)
assert "\n" in also_run_this.bash_command

runme_0 = yml_dag.task_dict["runme_0"]
assert isinstance(runme_0, BaseOperator)
assert "\n" in runme_0.bash_command

run_after_loop = yml_dag.task_dict["run_after_loop"]
assert isinstance(run_after_loop, BaseOperator)
assert run_after_loop.bash_command == "echo 1"
Expand Down
59 changes: 59 additions & 0 deletions tests/test_timedelta_sensor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# -*- coding: utf-8 -*-
#
# Copyright 2019, Rambler Digital Solutions
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from __future__ import absolute_import, division, print_function, unicode_literals

import datetime

from airflow import DAG

import airflow_declarative


try:
# Since Airflow 1.10
from airflow.sensors.time_delta_sensor import TimeDeltaSensor
except ImportError:
from airflow.operators.sensors import TimeDeltaSensor


def test_timedelta_sensor(good_dag_path):
path = good_dag_path("timedelta-sensor")
dags = airflow_declarative.from_path(path)

assert len(dags) == 1

yml_dag = dags[0]

assert isinstance(yml_dag, DAG)

expected_tasks = {
"dummy_operator",
"timedelta_sensor",
"dynamic_timedelta_sensor_1h",
}
assert set(yml_dag.task_ids) == expected_tasks

timedelta_sensor = yml_dag.task_dict["timedelta_sensor"]
assert isinstance(timedelta_sensor, TimeDeltaSensor)
assert isinstance(timedelta_sensor.delta, datetime.timedelta)
assert 6 == timedelta_sensor.delta.hours

dynamic_timedelta_sensor_1h = yml_dag.task_dict["dynamic_timedelta_sensor_1h"]
assert isinstance(dynamic_timedelta_sensor_1h, TimeDeltaSensor)
assert isinstance(dynamic_timedelta_sensor_1h.delta, datetime.timedelta)
assert 1 == dynamic_timedelta_sensor_1h.delta.hours