This is an automated email from the ASF dual-hosted git repository.
husseinawala pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 0bb8e8a994 Replace format() by f-string in tests (#33859)
0bb8e8a994 is described below
commit 0bb8e8a994e03839a21e2bad57f7c739241e9941
Author: Hussein Awala <[email protected]>
AuthorDate: Thu Aug 31 09:11:13 2023 +0200
Replace format() by f-string in tests (#33859)
---
tests/dags/test_default_impersonation.py | 10 ++++------
tests/dags/test_impersonation.py | 10 ++++------
tests/operators/test_trigger_dagrun.py | 6 +++---
tests/providers/apache/hive/hooks/test_hive.py | 6 +++---
tests/providers/google/cloud/hooks/test_gcs.py | 5 +----
tests/providers/telegram/hooks/test_telegram.py | 2 +-
tests/system/providers/plexus/example_plexus.py | 2 +-
7 files changed, 17 insertions(+), 24 deletions(-)
diff --git a/tests/dags/test_default_impersonation.py
b/tests/dags/test_default_impersonation.py
index c2d2dfdb09..7ae7dadef5 100644
--- a/tests/dags/test_default_impersonation.py
+++ b/tests/dags/test_default_impersonation.py
@@ -35,14 +35,12 @@ dag = DAG(dag_id="test_default_impersonation",
default_args=args)
deelevated_user = "airflow_test_user"
test_command = dedent(
- """\
- if [ '{user}' != "$(whoami)" ]; then
- echo current user $(whoami) is not {user}!
+ f"""\
+ if [ '{deelevated_user}' != "$(whoami)" ]; then
+ echo current user $(whoami) is not {deelevated_user}!
exit 1
fi
- """.format(
- user=deelevated_user
- )
+ """
)
task = BashOperator(
diff --git a/tests/dags/test_impersonation.py b/tests/dags/test_impersonation.py
index 60538e8498..0c54a3cfbe 100644
--- a/tests/dags/test_impersonation.py
+++ b/tests/dags/test_impersonation.py
@@ -35,14 +35,12 @@ dag = DAG(dag_id="test_impersonation", default_args=args)
run_as_user = "airflow_test_user"
test_command = dedent(
- """\
- if [ '{user}' != "$(whoami)" ]; then
- echo current user is not {user}!
+ f"""\
+ if [ '{run_as_user}' != "$(whoami)" ]; then
+ echo current user is not {run_as_user}!
exit 1
fi
- """.format(
- user=run_as_user
- )
+ """
)
task = BashOperator(
diff --git a/tests/operators/test_trigger_dagrun.py
b/tests/operators/test_trigger_dagrun.py
index 3d24315dbc..c57779243c 100644
--- a/tests/operators/test_trigger_dagrun.py
+++ b/tests/operators/test_trigger_dagrun.py
@@ -42,12 +42,12 @@ DAG_SCRIPT = (
"from airflow.models import DAG\n"
"from airflow.operators.empty import EmptyOperator\n\n"
"dag = DAG(\n"
- 'dag_id="{dag_id}", \n'
- 'default_args={{"start_date": datetime(2019, 1, 1)}}, \n'
+ f"dag_id='{TRIGGERED_DAG_ID}', \n"
+ "default_args={'start_date': datetime(2019, 1, 1)}, \n"
"schedule=None,\n"
")\n"
'task = EmptyOperator(task_id="test", dag=dag)'
-).format(dag_id=TRIGGERED_DAG_ID)
+)
class TestDagRunOperator:
diff --git a/tests/providers/apache/hive/hooks/test_hive.py
b/tests/providers/apache/hive/hooks/test_hive.py
index 69f8c395b4..8aa48aeaea 100644
--- a/tests/providers/apache/hive/hooks/test_hive.py
+++ b/tests/providers/apache/hive/hooks/test_hive.py
@@ -249,11 +249,11 @@ class TestHiveCliHook:
hook.load_file(filepath=filepath, table=table, field_dict=field_dict,
create=True, recreate=True)
create_table = (
- "DROP TABLE IF EXISTS {table};\n"
- "CREATE TABLE IF NOT EXISTS {table} (\n{fields})\n"
+ f"DROP TABLE IF EXISTS {table};\n"
+ f"CREATE TABLE IF NOT EXISTS {table} (\n{fields})\n"
"ROW FORMAT DELIMITED\n"
"FIELDS TERMINATED BY ','\n"
- "STORED AS textfile\n;".format(table=table, fields=fields)
+ "STORED AS textfile\n;"
)
load_data = f"LOAD DATA LOCAL INPATH '{filepath}' OVERWRITE INTO TABLE
{table} ;\n"
diff --git a/tests/providers/google/cloud/hooks/test_gcs.py
b/tests/providers/google/cloud/hooks/test_gcs.py
index 4f1839fc42..b38517e6b7 100644
--- a/tests/providers/google/cloud/hooks/test_gcs.py
+++ b/tests/providers/google/cloud/hooks/test_gcs.py
@@ -370,10 +370,7 @@ class TestGCSHook:
assert str(ctx.value) == (
"Either source/destination bucket or source/destination object
must be different, "
- "not both the same: bucket={}, object={}"
- ).format(
- source_bucket,
- source_object,
+ f"not both the same: bucket={source_bucket},
object={source_object}"
)
def test_copy_empty_source_bucket(self):
diff --git a/tests/providers/telegram/hooks/test_telegram.py
b/tests/providers/telegram/hooks/test_telegram.py
index 44e5bdb152..6aa83df5da 100644
--- a/tests/providers/telegram/hooks/test_telegram.py
+++ b/tests/providers/telegram/hooks/test_telegram.py
@@ -32,7 +32,7 @@ TELEGRAM_TOKEN = "dummy token"
class AsyncMock(mock.MagicMock):
async def __call__(self, *args, **kwargs):
- return super(AsyncMock, self).__call__(*args, **kwargs)
+ return super().__call__(*args, **kwargs)
class TestTelegramHook:
diff --git a/tests/system/providers/plexus/example_plexus.py
b/tests/system/providers/plexus/example_plexus.py
index 01bf19fc31..ad957133b0 100644
--- a/tests/system/providers/plexus/example_plexus.py
+++ b/tests/system/providers/plexus/example_plexus.py
@@ -23,7 +23,7 @@ from airflow import DAG
from airflow.providers.plexus.operators.job import PlexusJobOperator
HOME = "/home/acc"
-T3_PRERUN_SCRIPT = "cp {home}/imdb/run_scripts/mlflow.sh {home}/ && chmod +x
mlflow.sh".format(home=HOME)
+T3_PRERUN_SCRIPT = f"cp {HOME}/imdb/run_scripts/mlflow.sh {HOME}/ && chmod +x
mlflow.sh"
ENV_ID = os.environ.get("SYSTEM_TESTS_ENV_ID")
DAG_ID = "test"