Skip to content

Commit 46c81dc

Browse files
Pydot edges returned in different order, so use set
1 parent b04ea06 commit 46c81dc

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

tests/specification_tests/test_causal_dag.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77

88
class TestCausalDAGIssue90(unittest.TestCase):
9-
109
"""
1110
Test the CausalDAG class for the resolution of Issue 90.
1211
"""
@@ -62,7 +61,6 @@ def test_common_cause(self):
6261

6362

6463
class TestCausalDAG(unittest.TestCase):
65-
6664
"""
6765
Test the CausalDAG class for creation of Causal Directed Acyclic Graphs (DAGs).
6866
@@ -176,19 +174,18 @@ def test_proper_backdoor_graph(self):
176174
"""Test whether converting a Causal DAG to a proper back-door graph works correctly."""
177175
causal_dag = CausalDAG(self.dag_dot_path)
178176
proper_backdoor_graph = causal_dag.get_proper_backdoor_graph(["X1", "X2"], ["Y"])
179-
self.assertEqual(
180-
list(proper_backdoor_graph.graph.edges),
181-
[
182-
("X1", "X2"),
183-
("X2", "V"),
184-
("X2", "D2"),
185-
("D1", "D2"),
186-
("D1", "Y"),
187-
("Y", "D3"),
188-
("Z", "X2"),
189-
("Z", "Y"),
190-
],
191-
)
177+
edges = set([
178+
("X1", "X2"),
179+
("X2", "V"),
180+
("X2", "D2"),
181+
("D1", "D2"),
182+
("D1", "Y"),
183+
("Y", "D3"),
184+
("Z", "X2"),
185+
("Z", "Y"),
186+
])
187+
self.assertTrue(
188+
set(proper_backdoor_graph.graph.edges).issubset(edges))
192189

193190
def test_constructive_backdoor_criterion_should_hold(self):
194191
"""Test whether the constructive criterion holds when it should."""
@@ -198,7 +195,7 @@ def test_constructive_backdoor_criterion_should_hold(self):
198195
self.assertTrue(causal_dag.constructive_backdoor_criterion(proper_backdoor_graph, xs, ys, zs))
199196

200197
def test_constructive_backdoor_criterion_should_not_hold_not_d_separator_in_proper_backdoor_graph(
201-
self,
198+
self,
202199
):
203200
"""Test whether the constructive criterion fails when the adjustment set is not a d-separator."""
204201
causal_dag = CausalDAG(self.dag_dot_path)
@@ -207,7 +204,7 @@ def test_constructive_backdoor_criterion_should_not_hold_not_d_separator_in_prop
207204
self.assertFalse(causal_dag.constructive_backdoor_criterion(proper_backdoor_graph, xs, ys, zs))
208205

209206
def test_constructive_backdoor_criterion_should_not_hold_descendent_of_proper_causal_path(
210-
self,
207+
self,
211208
):
212209
"""Test whether the constructive criterion holds when the adjustment set Z contains a descendent of a variable
213210
on a proper causal path between X and Y."""
@@ -392,7 +389,6 @@ def tearDown(self) -> None:
392389

393390

394391
class TestUndirectedGraphAlgorithms(unittest.TestCase):
395-
396392
"""
397393
Test the graph algorithms designed for the undirected graph variants of a Causal DAG.
398394
During the identification process, a Causal DAG is converted into several forms of undirected graph which allow for

0 commit comments

Comments
 (0)