josix commented on code in PR #42902:
URL: https://github.com/apache/airflow/pull/42902#discussion_r1796762620


##########
tests/utils/test_file.py:
##########
@@ -212,3 +213,26 @@ def test_get_modules_from_invalid_file(self):
         modules = list(file_utils.iter_airflow_imports(file_path))
 
         assert len(modules) == 0
+
+
+def test_get_unique_dag_module_name():
+    edge_filenames = [
+        "test_dag.py",
+        "test-dag.py",
+        "test-dag-1.py",
+        "test-dag_1.py",
+        "test-dag.dev.py",
+        "test_dag.prod.py",
+    ]
+    # sha1 of file_path in middle
+    expected_regex = [
+        r"unusual_prefix_[0-9a-f]{40}_test_dag",
+        r"unusual_prefix_[0-9a-f]{40}_test_dag",
+        r"unusual_prefix_[0-9a-f]{40}_test_dag_1",
+        r"unusual_prefix_[0-9a-f]{40}_test_dag_1",
+        r"unusual_prefix_[0-9a-f]{40}_test_dag_dev",
+        r"unusual_prefix_[0-9a-f]{40}_test_dag_prod",
+    ]
+    for idx, filename in enumerate(edge_filenames):
+        modify_module_name = file_utils.get_unique_dag_module_name(filename)
+        assert re2.match(re2.compile(expected_regex[idx]), modify_module_name) 
is not None

Review Comment:
   How about mocking the hexdigest of the `hashlib.sha1` output like this?
   
   ```suggestion
   @pytest.mark.parametrize(
       "edge_filenames, expected_module_name", # sha1 of file_path in middle
       [
           ("test_dag.py", "unusual_prefix_mocked_sha1_test_dag"),
           ("test-dag.py", "unusual_prefix_mocked_sha1_test_dag"),
           ("test-dag-1.py", "unusual_prefix_mocked_sha1_test_dag_1"),
           ("test-dag_1.py", "unusual_prefix_mocked_sha1_test_dag_1"),
           ("test-dag.dev.py", "unusual_prefix_mocked_sha1_test_dag_dev"),
           ("test_dag.prod.py", "unusual_prefix_mocked_sha1_test_dag_prod"),
       ],
   )
   def test_get_unique_dag_module_name(edge_filenames, expected_module_name):
       with mock.patch("hashlib.sha1") as mock_hash_object:
           mock_hash_object.hexdigest.return_value = "mocked_sha1"
           for filename in enumerate(edge_filenames):
               modify_module_name = 
file_utils.get_unique_dag_module_name(filename)
               assert expected_module_name == modify_module_name
   ```



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