ashb commented on a change in pull request #5358: [AIRFLOW-4085] FileSensor - 
adding wildcard option
URL: https://github.com/apache/airflow/pull/5358#discussion_r317654351
 
 

 ##########
 File path: tests/contrib/sensors/test_file_sensor.py
 ##########
 @@ -134,6 +135,56 @@ def test_default_fs_conn_id(self):
             task.run(start_date=DEFAULT_DATE, end_date=DEFAULT_DATE,
                      ignore_ti_state=True)
 
+    def test_wildcard_file(self):
+        suffix = '.txt'
+        with tempfile.NamedTemporaryFile(suffix=suffix) as tmp:
+            fileglob = os.path.join(os.path.dirname(tmp.name), '*' + suffix)
+            task = FileSensor(
+                task_id='test',
+                filepath=fileglob,
+                fs_conn_id='fs_default',
+                dag=self.dag,
+                timeout=0,
+            )
+            task._hook = self.hook
+            task.run(start_date=DEFAULT_DATE, end_date=DEFAULT_DATE,
+                     ignore_ti_state=True)
+
+    def test_subdirectory_not_empty(self):
+        suffix = '.txt'
+        dir_ = tempfile.mkdtemp()
+        subdir = tempfile.mkdtemp(dir=dir_)
+
+        with tempfile.NamedTemporaryFile(suffix=suffix, dir=subdir):
+            task = FileSensor(
+                task_id='test',
+                filepath=dir_,
+                fs_conn_id='fs_default',
+                dag=self.dag,
+                timeout=0,
+            )
+            task._hook = self.hook
+            task.run(start_date=DEFAULT_DATE, end_date=DEFAULT_DATE,
+                     ignore_ti_state=True)
+        shutil.rmtree(dir_)
+
+    def test_subdirectory_empty(self):
+        dir_ = tempfile.mkdtemp()
+        tempfile.mkdtemp(dir=dir_)
+        task = FileSensor(
+            task_id='test',
+            filepath=dir_,
+            fs_conn_id='fs_default',
+            dag=self.dag,
+            timeout=0,
+        )
+        task._hook = self.hook
+
+        with self.assertRaises(AirflowSensorTimeout):
 
 Review comment:
   To make this test not take 60s to run please set it so that it only tries a 
single time.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to