Skip to content

Commit 36cb662

Browse files
Added missed black reformat
1 parent 72a23df commit 36cb662

File tree

1 file changed

+39
-27
lines changed

1 file changed

+39
-27
lines changed

tests/test.py

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,25 @@
44

55
from django.test import TestCase
66
from django.core.exceptions import ValidationError
7-
from django_postgresql_dag.exceptions import NodeNotReachableException, GraphModelsCannotBeParsedException, IncorrectUsageException
8-
from django_postgresql_dag.transformations import _ordered_filter, edges_from_nodes_queryset, nodes_from_edges_queryset, nx_from_queryset, model_to_dict
9-
from django_postgresql_dag.query_builders import AncestorQuery, DescendantQuery, UpwardPathQuery, DownwardPathQuery, ConnectedGraphQuery
7+
from django_postgresql_dag.exceptions import (
8+
NodeNotReachableException,
9+
GraphModelsCannotBeParsedException,
10+
IncorrectUsageException,
11+
)
12+
from django_postgresql_dag.transformations import (
13+
_ordered_filter,
14+
edges_from_nodes_queryset,
15+
nodes_from_edges_queryset,
16+
nx_from_queryset,
17+
model_to_dict,
18+
)
19+
from django_postgresql_dag.query_builders import (
20+
AncestorQuery,
21+
DescendantQuery,
22+
UpwardPathQuery,
23+
DownwardPathQuery,
24+
ConnectedGraphQuery,
25+
)
1026

1127
from .models import NetworkNode, NetworkEdge, NodeSet, EdgeSet
1228

@@ -58,7 +74,7 @@ def test_02_dag(self):
5874
a3.add_child(b3)
5975
a3.add_child(b4)
6076
b3.add_child(c1)
61-
77+
6278
log.debug("descendants part 2")
6379
root_descendants = root.descendants()
6480
self.assertNotIn(root, root_descendants)
@@ -69,17 +85,17 @@ def test_02_dag(self):
6985
self.assertNotIn(c1, c1_ancestors)
7086
self.assertNotIn(b4, c1_ancestors)
7187
self.assertTrue(all(elem in c1_ancestors for elem in [root, a3, b3]))
72-
88+
7389
a1.add_child(b2)
7490
a2.add_child(b2)
7591
b3.add_child(c2)
7692
b4.add_child(c1)
77-
93+
7894
log.debug("ancestors part 2")
7995
c1_ancestors = c1.ancestors()
8096
self.assertNotIn(c1, c1_ancestors)
8197
self.assertTrue(all(elem in c1_ancestors for elem in [root, a3, b3, b4]))
82-
98+
8399
# Try to add a node that is already an ancestor
84100
try:
85101
b3.add_parent(c1)
@@ -174,8 +190,7 @@ def test_02_dag(self):
174190
log.debug("path x2")
175191
self.assertTrue(
176192
[p.name for p in root.path(c1)] == ["root", "a3", "b3", "c1"]
177-
or [p.name for p in c1.path(root, directional=False)]
178-
== ["root", "a3", "b4", "c1"]
193+
or [p.name for p in c1.path(root, directional=False)] == ["root", "a3", "b4", "c1"]
179194
)
180195

181196
log.debug("path")
@@ -186,10 +201,8 @@ def test_02_dag(self):
186201

187202
log.debug("shortest_path x2")
188203
self.assertTrue(
189-
[p.name for p in c1.path(root, directional=False)]
190-
== ["c1", "b3", "a3", "root"]
191-
or [p.name for p in c1.path(root, directional=False)]
192-
== ["c1", "b4", "a3", "root"]
204+
[p.name for p in c1.path(root, directional=False)] == ["c1", "b3", "a3", "root"]
205+
or [p.name for p in c1.path(root, directional=False)] == ["c1", "b4", "a3", "root"]
193206
)
194207

