You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/02/03 07:49:13 UTC

[GitHub] [airflow] potiuk commented on a change in pull request #7346: [AIRFLOW-6720] Detect missing tests for providers package

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

 ##########
 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 it's good with equals. The goal is - similar as with pylint_todo.txt to go with this list to empty. So when someone adds test file, the test will fail and it will be the right time for the person who adds this file to remove it from the list.

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


With regards,
Apache Git Services