This is an automated email from the ASF dual-hosted git repository.
potiuk 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 3acf78ef0b Refactor: Replace lambdas with comprehensions in tests
(#33772)
3acf78ef0b is described below
commit 3acf78ef0b12ce2843e8cfa532700d09c6140fde
Author: Miroslav Šedivý <[email protected]>
AuthorDate: Tue Aug 29 07:56:01 2023 +0000
Refactor: Replace lambdas with comprehensions in tests (#33772)
---
tests/jobs/test_scheduler_job.py | 4 ++--
tests/models/test_dagbag.py | 4 ++--
tests/models/test_dagrun.py | 2 +-
tests/system/providers/amazon/aws/example_emr_eks.py | 11 +++++------
tests/utils/test_file.py | 2 +-
tests/utils/test_process_utils.py | 4 ++--
tests/www/test_utils.py | 3 +--
7 files changed, 14 insertions(+), 16 deletions(-)
diff --git a/tests/jobs/test_scheduler_job.py b/tests/jobs/test_scheduler_job.py
index 406257828d..081fbfe85d 100644
--- a/tests/jobs/test_scheduler_job.py
+++ b/tests/jobs/test_scheduler_job.py
@@ -576,7 +576,7 @@ class TestSchedulerJob:
res = self.job_runner._executable_task_instances_to_queued(max_tis=32,
session=session)
assert 1 == len(res)
- res_keys = map(lambda x: x.key, res)
+ res_keys = (x.key for x in res)
assert ti_with_dagrun.key in res_keys
session.rollback()
@@ -1017,7 +1017,7 @@ class TestSchedulerJob:
res = self.job_runner._executable_task_instances_to_queued(max_tis=32,
session=session)
assert 1 == len(res)
- res_keys = map(lambda x: x.key, res)
+ res_keys = (x.key for x in res)
assert ti2.key in res_keys
ti2.state = State.RUNNING
diff --git a/tests/models/test_dagbag.py b/tests/models/test_dagbag.py
index b9e5b5f2f1..e0a999b9d8 100644
--- a/tests/models/test_dagbag.py
+++ b/tests/models/test_dagbag.py
@@ -474,10 +474,10 @@ class TestDagBag:
return dagbag, found_dags, os.fspath(path)
def validate_dags(self, expected_parent_dag, actual_found_dags,
actual_dagbag, should_be_found=True):
- expected_dag_ids = list(map(lambda dag: dag.dag_id,
expected_parent_dag.subdags))
+ expected_dag_ids = [dag.dag_id for dag in expected_parent_dag.subdags]
expected_dag_ids.append(expected_parent_dag.dag_id)
- actual_found_dag_ids = list(map(lambda dag: dag.dag_id,
actual_found_dags))
+ actual_found_dag_ids = [dag.dag_id for dag in actual_found_dags]
for dag_id in expected_dag_ids:
actual_dagbag.log.info("validating %s", dag_id)
diff --git a/tests/models/test_dagrun.py b/tests/models/test_dagrun.py
index e789a2ef2b..62affe2485 100644
--- a/tests/models/test_dagrun.py
+++ b/tests/models/test_dagrun.py
@@ -1894,7 +1894,7 @@ def test_mapped_task_upstream_failed(dag_maker, session,
trigger_rule):
@dag.task
def make_list():
- return list(map(lambda a: f'echo "{a!r}"', [1, 2, {"a": "b"}]))
+ return [f'echo "{a!r}"' for a in [1, 2, {"a": "b"}]]
def consumer(*args):
print(repr(args))
diff --git a/tests/system/providers/amazon/aws/example_emr_eks.py
b/tests/system/providers/amazon/aws/example_emr_eks.py
index 53c865a4a1..8c9e7c3357 100644
--- a/tests/system/providers/amazon/aws/example_emr_eks.py
+++ b/tests/system/providers/amazon/aws/example_emr_eks.py
@@ -150,12 +150,11 @@ def update_trust_policy_execution_role(cluster_name,
cluster_namespace, role_nam
role_trust_policy =
client.get_role(RoleName=role_name)["Role"]["AssumeRolePolicyDocument"]
# We assume if the action is sts:AssumeRoleWithWebIdentity, the statement
had been added with
# "update-role-trust-policy". Removing it to not exceed the quota
- role_trust_policy["Statement"] = list(
- filter(
- lambda statement: statement["Action"] !=
"sts:AssumeRoleWithWebIdentity",
- role_trust_policy["Statement"],
- )
- )
+ role_trust_policy["Statement"] = [
+ statement
+ for statement in role_trust_policy["Statement"]
+ if statement["Action"] != "sts:AssumeRoleWithWebIdentity"
+ ]
client.update_assume_role_policy(
RoleName=role_name,
diff --git a/tests/utils/test_file.py b/tests/utils/test_file.py
index 448ddf31c7..daa23fa64e 100644
--- a/tests/utils/test_file.py
+++ b/tests/utils/test_file.py
@@ -135,7 +135,7 @@ class TestListPyFilesPath:
assert files
assert all(os.path.basename(file) not in should_ignore for file in
files)
- assert len(list(filter(lambda file: os.path.basename(file) in
should_not_ignore, files))) == len(
+ assert sum(1 for file in files if os.path.basename(file) in
should_not_ignore) == len(
should_not_ignore
)
diff --git a/tests/utils/test_process_utils.py
b/tests/utils/test_process_utils.py
index 322f10eb66..d5fb76613b 100644
--- a/tests/utils/test_process_utils.py
+++ b/tests/utils/test_process_utils.py
@@ -158,7 +158,7 @@ class TestKillChildProcessesByPids:
sleep(0)
all_processes = subprocess.check_output(["ps", "-ax", "-o",
"pid="]).decode().splitlines()
- assert str(process.pid) in map(lambda x: x.strip(), all_processes)
+ assert str(process.pid) in (x.strip() for x in all_processes)
with caplog.at_level(logging.INFO, logger=process_utils.log.name):
caplog.clear()
@@ -166,7 +166,7 @@ class TestKillChildProcessesByPids:
assert f"Killing child PID: {process.pid}" in caplog.messages
sleep(0)
all_processes = subprocess.check_output(["ps", "-ax", "-o",
"pid="]).decode().splitlines()
- assert str(process.pid) not in map(lambda x: x.strip(), all_processes)
+ assert str(process.pid) not in (x.strip() for x in all_processes)
class TestPatchEnviron:
diff --git a/tests/www/test_utils.py b/tests/www/test_utils.py
index 46fa055e8c..97d80e8b27 100644
--- a/tests/www/test_utils.py
+++ b/tests/www/test_utils.py
@@ -104,8 +104,7 @@ class TestUtils:
if sorting_key and sorting_direction:
if pages[0] == 0:
- pages = pages[1:]
- pages = list(map(lambda x: str(x), pages))
+ pages = [str(page) for page in pages[1:]]
assert pages == all_nodes