def test_raise_exception_on_non_zero_exit_code(self):
     bash_operator = BashOperator(bash_command='exit 42',
                                  task_id='test_return_value',
                                  dag=None)
     with self.assertRaisesRegex(
             AirflowException,
             "Bash command failed\\. The command returned a non-zero exit code\\."
     ):
         bash_operator.execute(context={})
Пример #2
0
def python_function():

    bash_task = BashOperator (
        task_id = 'bash_task',
        #bash_command = 'echo sandip',
        bash_command = 'sleep 30'
    )

    bash_task.execute(dict())
Пример #3
0
    def test_should_exec_subprocess(self, mock_popen, mock_temporary_directory):
        bash_operator = BashOperator(bash_command='echo "stdout"', task_id='test_return_value', dag=None)
        bash_operator.execute({})

        mock_popen.assert_called_once_with(
            ['bash', '-c', 'echo "stdout"'],
            cwd='/tmp/airflowtmpcatcat',
            env={},
            preexec_fn=mock.ANY,
            stderr=STDOUT,
            stdout=PIPE,
        )
    def test_return_value(self):
        bash_operator = BashOperator(bash_command='echo "stdout"',
                                     task_id='test_return_value',
                                     dag=None)
        return_value = bash_operator.execute(context={})

        self.assertEqual(return_value, 'stdout')
Пример #5
0
 def test_skip(self):
     op = BashOperator(task_id='abc',
                       bash_command='set -e; echo "hello world"; exit 127;')
     with pytest.raises(AirflowSkipException):
         op.execute({})
Пример #6
0
 def test_return_value(self, val, expected):
     op = BashOperator(task_id='abc', bash_command=f'set -e; echo "{val}";')
     line = op.execute({})
     assert line == expected
Пример #7
0
def test_example():
    task = BashOperator(task_id="test",
                        bash_command="echo 'hello!'",
                        xcom_push=True)
    result = task.execute(context={})
    assert result == "hello!"