potiuk commented on code in PR #70449:
URL: https://github.com/apache/airflow/pull/70449#discussion_r3681980390
##########
providers/google/tests/unit/google/cloud/transfers/test_gcs_to_gcs.py:
##########
@@ -1082,22 +1077,41 @@ def
test_execute_returns_list_of_destination_uris_single_file(self, mock_hook):
@mock.patch("airflow.providers.google.cloud.transfers.gcs_to_gcs.GCSHook")
def test_execute_returns_list_of_destination_uris_multiple_files(self,
mock_hook):
mock_hook.return_value.list.return_value = SOURCE_OBJECTS_LIST
+ operator = GCSToGCSOperator(
+ task_id=TASK_ID,
+ source_bucket=TEST_BUCKET,
+ source_object=SOURCE_OBJECT_WILDCARD_FILENAME,
+ destination_bucket=DESTINATION_BUCKET,
+ destination_object=DESTINATION_OBJECT_PREFIX,
+ )
with pytest.warns(AirflowProviderDeprecationWarning, match="Usage of
wildcard"):
- operator = GCSToGCSOperator(
- task_id=TASK_ID,
- source_bucket=TEST_BUCKET,
- source_object=SOURCE_OBJECT_WILDCARD_FILENAME,
- destination_bucket=DESTINATION_BUCKET,
- destination_object=DESTINATION_OBJECT_PREFIX,
- )
- result = operator.execute(None)
+ result = operator.execute(None)
expected = [
f"gs://{DESTINATION_BUCKET}/foo/bar/file1.txt",
f"gs://{DESTINATION_BUCKET}/foo/bar/file2.txt",
f"gs://{DESTINATION_BUCKET}/foo/bar/file3.json",
]
assert sorted(result) == sorted(expected)
+ @mock.patch("airflow.providers.google.cloud.transfers.gcs_to_gcs.GCSHook")
+ def test_wildcard_deprecation_warning_uses_rendered_source_object(self,
mock_hook):
+ mock_hook.return_value.list.return_value = SOURCE_OBJECTS_LIST
+ with DAG(dag_id="test_gcs_to_gcs_wildcard_templating",
start_date=datetime(2024, 1, 1)) as dag:
+ operator = GCSToGCSOperator(
+ task_id=TASK_ID,
+ source_bucket=TEST_BUCKET,
+ source_object="{{ params.source_object }}",
+ destination_bucket=DESTINATION_BUCKET,
+ destination_object=DESTINATION_OBJECT_PREFIX,
+ dag=dag,
+ )
+
+ operator.render_template_fields({"params": {"source_object":
SOURCE_OBJECT_WILDCARD_FILENAME}})
+ assert operator.source_object == SOURCE_OBJECT_WILDCARD_FILENAME
+
+ with pytest.warns(AirflowProviderDeprecationWarning, match="Usage of
wildcard"):
+ operator.execute(None)
Review Comment:
`execute(None)` works here because nothing reads the context before the
warnings fire, but `mock.MagicMock()` or `{}` is more robust — if the warning
block ever moves below something context-dependent, this fails with an
unrelated `AttributeError` rather than the assertion you meant.
Also, on line 25: `from airflow import DAG` in a provider test. Provider
tests run against multiple Airflow versions, where the usual import is via
`tests_common` compat (or `airflow.sdk` on 3.x). Worth checking this doesn't
trip the compat runs against older Airflow.
---
Drafted-by: Claude Code (Opus 5); reviewed by @potiuk before posting
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]