forked from apache/airflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add backward compatibility with old versions of Apache Beam (apache#2…
- Loading branch information
Showing
5 changed files
with
81 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,11 +18,13 @@ | |
|
||
import copy | ||
import os | ||
import re | ||
import subprocess | ||
import unittest | ||
from unittest import mock | ||
from unittest.mock import MagicMock | ||
|
||
import pytest | ||
from parameterized import parameterized | ||
|
||
from airflow.exceptions import AirflowException | ||
|
@@ -58,7 +60,8 @@ | |
|
||
class TestBeamHook(unittest.TestCase): | ||
@mock.patch(BEAM_STRING.format("BeamCommandRunner")) | ||
def test_start_python_pipeline(self, mock_runner): | ||
@mock.patch("airflow.providers.apache.beam.hooks.beam.subprocess.check_output", return_value=b"2.39.0") | ||
def test_start_python_pipeline(self, mock_check_output, mock_runner): | ||
hook = BeamHook(runner=DEFAULT_RUNNER) | ||
wait_for_done = mock_runner.return_value.wait_for_done | ||
process_line_callback = MagicMock() | ||
|
@@ -83,6 +86,26 @@ def test_start_python_pipeline(self, mock_runner): | |
) | ||
wait_for_done.assert_called_once_with() | ||
|
||
@mock.patch("airflow.providers.apache.beam.hooks.beam.subprocess.check_output", return_value=b"2.35.0") | ||
def test_start_python_pipeline_unsupported_option(self, mock_check_output): | ||
hook = BeamHook(runner=DEFAULT_RUNNER) | ||
|
||
with pytest.raises( | ||
AirflowException, | ||
match=re.escape("The impersonateServiceAccount option requires Apache Beam 2.39.0 or newer."), | ||
): | ||
hook.start_python_pipeline( | ||
variables={ | ||
"impersonate_service_account": "[email protected]", | ||
}, | ||
py_file="/tmp/file.py", | ||
py_options=["-m"], | ||
py_interpreter="python3", | ||
py_requirements=None, | ||
py_system_site_packages=False, | ||
process_line_callback=MagicMock(), | ||
) | ||
|
||
@parameterized.expand( | ||
[ | ||
("default_to_python3", "python3"), | ||
|
@@ -92,7 +115,10 @@ def test_start_python_pipeline(self, mock_runner): | |
] | ||
) | ||
@mock.patch(BEAM_STRING.format("BeamCommandRunner")) | ||
def test_start_python_pipeline_with_custom_interpreter(self, _, py_interpreter, mock_runner): | ||
@mock.patch("airflow.providers.apache.beam.hooks.beam.subprocess.check_output", return_value=b"2.39.0") | ||
def test_start_python_pipeline_with_custom_interpreter( | ||
self, _, py_interpreter, mock_check_output, mock_runner | ||
): | ||
hook = BeamHook(runner=DEFAULT_RUNNER) | ||
wait_for_done = mock_runner.return_value.wait_for_done | ||
process_line_callback = MagicMock() | ||
|
@@ -127,8 +153,14 @@ def test_start_python_pipeline_with_custom_interpreter(self, _, py_interpreter, | |
) | ||
@mock.patch(BEAM_STRING.format("prepare_virtualenv")) | ||
@mock.patch(BEAM_STRING.format("BeamCommandRunner")) | ||
@mock.patch("airflow.providers.apache.beam.hooks.beam.subprocess.check_output", return_value=b"2.39.0") | ||
def test_start_python_pipeline_with_non_empty_py_requirements_and_without_system_packages( | ||
self, current_py_requirements, current_py_system_site_packages, mock_runner, mock_virtualenv | ||
self, | ||
current_py_requirements, | ||
current_py_system_site_packages, | ||
mock_check_output, | ||
mock_runner, | ||
mock_virtualenv, | ||
): | ||
hook = BeamHook(runner=DEFAULT_RUNNER) | ||
wait_for_done = mock_runner.return_value.wait_for_done | ||
|
@@ -164,7 +196,10 @@ def test_start_python_pipeline_with_non_empty_py_requirements_and_without_system | |
) | ||
|
||
@mock.patch(BEAM_STRING.format("BeamCommandRunner")) | ||
def test_start_python_pipeline_with_empty_py_requirements_and_without_system_packages(self, mock_runner): | ||
@mock.patch("airflow.providers.apache.beam.hooks.beam.subprocess.check_output", return_value=b"2.39.0") | ||
def test_start_python_pipeline_with_empty_py_requirements_and_without_system_packages( | ||
self, mock_check_output, mock_runner | ||
): | ||
hook = BeamHook(runner=DEFAULT_RUNNER) | ||
wait_for_done = mock_runner.return_value.wait_for_done | ||
process_line_callback = MagicMock() | ||
|