jason810496 commented on code in PR #42902:
URL: https://github.com/apache/airflow/pull/42902#discussion_r1796760117
##########
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",
+ ]
Review Comment:
Without using regex to match the expected output, the test will be like this:
```python
@pytest.mark.parametrize(
"edge_filename, expected_modification_end",
[
("test_dag.py", "_test_dag"),
# ...
],
)
def test_get_unique_dag_module_name(edge_filename,
expected_modification_end):
modify_module_name = file_utils.get_unique_dag_module_name(edge_filename)
assert modify_module_name.startswith("unusual_prefix_")
assert modify_module_name.endswith(expected_modification_end)
```
From my perspective, using regex for matching will make it clearer what the
expected output of
[`get_unique_dag_module_name`](https://github.com/apache/airflow/blob/main/airflow/utils/file.py#L354-L359)
is.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]