Skip to content

Commit 11dcd91

Browse files
Leon-Algoclaude
andauthored
test: fix broken async partitioner integration tests (#193)
Convert BFS/DFS/ECE partitioner integration tests to the synchronous BasePartitioner/storage APIs and fix the NetworkXStorage import so the tests collect again. No production code changes. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
1 parent 3a3eb09 commit 11dcd91

3 files changed

Lines changed: 58 additions & 73 deletions

File tree

‎tests/integration_tests/models/partitioner/test_bfs_partitioner.py‎

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,39 @@
11
import tempfile
22

3-
import pytest
4-
53
from graphgen.bases.datatypes import Community
6-
from graphgen.models import BFSPartitioner, NetworkXStorage
4+
from graphgen.models import BFSPartitioner
5+
from graphgen.storage import NetworkXStorage
76

87

9-
@pytest.mark.asyncio
10-
async def test_empty_graph():
8+
def test_empty_graph():
119
with tempfile.TemporaryDirectory() as tmpdir:
1210
storage = NetworkXStorage(working_dir=tmpdir, namespace="empty")
1311
partitioner = BFSPartitioner()
14-
communities = await partitioner.partition(storage, max_units_per_community=5)
12+
communities = list(partitioner.partition(storage, max_units_per_community=5))
1513
assert communities == []
1614

1715

18-
@pytest.mark.asyncio
19-
async def test_single_node():
16+
def test_single_node():
2017
nodes = [("A", {"desc": "alone"})]
2118
edges = []
2219
with tempfile.TemporaryDirectory() as tmpdir:
2320
storage = NetworkXStorage(working_dir=tmpdir, namespace="single_node")
2421

2522
for nid, ndata in nodes:
26-
await storage.upsert_node(nid, ndata)
23+
storage.upsert_node(nid, ndata)
2724
for src, tgt, edata in edges:
28-
await storage.upsert_edge(src, tgt, edata)
25+
storage.upsert_edge(src, tgt, edata)
2926

3027
partitioner = BFSPartitioner()
31-
communities: list[Community] = await partitioner.partition(
28+
communities: list[Community] = list(partitioner.partition(
3229
storage, max_units_per_community=5
33-
)
30+
))
3431
assert len(communities) == 1
3532
assert communities[0].nodes == ["A"]
3633
assert communities[0].edges == []
3734

3835

39-
@pytest.mark.asyncio
40-
async def test_small_graph():
36+
def test_small_graph():
4137
"""
4238
0 - 1 - 2
4339
| | |
@@ -59,14 +55,14 @@ async def test_small_graph():
5955
storage = NetworkXStorage(working_dir=tmpdir, namespace="small_graph")
6056

6157
for nid, ndata in nodes:
62-
await storage.upsert_node(nid, ndata)
58+
storage.upsert_node(nid, ndata)
6359
for src, tgt, edata in edges:
64-
await storage.upsert_edge(src, tgt, edata)
60+
storage.upsert_edge(src, tgt, edata)
6561

6662
partitioner = BFSPartitioner()
67-
communities: list[Community] = await partitioner.partition(
63+
communities: list[Community] = list(partitioner.partition(
6864
storage, max_units_per_community=4
69-
)
65+
))
7066

7167
assert len(communities) <= 5
7268

‎tests/integration_tests/models/partitioner/test_dfs_partitioner.py‎

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
import tempfile
22

3-
import pytest
4-
53
from graphgen.bases.datatypes import Community
6-
from graphgen.models import DFSPartitioner, NetworkXStorage
4+
from graphgen.models import DFSPartitioner
5+
from graphgen.storage import NetworkXStorage
76

87

9-
@pytest.mark.asyncio
10-
async def test_empty_graph():
8+
def test_empty_graph():
119
with tempfile.TemporaryDirectory() as tmpdir:
1210
storage = NetworkXStorage(
1311
working_dir=tmpdir,
1412
namespace="empty",
1513
)
1614
partitioner = DFSPartitioner()
17-
communities = await partitioner.partition(storage, max_units_per_community=5)
15+
communities = list(partitioner.partition(storage, max_units_per_community=5))
1816
assert communities == []
1917

2018

21-
@pytest.mark.asyncio
22-
async def test_single_node():
19+
def test_single_node():
2320
nodes = [("A", {"desc": "alone"})]
2421
edges = []
2522
with tempfile.TemporaryDirectory() as tmpdir:
@@ -29,21 +26,20 @@ async def test_single_node():
2926
)
3027

3128
for nid, ndata in nodes:
32-
await storage.upsert_node(nid, ndata)
29+
storage.upsert_node(nid, ndata)
3330
for src, tgt, edata in edges:
34-
await storage.upsert_edge(src, tgt, edata)
31+
storage.upsert_edge(src, tgt, edata)
3532

3633
partitioner = DFSPartitioner()
37-
communities: list[Community] = await partitioner.partition(
34+
communities: list[Community] = list(partitioner.partition(
3835
storage, max_units_per_community=5
39-
)
36+
))
4037
assert len(communities) == 1
4138
assert communities[0].nodes == ["A"]
4239
assert communities[0].edges == []
4340

4441

45-
@pytest.mark.asyncio
46-
async def test_small_graph():
42+
def test_small_graph():
4743
"""
4844
0 - 1 - 2
4945
| | |
@@ -68,17 +64,17 @@ async def test_small_graph():
6864
)
6965

