From 5e38319f750f8443e29609a68ffbddaccdc3765c Mon Sep 17 00:00:00 2001 From: Jarek Potiuk Date: Thu, 28 Nov 2024 19:17:11 +0000 Subject: [PATCH] Fix issues reported by ruff team before new ruff rules are out (#44460) Ruff team is using Airflow as one of the "ecosystem" benchmarks for new rules they developed and reported the issues to us in the #44455 discussion. This PR addresses those issues that are still there (some of the reported tests were removed earlier today when we removed AIP-44 code in #44454 --- providers/tests/amazon/aws/hooks/test_base_aws.py | 2 +- providers/tests/google/cloud/sensors/test_gcs.py | 4 ++-- providers/tests/google/common/hooks/test_base_google.py | 2 +- .../endpoints/test_task_instance_endpoint.py | 4 ++-- .../core_api/routes/public/test_task_instances.py | 8 ++++---- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/providers/tests/amazon/aws/hooks/test_base_aws.py b/providers/tests/amazon/aws/hooks/test_base_aws.py index f0b579d10c0a3..86487ece6f88c 100644 --- a/providers/tests/amazon/aws/hooks/test_base_aws.py +++ b/providers/tests/amazon/aws/hooks/test_base_aws.py @@ -1074,7 +1074,7 @@ def _non_retryable_test(thing): class TestRetryDecorator: # ptlint: disable=invalid-name def test_do_nothing_on_non_exception(self): result = _retryable_test(lambda: 42) - assert result, 42 + assert result == 42 @mock.patch("time.sleep", return_value=0) def test_retry_on_exception(self, _): diff --git a/providers/tests/google/cloud/sensors/test_gcs.py b/providers/tests/google/cloud/sensors/test_gcs.py index bcec4f6220a82..c242856d603d7 100644 --- a/providers/tests/google/cloud/sensors/test_gcs.py +++ b/providers/tests/google/cloud/sensors/test_gcs.py @@ -83,7 +83,7 @@ def test_gcs_object_existence_sensor_return_value(self, mock_defer, mock_hook): ) mock_hook.return_value.list.return_value = True return_value = task.execute(mock.MagicMock()) - assert return_value, True + assert return_value @mock.patch("airflow.providers.google.cloud.sensors.gcs.GCSHook") def test_should_pass_argument_to_hook(self, mock_hook): @@ -198,7 +198,7 @@ def test_gcs_object_existence_sensor_execute_complete_return_value(self): context=None, event={"status": "success", "message": "Job completed"} ) mock_log_info.assert_called_with("File %s was found in bucket %s.", TEST_OBJECT, TEST_BUCKET) - assert return_value, True + assert return_value class TestGoogleCloudStorageObjectUpdatedSensor: diff --git a/providers/tests/google/common/hooks/test_base_google.py b/providers/tests/google/common/hooks/test_base_google.py index 20ec029a94758..d3ce25fd0ed77 100644 --- a/providers/tests/google/common/hooks/test_base_google.py +++ b/providers/tests/google/common/hooks/test_base_google.py @@ -81,7 +81,7 @@ def _retryable_test_with_temporary_quota_retry(thing): class TestQuotaRetry: def test_do_nothing_on_non_error(self): result = _retryable_test_with_temporary_quota_retry(lambda: 42) - assert result, 42 + assert result == 42 def test_retry_on_exception(self): message = "POST https://translation.googleapis.com/language/translate/v2: User Rate Limit Exceeded" diff --git a/tests/api_connexion/endpoints/test_task_instance_endpoint.py b/tests/api_connexion/endpoints/test_task_instance_endpoint.py index 76b1164591c86..18108edfe284f 100644 --- a/tests/api_connexion/endpoints/test_task_instance_endpoint.py +++ b/tests/api_connexion/endpoints/test_task_instance_endpoint.py @@ -1366,8 +1366,8 @@ def test_should_respond_200_with_reset_dag_run(self, session): ] for task_instance in expected_response: assert task_instance in response.json["task_instances"] - assert 6 == len(response.json["task_instances"]) - assert 0 == failed_dag_runs, 0 + assert len(response.json["task_instances"]) == 6 + assert failed_dag_runs == 0 _check_last_log(session, dag_id=dag_id, event="api.post_clear_task_instances", logical_date=None) def test_should_respond_200_with_dag_run_id(self, session): diff --git a/tests/api_fastapi/core_api/routes/public/test_task_instances.py b/tests/api_fastapi/core_api/routes/public/test_task_instances.py index 899af4640ea9d..3f008c44911cc 100644 --- a/tests/api_fastapi/core_api/routes/public/test_task_instances.py +++ b/tests/api_fastapi/core_api/routes/public/test_task_instances.py @@ -1955,8 +1955,8 @@ def test_should_respond_200_with_reset_dag_run(self, test_client, session): ] for task_instance in expected_response: assert task_instance in response.json()["task_instances"] - assert 6 == response.json()["total_entries"] - assert 0 == failed_dag_runs, 0 + assert response.json()["total_entries"] == 6 + assert failed_dag_runs == 0 def test_should_respond_200_with_dag_run_id(self, test_client, session): dag_id = "example_python_operator" @@ -2012,7 +2012,7 @@ def test_should_respond_200_with_dag_run_id(self, test_client, session): }, ] assert response.json()["task_instances"] == expected_response - assert 1 == response.json()["total_entries"] + assert response.json()["total_entries"] == 1 def test_should_respond_200_with_include_past(self, test_client, session): dag_id = "example_python_operator" @@ -2177,7 +2177,7 @@ def test_should_respond_200_with_include_future(self, test_client, session): ] for task_instance in expected_response: assert task_instance in response.json()["task_instances"] - assert 6 == response.json()["total_entries"] + assert response.json()["total_entries"] == 6 def test_should_respond_404_for_nonexistent_dagrun_id(self, test_client, session): dag_id = "example_python_operator"