jason810496 commented on code in PR #74034:
URL: https://github.com/apache/airflow/pull/74034#discussion_r4163053815


##########
shared/dagnode/tests/dagnode/test_cycle.py:
##########
@@ -0,0 +1,87 @@
+# 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.
+
+from __future__ import annotations
+
+import sys
+
+import pytest
+
+from airflow_shared.dagnode.cycle import detect_cycle
+
+
+def edges_of(graph: dict[str, list[str]]):
+    return lambda node_id: graph[node_id]
+
+
[email protected](
+    "graph",
+    [
+        pytest.param({}, id="empty"),
+        pytest.param({"a": []}, id="single-node"),
+        pytest.param({"a": ["b"], "b": ["c"], "c": []}, id="chain"),
+        pytest.param({"a": ["b", "c"], "b": ["d"], "c": ["d"], "d": []}, 
id="diamond"),
+        pytest.param({"a": ["b"], "b": [], "c": ["d"], "d": []}, 
id="disconnected-components"),
+    ],
+)
+def test_returns_none_when_acyclic(graph):
+    assert detect_cycle(graph, edges_of(graph)) is None
+
+
[email protected](
+    ("graph", "expected"),
+    [
+        pytest.param({"a": ["a"]}, "a", id="self-loop"),
+        pytest.param({"a": ["b"], "b": ["a"]}, "b", id="two-node-cycle"),
+        pytest.param({"a": ["b"], "b": ["c"], "c": ["a"]}, "c", 
id="three-node-cycle"),
+        pytest.param({"a": ["b"], "b": ["c"], "c": ["b"]}, "c", 
id="cycle-below-an-acyclic-root"),
+        pytest.param({"a": [], "b": ["c"], "c": ["b"]}, "c", 
id="cycle-outside-the-first-component"),
+    ],
+)
+def test_returns_the_node_whose_edge_closes_the_cycle(graph, expected):
+    assert detect_cycle(graph, edges_of(graph)) == expected
+
+
+def test_follows_downstream_edges_only():

Review Comment:
   Addressed in 
https://github.com/apache/airflow/pull/74034/commits/e5ae872c9a13ac7f73be922319c663af515fd644.



##########
shared/dagnode/tests/dagnode/test_cycle.py:
##########
@@ -0,0 +1,87 @@
+# 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.
+
+from __future__ import annotations
+
+import sys
+
+import pytest
+
+from airflow_shared.dagnode.cycle import detect_cycle
+
+
+def edges_of(graph: dict[str, list[str]]):
+    return lambda node_id: graph[node_id]
+
+
[email protected](
+    "graph",
+    [
+        pytest.param({}, id="empty"),
+        pytest.param({"a": []}, id="single-node"),
+        pytest.param({"a": ["b"], "b": ["c"], "c": []}, id="chain"),
+        pytest.param({"a": ["b", "c"], "b": ["d"], "c": ["d"], "d": []}, 
id="diamond"),
+        pytest.param({"a": ["b"], "b": [], "c": ["d"], "d": []}, 
id="disconnected-components"),
+    ],
+)
+def test_returns_none_when_acyclic(graph):
+    assert detect_cycle(graph, edges_of(graph)) is None
+
+
[email protected](
+    ("graph", "expected"),
+    [
+        pytest.param({"a": ["a"]}, "a", id="self-loop"),
+        pytest.param({"a": ["b"], "b": ["a"]}, "b", id="two-node-cycle"),
+        pytest.param({"a": ["b"], "b": ["c"], "c": ["a"]}, "c", 
id="three-node-cycle"),
+        pytest.param({"a": ["b"], "b": ["c"], "c": ["b"]}, "c", 
id="cycle-below-an-acyclic-root"),
+        pytest.param({"a": [], "b": ["c"], "c": ["b"]}, "c", 
id="cycle-outside-the-first-component"),
+    ],
+)
+def test_returns_the_node_whose_edge_closes_the_cycle(graph, expected):
+    assert detect_cycle(graph, edges_of(graph)) == expected
+
+
+def test_follows_downstream_edges_only():

Review Comment:
   Addressed in 
https://github.com/apache/airflow/pull/74034/commits/e5ae872c9a13ac7f73be922319c663af515fd644,
 thanks.



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

Reply via email to