From e61cf07144f839705583652266e028234dd529c5 Mon Sep 17 00:00:00 2001 From: Jarek Potiuk Date: Wed, 3 Mar 2021 06:06:41 +0100 Subject: [PATCH] fixup! Switch to f-strings using flynt. (#13732) --- .../snowflake/transfers/s3_to_snowflake.py | 18 +++++++----------- .../google/cloud/operators/test_pubsub.py | 2 +- .../google/cloud/sensors/test_pubsub.py | 2 +- .../transfers/test_s3_to_snowflake.py | 18 ++++++------------ 4 files changed, 15 insertions(+), 25 deletions(-) diff --git a/airflow/providers/snowflake/transfers/s3_to_snowflake.py b/airflow/providers/snowflake/transfers/s3_to_snowflake.py index 22387180dcd13..27f8810337ad4 100644 --- a/airflow/providers/snowflake/transfers/s3_to_snowflake.py +++ b/airflow/providers/snowflake/transfers/s3_to_snowflake.py @@ -82,13 +82,11 @@ def execute(self, context: Any) -> None: files = files.replace(']', ')') # we can extend this based on stage - base_sql = """ - FROM @{stage}/ + base_sql = f""" + FROM @{self.stage}/ files={files} - file_format={file_format} - """.format( - stage=self.stage, files=files, file_format=self.file_format - ) + file_format={self.file_format} + """ if self.columns_array: copy_query = """ @@ -97,11 +95,9 @@ def execute(self, context: Any) -> None: schema=self.schema, table=self.table, columns=",".join(self.columns_array), base_sql=base_sql ) else: - copy_query = """ - COPY INTO {schema}.{table} {base_sql} - """.format( - schema=self.schema, table=self.table, base_sql=base_sql - ) + copy_query = f""" + COPY INTO {self.schema}.{self.table} {base_sql} + """ self.log.info('Executing COPY command...') snowflake_hook.run(copy_query, self.autocommit) diff --git a/tests/providers/google/cloud/operators/test_pubsub.py b/tests/providers/google/cloud/operators/test_pubsub.py index 6abfffa0e0c84..02f356dcad519 100644 --- a/tests/providers/google/cloud/operators/test_pubsub.py +++ b/tests/providers/google/cloud/operators/test_pubsub.py @@ -230,7 +230,7 @@ class TestPubSubPullOperator(unittest.TestCase): def _generate_messages(self, count): return [ ReceivedMessage( - ack_id="%s" % i, + ack_id=f"{i}", message={ "data": f'Message {i}'.encode('utf8'), "attributes": {"type": "generated message"}, diff --git a/tests/providers/google/cloud/sensors/test_pubsub.py b/tests/providers/google/cloud/sensors/test_pubsub.py index 795860b3d353c..6a502aaeabed4 100644 --- a/tests/providers/google/cloud/sensors/test_pubsub.py +++ b/tests/providers/google/cloud/sensors/test_pubsub.py @@ -35,7 +35,7 @@ class TestPubSubPullSensor(unittest.TestCase): def _generate_messages(self, count): return [ ReceivedMessage( - ack_id="%s" % i, + ack_id=f"{i}", message={ "data": f'Message {i}'.encode('utf8'), "attributes": {"type": "generated message"}, diff --git a/tests/providers/snowflake/transfers/test_s3_to_snowflake.py b/tests/providers/snowflake/transfers/test_s3_to_snowflake.py index 02e6e5a205bd9..f965acfeecc59 100644 --- a/tests/providers/snowflake/transfers/test_s3_to_snowflake.py +++ b/tests/providers/snowflake/transfers/test_s3_to_snowflake.py @@ -46,19 +46,15 @@ def test_execute(self, mock_run): files = str(s3_keys) files = files.replace('[', '(') files = files.replace(']', ')') - base_sql = """ + base_sql = f""" FROM @{stage}/ files={files} file_format={file_format} - """.format( - stage=stage, files=files, file_format=file_format - ) + """ - copy_query = """ + copy_query = f""" COPY INTO {schema}.{table} {base_sql} - """.format( - schema=schema, table=table, base_sql=base_sql - ) + """ assert mock_run.call_count == 1 assert_equal_ignore_multiple_spaces(self, mock_run.call_args[0][0], copy_query) @@ -86,13 +82,11 @@ def test_execute_with_columns(self, mock_run): files = str(s3_keys) files = files.replace('[', '(') files = files.replace(']', ')') - base_sql = """ + base_sql = f""" FROM @{stage}/ files={files} file_format={file_format} - """.format( - stage=stage, files=files, file_format=file_format - ) + """ copy_query = """ COPY INTO {schema}.{table}({columns}) {base_sql}