7066
for nid, ndata in nodes:
71-
await storage.upsert_node(nid, ndata)
67+
storage.upsert_node(nid, ndata)
7268
for src, tgt, edata in edges:
73-
await storage.upsert_edge(src, tgt, edata)
69+
storage.upsert_edge(src, tgt, edata)
7470

7571
partitioner = DFSPartitioner()
7672

77-
communities: list[Community] = await partitioner.partition(
73+
communities: list[Community] = list(partitioner.partition(
7874
storage, max_units_per_community=4
79-
)
75+
))
8076

81-
assert len(communities) <= 5
77+
assert len(communities) <= len(nodes)
8278
all_nodes = set()
8379
all_edges = set()
8480
for c in communities:

‎tests/integration_tests/models/partitioner/test_ece_partitioner.py‎

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
import tempfile
22

3-
import pytest
4-
53
from graphgen.bases.datatypes import Community
6-
from graphgen.models import ECEPartitioner, NetworkXStorage
4+
from graphgen.models import ECEPartitioner
5+
from graphgen.storage import NetworkXStorage
76

87

9-
@pytest.mark.asyncio
10-
async def test_ece_empty_graph():
8+
def test_ece_empty_graph():
119
"""ECE partitioning on an empty graph should return an empty community list."""
1210
with tempfile.TemporaryDirectory() as tmpdir:
1311
storage = NetworkXStorage(working_dir=tmpdir, namespace="empty")
1412
partitioner = ECEPartitioner()
15-
communities = await partitioner.partition(
13+
communities = list(partitioner.partition(
1614
storage, max_units_per_community=5, unit_sampling="random"
17-
)
15+
))
1816
assert communities == []
1917

2018

21-
@pytest.mark.asyncio
22-
async def test_ece_single_node():
19+
def test_ece_single_node():
2320
"""A single node must be placed in exactly one community under any edge-sampling strategy."""
2421
nodes = [("A", {"desc": "alone", "length": 10, "loss": 0.1})]
2522

@@ -29,19 +26,18 @@ async def test_ece_single_node():
2926
working_dir=tmpdir, namespace=f"single_{strategy}"
3027
)
3128
for nid, ndata in nodes:
32-
await storage.upsert_node(nid, ndata)
29+
storage.upsert_node(nid, ndata)
3330

3431
partitioner = ECEPartitioner()
35-
communities: list[Community] = await partitioner.partition(
32+
communities: list[Community] = list(partitioner.partition(
3633
storage, max_units_per_community=5, unit_sampling=strategy
37-
)
34+
))
3835
assert len(communities) == 1
3936
assert communities[0].nodes == ["A"]
4037
assert communities[0].edges == []
4138

4239

