Skip to content
This repository has been archived by the owner on May 22, 2021. It is now read-only.

Commit

Permalink
[AIRFLOW-6456] Remove create_mock_args in CLI tests (apache#7044)
Browse files Browse the repository at this point in the history
  • Loading branch information
mik-laj authored and galuszkak committed Mar 5, 2020
1 parent b96d689 commit 83c6f93
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 121 deletions.
54 changes: 0 additions & 54 deletions tests/cli/commands/test_dag_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
import subprocess
import tempfile
import unittest
from argparse import Namespace
from datetime import datetime, time, timedelta
from unittest.mock import MagicMock

import mock
import pytz
Expand All @@ -45,58 +43,6 @@
TEST_DAG_ID = 'unit_tests'


def create_mock_args( # pylint: disable=too-many-arguments
task_id,
dag_id,
subdir,
execution_date,
task_params=None,
dry_run=False,
queue=None,
pool=None,
priority_weight_total=None,
retries=0,
local=True,
mark_success=False,
ignore_all_dependencies=False,
ignore_depends_on_past=False,
ignore_dependencies=False,
force=False,
run_as_user=None,
executor_config=None,
cfg_path=None,
pickle=None,
raw=None,
interactive=None,
):
if executor_config is None:
executor_config = {}
args = MagicMock(spec=Namespace)
args.task_id = task_id
args.dag_id = dag_id
args.subdir = subdir
args.task_params = task_params
args.execution_date = execution_date
args.dry_run = dry_run
args.queue = queue
args.pool = pool
args.priority_weight_total = priority_weight_total
args.retries = retries
args.local = local
args.run_as_user = run_as_user
args.executor_config = executor_config
args.cfg_path = cfg_path
args.pickle = pickle
args.raw = raw
args.mark_success = mark_success
args.ignore_all_dependencies = ignore_all_dependencies
args.ignore_depends_on_past = ignore_depends_on_past
args.ignore_dependencies = ignore_dependencies
args.force = force
args.interactive = interactive
return args


EXAMPLE_DAGS_FOLDER = os.path.join(
os.path.dirname(
os.path.dirname(
Expand Down
81 changes: 14 additions & 67 deletions tests/cli/commands/test_task_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@
#
import io
import unittest
from argparse import Namespace
from contextlib import redirect_stdout
from datetime import datetime, timedelta
from unittest import mock
from unittest.mock import MagicMock

from parameterized import parameterized

Expand All @@ -48,58 +46,6 @@ def reset(dag_id):
session.close()


def create_mock_args( # pylint: disable=too-many-arguments
task_id,
dag_id,
subdir,
execution_date,
task_params=None,
dry_run=False,
queue=None,
pool=None,
priority_weight_total=None,
retries=0,
local=True,
mark_success=False,
ignore_all_dependencies=False,
ignore_depends_on_past=False,
ignore_dependencies=False,
force=False,
run_as_user=None,
executor_config=None,
cfg_path=None,
pickle=None,
raw=None,
interactive=None,
):
if executor_config is None:
executor_config = {}
args = MagicMock(spec=Namespace)
args.task_id = task_id
args.dag_id = dag_id
args.subdir = subdir
args.task_params = task_params
args.execution_date = execution_date
args.dry_run = dry_run
args.queue = queue
args.pool = pool
args.priority_weight_total = priority_weight_total
args.retries = retries
args.local = local
args.run_as_user = run_as_user
args.executor_config = executor_config
args.cfg_path = cfg_path
args.pickle = pickle
args.raw = raw
args.mark_success = mark_success
args.ignore_all_dependencies = ignore_all_dependencies
args.ignore_depends_on_past = ignore_depends_on_past
args.ignore_dependencies = ignore_dependencies
args.force = force
args.interactive = interactive
return args


class TestCliTasks(unittest.TestCase):
@classmethod
def setUpClass(cls):
Expand All @@ -117,12 +63,9 @@ def test_cli_list_tasks(self):

def test_test(self):
"""Test the `airflow test` command"""
args = create_mock_args(
task_id='print_the_context',
dag_id='example_python_operator',
subdir=None,
execution_date=timezone.parse('2018-01-01')
)
args = self.parser.parse_args([
"tasks", "test", "example_python_operator", 'print_the_context', '2018-01-01'
])

with redirect_stdout(io.StringIO()) as stdout:
task_command.task_test(args)
Expand Down Expand Up @@ -232,13 +175,17 @@ def test_parentdag_downstream_clear(self):
task_command.task_clear(args)

def test_local_run(self):
args = create_mock_args(
task_id='print_the_context',
dag_id='example_python_operator',
subdir='/root/dags/example_python_operator.py',
interactive=True,
execution_date=timezone.parse('2018-04-27T08:39:51.298439+00:00')
)
args = self.parser.parse_args([
'tasks',
'run',
'example_python_operator',
'print_the_context',
'2018-04-27T08:39:51.298439+00:00',
'--interactive',
'--subdir',
'/root/dags/example_python_operator.py'
])

dag = get_dag(args.subdir, args.dag_id)
reset(dag.dag_id)

Expand Down

0 comments on commit 83c6f93

Please sign in to comment.