ephraimbuddy commented on code in PR #29265:
URL: https://github.com/apache/airflow/pull/29265#discussion_r1092031302


##########
tests/triggers/test_file.py:
##########
@@ -0,0 +1,64 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+import asyncio
+
+import pytest
+
+from airflow.triggers.file import FileTrigger
+
+
+class TestFileTrigger:
+    FILE_PATH = "/files/dags/example_async_file.py"
+
+    def test_serialization(self):
+        """Asserts that the trigger correctly serializes its arguments and 
classpath."""
+        trigger = FileTrigger(filepath=self.FILE_PATH, poll_interval=5)
+        classpath, kwargs = trigger.serialize()
+        assert classpath == "airflow.triggers.file.FileTrigger"
+        assert kwargs == {
+            "filepath": self.FILE_PATH,
+            "poll_interval": 5,
+            "recursive": False,
+        }
+
+    @pytest.mark.asyncio
+    async def test_task_file_trigger(self, tmp_path):

Review Comment:
   Should we test the implementation of the run function? Looks like we only 
tested the behaviour



##########
airflow/triggers/file.py:
##########
@@ -0,0 +1,73 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+import asyncio
+import datetime
+import os
+import typing
+from glob import glob
+from typing import Any
+
+from airflow.triggers.base import BaseTrigger, TriggerEvent
+
+
+class FileTrigger(BaseTrigger):
+    """
+    A trigger that fires exactly once after it finds the requested file or 
folder.
+
+    :param filepath: File or folder name (relative to the base path set within 
the connection), can
+        be a glob.
+    :param recursive: when set to ``True``, enables recursive directory 
matching behavior of
+        ``**`` in glob filepath parameter. Defaults to ``False``.
+    """
+
+    def __init__(
+        self,
+        filepath: str,
+        recursive: bool = False,
+        poll_interval: float = 5.0,
+    ):
+        super().__init__()
+        self.filepath = filepath
+        self.recursive = recursive
+        self.poll_interval = poll_interval
+
+    def serialize(self) -> tuple[str, dict[str, Any]]:
+        """Serializes FileTrigger arguments and classpath."""
+        return (
+            "airflow.triggers.file.FileTrigger",
+            {
+                "filepath": self.filepath,
+                "recursive": self.recursive,
+                "poll_interval": self.poll_interval,
+            },
+        )
+
+    async def run(self) -> typing.AsyncIterator["TriggerEvent"]:
+        """Simple loop until the relevant files are found."""

Review Comment:
   ```suggestion
           """Loop until the relevant files are found."""
   ```



-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to