Skip to content

Commit

Permalink
[AIRFLOW-6391] Move content of utils.tests to tests.test_utils (#6949)
Browse files Browse the repository at this point in the history
  • Loading branch information
turbaszek authored and potiuk committed Dec 29, 2019
1 parent 62f6070 commit de5b43a
Show file tree
Hide file tree
Showing 11 changed files with 174 additions and 194 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ repos:
files: \.py$
- id: base-operator
language: pygrep
name: Make sure BaseOperator is imported from airflow.models.baseoperator in core
name: Make sure BaseOperator[Link] is imported from airflow.models.baseoperator in core
entry: "from airflow\\.models import.* BaseOperator"
files: \.py$
pass_filenames: true
Expand All @@ -233,7 +233,7 @@ repos:
pass_filenames: true
- id: base-operator
language: pygrep
name: Make sure BaseOperator is imported from airflow.models outside of core
name: Make sure BaseOperator[Link] is imported from airflow.models outside of core
entry: "from airflow\\.models\\.baseoperator import.* BaseOperator"
pass_filenames: true
files: >
Expand Down
173 changes: 0 additions & 173 deletions airflow/utils/tests.py

This file was deleted.

4 changes: 2 additions & 2 deletions tests/hooks/test_hive_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from airflow.operators.hive_operator import HiveOperator
from airflow.utils import timezone
from airflow.utils.operator_helpers import AIRFLOW_VAR_NAME_FORMAT_MAPPING
from airflow.utils.tests import assertEqualIgnoreMultipleSpaces
from tests.test_utils.asserts import assert_equal_ignore_multiple_spaces

DEFAULT_DATE = timezone.datetime(2015, 1, 1)
DEFAULT_DATE_ISO = DEFAULT_DATE.isoformat()
Expand Down Expand Up @@ -247,7 +247,7 @@ def test_load_df_with_data_types(self, mock_run_cli):
STORED AS textfile
;
"""
assertEqualIgnoreMultipleSpaces(self, mock_run_cli.call_args_list[0][0][0], query)
assert_equal_ignore_multiple_spaces(self, mock_run_cli.call_args_list[0][0][0], query)


class TestHiveMetastoreHook(TestHiveEnvironment):
Expand Down
4 changes: 2 additions & 2 deletions tests/operators/test_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ def test_mysql_hook_test_bulk_dump_mock(self, mock_get_conn):
tmp_file = "/path/to/output/file"
hook.bulk_dump(table, tmp_file)

from airflow.utils.tests import assertEqualIgnoreMultipleSpaces
from tests.test_utils.asserts import assert_equal_ignore_multiple_spaces
assert mock_execute.call_count == 1
query = """
SELECT * INTO OUTFILE '{tmp_file}'
FROM {table}
""".format(tmp_file=tmp_file, table=table)
assertEqualIgnoreMultipleSpaces(self, mock_execute.call_args[0][0], query)
assert_equal_ignore_multiple_spaces(self, mock_execute.call_args[0][0], query)

@unittest.skipUnless('mysql' in conf.get('core', 'sql_alchemy_conn'),
"This is a MySQL test")
Expand Down
4 changes: 2 additions & 2 deletions tests/operators/test_redshift_to_s3_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from parameterized import parameterized

from airflow.operators.redshift_to_s3_operator import RedshiftToS3Transfer
from airflow.utils.tests import assertEqualIgnoreMultipleSpaces
from tests.test_utils.asserts import assert_equal_ignore_multiple_spaces


class TestRedshiftToS3Transfer(unittest.TestCase):
Expand Down Expand Up @@ -76,4 +76,4 @@ def test_execute(self, table_as_file_name, expected_s3_key, mock_run, mock_sessi
unload_options=unload_options)

assert mock_run.call_count == 1
assertEqualIgnoreMultipleSpaces(self, mock_run.call_args[0][0], unload_query)
assert_equal_ignore_multiple_spaces(self, mock_run.call_args[0][0], unload_query)
4 changes: 2 additions & 2 deletions tests/operators/test_s3_to_redshift_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from boto3.session import Session

from airflow.operators.s3_to_redshift_operator import S3ToRedshiftTransfer
from airflow.utils.tests import assertEqualIgnoreMultipleSpaces
from tests.test_utils.asserts import assert_equal_ignore_multiple_spaces


class TestS3ToRedshiftTransfer(unittest.TestCase):
Expand Down Expand Up @@ -69,4 +69,4 @@ def test_execute(self, mock_run, mock_session):
copy_options=copy_options)

assert mock_run.call_count == 1
assertEqualIgnoreMultipleSpaces(self, mock_run.call_args[0][0], copy_query)
assert_equal_ignore_multiple_spaces(self, mock_run.call_args[0][0], copy_query)
2 changes: 1 addition & 1 deletion tests/plugins/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# This is the class you derive to create a plugin
from airflow.plugins_manager import AirflowPlugin
from airflow.sensors.base_sensor_operator import BaseSensorOperator
from airflow.utils.tests import (
from tests.test_utils.mock_operators import (
AirflowLink, AirflowLink2, CustomBaseIndexOpLink, CustomOpLink, GithubLink, GoogleLink,
)

Expand Down
12 changes: 6 additions & 6 deletions tests/serialization/test_dag_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from airflow.operators.bash_operator import BashOperator
from airflow.operators.subdag_operator import SubDagOperator
from airflow.serialization.serialized_objects import SerializedBaseOperator, SerializedDAG
from airflow.utils.tests import CustomOperator, CustomOpLink, GoogleLink
from tests.test_utils.mock_operators import CustomOperator, CustomOpLink, GoogleLink

serialized_simple_dag_ground_truth = {
"__version": 1,
Expand Down Expand Up @@ -78,12 +78,12 @@
"_downstream_task_ids": [],
"_inlets": [],
"_outlets": [],
"_operator_extra_links": [{"airflow.utils.tests.CustomOpLink": {}}],
"_operator_extra_links": [{"tests.test_utils.mock_operators.CustomOpLink": {}}],
"ui_color": "#fff",
"ui_fgcolor": "#000",
"template_fields": [],
"_task_type": "CustomOperator",
"_task_module": "airflow.utils.tests",
"_task_module": "tests.test_utils.mock_operators",
},
],
"timezone": "UTC",
Expand Down Expand Up @@ -391,7 +391,7 @@ def test_extra_serialized_field_and_operator_links(self):
# Check Serialized version of operator link only contains the inbuilt Op Link
self.assertEqual(
serialized_dag["dag"]["tasks"][0]["_operator_extra_links"],
[{'airflow.utils.tests.CustomOpLink': {}}]
[{'tests.test_utils.mock_operators.CustomOpLink': {}}]
)

# Test all the extra_links are set
Expand Down Expand Up @@ -438,8 +438,8 @@ def test_extra_serialized_field_and_multiple_operator_links(self):
self.assertEqual(
serialized_dag["dag"]["tasks"][0]["_operator_extra_links"],
[
{'airflow.utils.tests.CustomBaseIndexOpLink': {'index': 0}},
{'airflow.utils.tests.CustomBaseIndexOpLink': {'index': 1}},
{'tests.test_utils.mock_operators.CustomBaseIndexOpLink': {'index': 0}},
{'tests.test_utils.mock_operators.CustomBaseIndexOpLink': {'index': 1}},
]
)

Expand Down
24 changes: 24 additions & 0 deletions tests/test_utils/asserts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.

import re


def assert_equal_ignore_multiple_spaces(case, first, second, msg=None):
def _trim(s):
return re.sub(r"\s+", " ", s.strip())
return case.assertEqual(_trim(first), _trim(second), msg)
Loading

0 comments on commit de5b43a

Please sign in to comment.