turbaszek commented on a change in pull request #9531:
URL: https://github.com/apache/airflow/pull/9531#discussion_r449633646



##########
File path: tests/plugins/test_plugin_ignore.py
##########
@@ -0,0 +1,96 @@
+#
+# 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.
+#
+
+import os
+import shutil
+import tempfile
+import unittest
+from unittest.mock import patch
+
+from airflow import settings  # type: ignore
+from airflow.utils.file import find_path_from_directory  # type: ignore
+
+
+class TestIgnorePluginFile(unittest.TestCase):
+    """
+    Test that the .airflowignore work and whether the file is properly ignored.
+    """
+
+    def setUp(self):
+        """
+        Make tmp folder and files that should be ignored. And set base path.
+        """
+        self.test_dir = tempfile.mkdtemp()
+        self.test_file = os.path.join(self.test_dir, 'test_file.txt')
+        self.plugin_folder_path = os.path.join(self.test_dir, 'test_ignore')
+        os.mkdir(os.path.join(self.test_dir, "test_ignore"))
+        with open(os.path.join(self.plugin_folder_path, "test_load.py"), "w") 
as file:
+            file.write("#Should not be ignored file")
+        with open(os.path.join(self.plugin_folder_path, ".airflowignore"), 
"w") as file:
+            file.write("#ignore test\nnot\nsubdir2")
+        os.mkdir(os.path.join(self.plugin_folder_path, "subdir1"))
+        with open(os.path.join(self.plugin_folder_path, 
"subdir1/.airflowignore"), "w") as file:
+            file.write("#ignore test\nnone")
+        with open(os.path.join(self.plugin_folder_path, 
"subdir1/test_load_sub1.py"), "w") as file:
+            file.write("#Should not be ignored file")
+        with open(os.path.join(self.plugin_folder_path, 
"test_notload_sub.py"), 'w') as file:
+            file.write('raise Exception("This file should have been 
ignored!")')
+        with open(os.path.join(self.plugin_folder_path, 
"subdir1/test_noneload_sub1.py"), 'w') as file:
+            file.write('raise Exception("This file should have been 
ignored!")')
+        os.mkdir(os.path.join(self.plugin_folder_path, "subdir2"))
+        with open(os.path.join(self.plugin_folder_path, 
"subdir2/test_shouldignore.py"), 'w') as file:
+            file.write('raise Exception("This file should have been 
ignored!")')
+        with open(os.path.join(self.plugin_folder_path, 
"subdir2/test_shouldignore.py"), 'w') as file:
+            file.write('raise Exception("This file should have been 
ignored!")')

Review comment:
       Is content of those files important? There's a lot of repeated code so I 
would opt for some loop like:
   ```python
   for file_path, content in files_content:
       with open(file_path) as f:
           f.wrtie(content)
   ```
   Do you think it will make the code clearer? 




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to