nuclearpinguin commented on a change in pull request #7346: [AIRFLOW-6720] 
Detect missing tests for providers package
URL: https://github.com/apache/airflow/pull/7346#discussion_r373957187
 
 

 ##########
 File path: tests/test_project_structure.py
 ##########
 @@ -35,3 +70,50 @@ def assert_file_not_contains(self, filename, pattern):
         with open(filename, 'rb', 0) as file, mmap.mmap(file.fileno(), 0, 
access=mmap.ACCESS_READ) as content:
             if content.find(bytes(pattern, 'utf-8')) != -1:
                 self.fail(f"File {filename} contians illegal pattern - 
{pattern}")
+
+    def test_providers_modules_should_have_tests(self):
+        # TODO: Should we extend this test to cover other directories?
+        expected_test_files = 
glob.glob(f"{ROOT_FOLDER}/airflow/providers/**/*.py", recursive=True)
+        # Make path relative
+        expected_test_files = (os.path.relpath(f, ROOT_FOLDER) for f in 
expected_test_files)
+        # Exclude example_dags
+        expected_test_files = (f for f in expected_test_files if 
"/example_dags/" not in f)
+        # Exclude __init__.py
+        expected_test_files = (f for f in expected_test_files if not 
f.endswith("__init__.py"))
+        # Change airflow/ to tests/
+        expected_test_files = (
+            f'tests/{f.partition("/")[2]}'
+            for f in expected_test_files if not f.endswith("__init__.py")
+        )
+        # Add test_ prefix to filename
+        expected_test_files = (
+            f'{f.rpartition("/")[0]}/test_{f.rpartition("/")[2]}'
+            for f in expected_test_files if not f.endswith("__init__.py")
+        )
+
+        current_test_files = 
glob.glob(f"{ROOT_FOLDER}/tests/providers/**/*.py", recursive=True)
+        # Make path relative
+        current_test_files = (os.path.relpath(f, ROOT_FOLDER) for f in 
current_test_files)
+        # Exclude __init__.py
+        current_test_files = (f for f in current_test_files if not 
f.endswith("__init__.py"))
+
+        expected_test_files = set(expected_test_files)
+        current_test_files = set(current_test_files)
+
+        missing_tests_files = expected_test_files - 
expected_test_files.intersection(current_test_files)
+        self.assertEqual(missing_tests_files, MISSING_TEST_FILES)
 
 Review comment:
   I think `missing_tests_files <= MISSING_TEST_FILES` is the proper condition, 
as `missing_tests_files` can be subset of `MISSING_TEST_FILES`. In case someone 
added a missing test this test should pass and 
`test_keep_missing_test_files_update` should fail. Otherwise, we are testing 
the same thing two times. 

----------------------------------------------------------------
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