You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by vi...@apache.org on 2023/09/11 22:19:00 UTC
[airflow] branch main updated: Refactor unneeded 'continue' jumps in tests (#33841)
This is an automated email from the ASF dual-hosted git repository.
vincbeck 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 e10bf9ec3b Refactor unneeded 'continue' jumps in tests (#33841)
e10bf9ec3b is described below
commit e10bf9ec3b6ee92cc41ed6210f6fa8d7d9c04c0b
Author: Miroslav Šedivý <67...@users.noreply.github.com>
AuthorDate: Mon Sep 11 22:18:50 2023 +0000
Refactor unneeded 'continue' jumps in tests (#33841)
---
tests/always/test_project_structure.py | 10 +++----
tests/jobs/test_scheduler_job.py | 5 ++--
tests/plugins/test_plugins_manager.py | 7 ++---
tests/serialization/test_serialized_objects.py | 34 ++++++++++------------
tests/system/conftest.py | 7 ++---
.../cloud/gcs/resources/transform_timespan.py | 12 +++-----
6 files changed, 31 insertions(+), 44 deletions(-)
diff --git a/tests/always/test_project_structure.py b/tests/always/test_project_structure.py
index a518c9f3d2..3b5a57eda7 100644
--- a/tests/always/test_project_structure.py
+++ b/tests/always/test_project_structure.py
@@ -147,12 +147,10 @@ class ProjectStructureTest:
module = filepath_to_module(filepath)
results: dict = {}
for current_node in ast.walk(doc_node):
- if not isinstance(current_node, ast.ClassDef):
- continue
- name = current_node.name
- if not name.endswith(tuple(self.CLASS_SUFFIXES)):
- continue
- results[f"{module}.{name}"] = current_node
+ if isinstance(current_node, ast.ClassDef) and current_node.name.endswith(
+ tuple(self.CLASS_SUFFIXES)
+ ):
+ results[f"{module}.{current_node.name}"] = current_node
return results
diff --git a/tests/jobs/test_scheduler_job.py b/tests/jobs/test_scheduler_job.py
index 4fdb006a38..5e602c8f10 100644
--- a/tests/jobs/test_scheduler_job.py
+++ b/tests/jobs/test_scheduler_job.py
@@ -2271,9 +2271,8 @@ class TestSchedulerJob:
ex_date = dr.execution_date
for tid, state in expected_task_states.items():
- if state != State.FAILED:
- continue
- self.null_exec.mock_task_fail(dag_id, tid, dr.run_id)
+ if state == State.FAILED:
+ self.null_exec.mock_task_fail(dag_id, tid, dr.run_id)
try:
dag = DagBag().get_dag(dag.dag_id)
diff --git a/tests/plugins/test_plugins_manager.py b/tests/plugins/test_plugins_manager.py
index 24faaeed34..adc1507079 100644
--- a/tests/plugins/test_plugins_manager.py
+++ b/tests/plugins/test_plugins_manager.py
@@ -206,10 +206,9 @@ class TestPluginsManager:
assert 6 == len(plugins_manager.plugins)
for plugin in plugins_manager.plugins:
- if "AirflowTestOnLoadPlugin" not in str(plugin):
- continue
- assert "postload" == plugin.name
- break
+ if "AirflowTestOnLoadPlugin" in str(plugin):
+ assert "postload" == plugin.name
+ break
else:
pytest.fail("Wasn't able to find a registered `AirflowTestOnLoadPlugin`")
diff --git a/tests/serialization/test_serialized_objects.py b/tests/serialization/test_serialized_objects.py
index 9ac033672e..6f0a6f8775 100644
--- a/tests/serialization/test_serialized_objects.py
+++ b/tests/serialization/test_serialized_objects.py
@@ -42,32 +42,28 @@ def test_recursive_serialize_calls_must_forward_kwargs():
class_def = None
for stmt in ast.walk(tree):
- if not isinstance(stmt, ast.ClassDef):
- continue
- if stmt.name == "BaseSerialization":
+ if isinstance(stmt, ast.ClassDef) and stmt.name == "BaseSerialization":
class_def = stmt
method_def = None
for elem in ast.walk(class_def):
- if isinstance(elem, ast.FunctionDef):
- if elem.name == "serialize":
- method_def = elem
- break
+ if isinstance(elem, ast.FunctionDef) and elem.name == "serialize":
+ method_def = elem
+ break
kwonly_args = [x.arg for x in method_def.args.kwonlyargs]
for elem in ast.walk(method_def):
- if isinstance(elem, ast.Call):
- if getattr(elem.func, "attr", "") == "serialize":
- kwargs = {y.arg: y.value for y in elem.keywords}
- for name in kwonly_args:
- if name not in kwargs or getattr(kwargs[name], "id", "") != name:
- ref = f"{file}:{elem.lineno}"
- message = (
- f"Error at {ref}; recursive calls to `cls.serialize` "
- f"must forward the `{name}` argument"
- )
- raise Exception(message)
- valid_recursive_call_count += 1
+ if isinstance(elem, ast.Call) and getattr(elem.func, "attr", "") == "serialize":
+ kwargs = {y.arg: y.value for y in elem.keywords}
+ for name in kwonly_args:
+ if name not in kwargs or getattr(kwargs[name], "id", "") != name:
+ ref = f"{file}:{elem.lineno}"
+ message = (
+ f"Error at {ref}; recursive calls to `cls.serialize` "
+ f"must forward the `{name}` argument"
+ )
+ raise Exception(message)
+ valid_recursive_call_count += 1
print(f"validated calls: {valid_recursive_call_count}")
assert valid_recursive_call_count > 0
diff --git a/tests/system/conftest.py b/tests/system/conftest.py
index 58eca1287c..05d985af5e 100644
--- a/tests/system/conftest.py
+++ b/tests/system/conftest.py
@@ -53,7 +53,6 @@ def pytest_collection_modifyitems(config, items):
for item in items:
rel_path = Path(item.fspath).relative_to(rootdir)
match = re.match(".+/system/providers/([^/]+)", str(rel_path))
- if not match:
- continue
- provider = match.group(1)
- item.add_marker(pytest.mark.system(provider))
+ if match:
+ provider = match.group(1)
+ item.add_marker(pytest.mark.system(provider))
diff --git a/tests/system/providers/google/cloud/gcs/resources/transform_timespan.py b/tests/system/providers/google/cloud/gcs/resources/transform_timespan.py
index 12f8c81bee..9a871fb1c8 100644
--- a/tests/system/providers/google/cloud/gcs/resources/transform_timespan.py
+++ b/tests/system/providers/google/cloud/gcs/resources/transform_timespan.py
@@ -28,11 +28,7 @@ print(sys.argv)
print(f"Running script, called with source: {source}, destination: {destination}")
print(f"timespan_start: {timespan_start}, timespan_end: {timespan_end}")
-with open(Path(destination) / "output.txt", "w+") as dest:
- for f in Path(source).glob("**/*"):
- if f.is_dir():
- continue
- with open(f) as src:
- lines = [line.upper() for line in src.readlines()]
- print(lines)
- dest.writelines(lines)
+path = next(path for path in Path(source).rglob("*") if path.is_file())
+content = path.read_text().upper()
+print(content)
+Path(destination, "output.txt").write_text(content)