11import tempfile
22
3- import pytest
4-
53from 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