Exemplo n.º 1
0
    def test_backfill(self, mock_run):
        dag_command.dag_backfill(self.parser.parse_args([
            'dags', 'backfill', 'example_bash_operator',
            '--start-date', DEFAULT_DATE.isoformat()]))

        mock_run.assert_called_once_with(
            start_date=DEFAULT_DATE,
            end_date=DEFAULT_DATE,
            conf=None,
            delay_on_limit_secs=1.0,
            donot_pickle=False,
            ignore_first_depends_on_past=False,
            ignore_task_deps=False,
            local=False,
            mark_success=False,
            pool=None,
            rerun_failed_tasks=False,
            run_backwards=False,
            verbose=False,
        )
        mock_run.reset_mock()
        dag = self.dagbag.get_dag('example_bash_operator')

        with contextlib.redirect_stdout(io.StringIO()) as stdout:
            dag_command.dag_backfill(self.parser.parse_args([
                'dags', 'backfill', 'example_bash_operator', '--task-regex', 'runme_0', '--dry-run',
                '--start-date', DEFAULT_DATE.isoformat()]), dag=dag)

        output = stdout.getvalue()
        self.assertIn("Dry run of DAG example_bash_operator on {}\n".format(DEFAULT_DATE.isoformat()), output)
        self.assertIn("Task runme_0\n", output)

        mock_run.assert_not_called()  # Dry run shouldn't run the backfill

        dag_command.dag_backfill(self.parser.parse_args([
            'dags', 'backfill', 'example_bash_operator', '--dry-run',
            '--start-date', DEFAULT_DATE.isoformat()]), dag=dag)

        mock_run.assert_not_called()  # Dry run shouldn't run the backfill

        dag_command.dag_backfill(self.parser.parse_args([
            'dags', 'backfill', 'example_bash_operator', '--local',
            '--start-date', DEFAULT_DATE.isoformat()]), dag=dag)

        mock_run.assert_called_once_with(
            start_date=DEFAULT_DATE,
            end_date=DEFAULT_DATE,
            conf=None,
            delay_on_limit_secs=1.0,
            donot_pickle=False,
            ignore_first_depends_on_past=False,
            ignore_task_deps=False,
            local=True,
            mark_success=False,
            pool=None,
            rerun_failed_tasks=False,
            run_backwards=False,
            verbose=False,
        )
        mock_run.reset_mock()
Exemplo n.º 2
0
    def test_cli_backfill_depends_on_past_backwards(self, mock_run):
        """
        Test that CLI respects -B argument and raises on interaction with depends_on_past
        """
        dag_id = 'test_depends_on_past'
        start_date = DEFAULT_DATE + timedelta(days=1)
        end_date = start_date + timedelta(days=1)
        args = [
            'dags',
            'backfill',
            dag_id,
            '--local',
            '--start-date',
            start_date.isoformat(),
            '--end-date',
            end_date.isoformat(),
            '--ignore-first-depends-on-past',
            '--run-backwards',
        ]
        dag = self.dagbag.get_dag(dag_id)

        dag_command.dag_backfill(self.parser.parse_args(args), dag=dag)
        mock_run.assert_called_once_with(
            start_date=start_date,
            end_date=end_date,
            conf=None,
            delay_on_limit_secs=1.0,
            donot_pickle=False,
            ignore_first_depends_on_past=True,
            ignore_task_deps=False,
            local=True,
            mark_success=False,
            pool=None,
            rerun_failed_tasks=False,
            run_backwards=True,
            verbose=False,
        )
Exemplo n.º 3
0
    def test_cli_backfill_depends_on_past(self, mock_run):
        """
        Test that CLI respects -I argument

        We just check we call dag.run() right. The behaviour of that kwarg is
        tested in test_jobs
        """
        dag_id = 'test_dagrun_states_deadlock'
        run_date = DEFAULT_DATE + timedelta(days=1)
        args = [
            'dags',
            'backfill',
            dag_id,
            '--local',
            '--start-date',
            run_date.isoformat(),
            '--ignore-first-depends-on-past',
        ]
        dag = self.dagbag.get_dag(dag_id)

        dag_command.dag_backfill(self.parser.parse_args(args), dag=dag)

        mock_run.assert_called_once_with(
            start_date=run_date,
            end_date=run_date,
            conf=None,
            delay_on_limit_secs=1.0,
            donot_pickle=False,
            ignore_first_depends_on_past=True,
            ignore_task_deps=False,
            local=True,
            mark_success=False,
            pool=None,
            rerun_failed_tasks=False,
            run_backwards=False,
            verbose=False,
        )
Exemplo n.º 4
0
    def test_backfill(self, mock_run):
        dag_command.dag_backfill(
            self.parser.parse_args([
                'dags', 'backfill', 'example_bash_operator', '-s',
                DEFAULT_DATE.isoformat()
            ]))

        mock_run.assert_called_once_with(
            start_date=DEFAULT_DATE,
            end_date=DEFAULT_DATE,
            conf=None,
            delay_on_limit_secs=1.0,
            donot_pickle=False,
            ignore_first_depends_on_past=False,
            ignore_task_deps=False,
            local=False,
            mark_success=False,
            pool=None,
            rerun_failed_tasks=False,
            run_backwards=False,
            verbose=False,
        )
        mock_run.reset_mock()
        dag = self.dagbag.get_dag('example_bash_operator')

        with mock.patch('sys.stdout', new_callable=io.StringIO) as mock_stdout:
            dag_command.dag_backfill(self.parser.parse_args([
                'dags', 'backfill', 'example_bash_operator', '-t', 'runme_0',
                '--dry_run', '-s',
                DEFAULT_DATE.isoformat()
            ]),
                                     dag=dag)

        mock_stdout.seek(0, 0)

        output = mock_stdout.read()
        self.assertIn(
            "Dry run of DAG example_bash_operator on {}\n".format(
                DEFAULT_DATE.isoformat()), output)
        self.assertIn("Task runme_0\n".format(DEFAULT_DATE.isoformat()),
                      output)

        mock_run.assert_not_called()  # Dry run shouldn't run the backfill

        dag_command.dag_backfill(self.parser.parse_args([
            'dags', 'backfill', 'example_bash_operator', '--dry_run', '-s',
            DEFAULT_DATE.isoformat()
        ]),
                                 dag=dag)

        mock_run.assert_not_called()  # Dry run shouldn't run the backfill

        dag_command.dag_backfill(self.parser.parse_args([
            'dags', 'backfill', 'example_bash_operator', '-l', '-s',
            DEFAULT_DATE.isoformat()
        ]),
                                 dag=dag)

        mock_run.assert_called_once_with(
            start_date=DEFAULT_DATE,
            end_date=DEFAULT_DATE,
            conf=None,
            delay_on_limit_secs=1.0,
            donot_pickle=False,
            ignore_first_depends_on_past=False,
            ignore_task_deps=False,
            local=True,
            mark_success=False,
            pool=None,
            rerun_failed_tasks=False,
            run_backwards=False,
            verbose=False,
        )
        mock_run.reset_mock()