195208
log.debug("get_leaves")
@@ -227,15 +240,19 @@ def test_02_dag(self):
227240
log.debug("ancestors")
228241
self.assertEqual([p.name for p in c1.ancestors()], ["root", "a3", "b4"])
229242
self.assertFalse(c1.is_island())
230-
243+
231244
# Test is we can properly export to a NetworkX graph
232245
log = logging.getLogger("test_02_networkx")
233-
nx_out = nx_from_queryset(c1.ancestors_and_self(), graph_attributes_dict={"test": "test"}, node_attribute_fields_list=["id", "name"], edge_attribute_fields_list=["id", "name"])
246+
nx_out = nx_from_queryset(
247+
c1.ancestors_and_self(),
248+
graph_attributes_dict={"test": "test"},
249+
node_attribute_fields_list=["id", "name"],
250+
edge_attribute_fields_list=["id", "name"],
251+
)
234252
log.debug("Check attributes")
235253
self.assertEqual(nx_out.graph, {"test": "test"})
236-
self.assertEqual(nx_out.nodes[11], {'id': 11, 'name': 'root'})
237-
self.assertEqual(nx_out.edges[11, 14], {'id': 4, 'name': 'root a3'})
238-
254+
self.assertEqual(nx_out.nodes[11], {"id": 11, "name": "root"})
255+
self.assertEqual(nx_out.edges[11, 14], {"id": 4, "name": "root a3"})
239256

240257
"""
241258
Simulate a basic irrigation canal network
@@ -456,14 +473,12 @@ def test_02_dag(self):
456473
adjacency_list.append([f"SA{n}", f"SB{n}"])
457474
adjacency_list.append([f"SA{n}", f"SC{n}"])
458475

459-
460476
# Create and assign nodes to variables
461477
log.debug("Start creating nodes")
462478
for node in node_name_list2:
463479
globals()[f"{node}"] = NetworkNode.objects.create(name=node)
464480
log.debug("Done creating nodes")
465481

466-
467482
log.debug("Connect nodes")
468483
for connection in adjacency_list:
469484
globals()[f"{connection[0]}"].add_child(globals()[f"{connection[1]}"])
@@ -508,7 +523,7 @@ def create_multilinked_nodes(shared_edge_count):
508523
for _ in range(shared_edge_count):
509524
child_node.add_parent(parent_node)
510525

511-
return child_node, parent_node
526+
return child_node, parent_node
512527

513528
def delete_parents():
514529
child_node, parent_node = create_multilinked_nodes(shared_edge_count)
@@ -554,7 +569,6 @@ def run_test():
554569

555570
n = 22 # Keep it an even number
556571

557-
558572
log.debug("Start creating nodes")
559573
for i in range(2 * n):
560574
NetworkNode(pk=i, name=str(i)).save()
@@ -591,17 +605,15 @@ def run_test():
591605
last = NetworkNode.objects.get(name=str(2 * n - 1))
592606

593607
path_exists = first.path_exists(last, max_depth=n)
594-
log.debug(f"Path exists: {path_exists}")
595-
self.assertTrue(path_exists, True)
608+
log.debug(f"Path exists: {path_exists}")
609+
self.assertTrue(path_exists, True)
596610
self.assertEqual(first.distance(last, max_depth=n), n - 1)
597611

598612
log.debug(f"Node count: {NetworkNode.objects.count()}")
599613
log.debug(f"Edge count: {NetworkEdge.objects.count()}")
600614

601615
# Connect the first-created node to the last-created node
602-
NetworkNode.objects.get(pk=0).add_child(
603-
NetworkNode.objects.get(pk=2 * n - 1)
604-
)
616+
NetworkNode.objects.get(pk=0).add_child(NetworkNode.objects.get(pk=2 * n - 1))
605617

606618
middle = NetworkNode.objects.get(pk=n - 1)
607619
distance = first.distance(middle, max_depth=n)

0 commit comments

Comments
 (0)