43-
@pytest.mark.asyncio
44-
async def test_ece_small_graph_random():
40+
def test_ece_small_graph_random():
4541
"""
4642
2x3 grid graph:
4743
0 — 1 — 2
@@ -63,14 +59,14 @@ async def test_ece_small_graph_random():
6359
with tempfile.TemporaryDirectory() as tmpdir:
6460
storage = NetworkXStorage(working_dir=tmpdir, namespace="small_random")
6561
for nid, ndata in nodes:
66-
await storage.upsert_node(nid, ndata)
62+
storage.upsert_node(nid, ndata)
6763
for src, tgt, edata in edges:
68-
await storage.upsert_edge(src, tgt, edata)
64+
storage.upsert_edge(src, tgt, edata)
6965

7066
partitioner = ECEPartitioner()
71-
communities: list[Community] = await partitioner.partition(
67+
communities: list[Community] = list(partitioner.partition(
7268
storage, max_units_per_community=4, unit_sampling="random"
73-
)
69+
))
7470

7571
# Basic integrity checks
7672
all_nodes = set()
@@ -83,8 +79,7 @@ async def test_ece_small_graph_random():
8379
assert len(all_edges) == 7
8480

8581

86-
@pytest.mark.asyncio
87-
async def test_ece_small_graph_min_loss():
82+
def test_ece_small_graph_min_loss():
8883
"""
8984
Same grid graph, but using min_loss sampling.
9085
Edges with lower loss should be preferred during community expansion.
@@ -105,14 +100,14 @@ async def test_ece_small_graph_min_loss():
105100
with tempfile.TemporaryDirectory() as tmpdir:
106101
storage = NetworkXStorage(working_dir=tmpdir, namespace="small_min")
107102
for nid, ndata in nodes:
108-
await storage.upsert_node(nid, ndata)
103+
storage.upsert_node(nid, ndata)
109104
for src, tgt, edata in edges:
110-
await storage.upsert_edge(src, tgt, edata)
105+
storage.upsert_edge(src, tgt, edata)
111106

112107
partitioner = ECEPartitioner()
113-
communities: list[Community] = await partitioner.partition(
108+
communities: list[Community] = list(partitioner.partition(
114109
storage, max_units_per_community=4, unit_sampling="min_loss"
115-
)
110+
))
116111

117112
all_nodes = set()
118113
all_edges = set()
@@ -124,8 +119,7 @@ async def test_ece_small_graph_min_loss():
124119
assert len(all_edges) == 7
125120

126121

127-
@pytest.mark.asyncio
128-
async def test_ece_small_graph_max_loss():
122+
def test_ece_small_graph_max_loss():
129123
"""
130124
Same grid graph, but using max_loss sampling.
131125
Edges with higher loss should be preferred during community expansion.
@@ -147,14 +141,14 @@ async def test_ece_small_graph_max_loss():
147141
with tempfile.TemporaryDirectory() as tmpdir:
148142
storage = NetworkXStorage(working_dir=tmpdir, namespace="small_max")
149143
for nid, ndata in nodes:
150-
await storage.upsert_node(nid, ndata)
144+
storage.upsert_node(nid, ndata)
151145
for src, tgt, edata in edges:
152-
await storage.upsert_edge(src, tgt, edata)
146+
storage.upsert_edge(src, tgt, edata)
153147

154148
partitioner = ECEPartitioner()
155-
communities: list[Community] = await partitioner.partition(
149+
communities: list[Community] = list(partitioner.partition(
156150
storage, max_units_per_community=4, unit_sampling="max_loss"
157-
)
151+
))
158152

159153
all_nodes = set()
160154
all_edges = set()
@@ -166,8 +160,7 @@ async def test_ece_small_graph_max_loss():
166160
assert len(all_edges) == 7
167161

168162

169-
@pytest.mark.asyncio
170-
async def test_ece_max_tokens_limit():
163+
def test_ece_max_tokens_limit():
171164
"""Ensure max_tokens_per_community is respected."""
172165
# node id -> data
173166
node_data = {"A": {"length": 3000}, "B": {"length": 3000}, "C": {"length": 3000}}
@@ -177,17 +170,17 @@ async def test_ece_max_tokens_limit():
177170
with tempfile.TemporaryDirectory() as tmpdir:
178171
storage = NetworkXStorage(working_dir=tmpdir, namespace="token_limit")
179172
for nid, ndata in node_data.items():
180-
await storage.upsert_node(nid, ndata)
173+
storage.upsert_node(nid, ndata)
181174
for src, tgt, edata in edges:
182-
await storage.upsert_edge(src, tgt, edata)
175+
storage.upsert_edge(src, tgt, edata)
183176

184177
partitioner = ECEPartitioner()
185-
communities: list[Community] = await partitioner.partition(
178+
communities: list[Community] = list(partitioner.partition(
186179
storage,
187180
max_units_per_community=10,
188181
max_tokens_per_community=5000, # 1 node (3000) + 1 edge (2000) = 5000
189182
unit_sampling="random",
190-
)
183+
))
191184

192185
# With a 5000-token budget we need at least two communities
193186
assert len(communities) >= 2

0 commit comments

Comments
 (0)