Skip to content

Commit 455fed2

Browse files
committed
Fix bug when building large graph for benchmarks
We should still add modules, even if they have no imports.
1 parent 9657d65 commit 455fed2

1 file changed

Lines changed: 123 additions & 4 deletions

File tree

tests/benchmarking/test_benchmarking.py

Lines changed: 123 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def large_graph():
2222
graph = ImportGraph()
2323

2424
for importer, importeds in graph_dict.items():
25+
graph.add_module(importer)
2526
for imported in importeds:
2627
graph.add_import(importer=importer, imported=imported)
2728

@@ -70,7 +71,127 @@ def test_top_level_large_graph(large_graph, benchmark):
7071
layers=TOP_LEVEL_LAYERS,
7172
containers=("mypackage",),
7273
)
73-
assert result == set()
74+
assert result == {
75+
PackageDependency(
76+
importer="mypackage.domain",
77+
imported="mypackage.application",
78+
routes=frozenset(
79+
{
80+
Route(
81+
heads=frozenset({"mypackage.domain.7960519247.6215972208"}),
82+
middle=(),
83+
tails=frozenset(
84+
{"mypackage.application.7537183614.6928774480.5676105139.3275676604"}
85+
),
86+
),
87+
Route(
88+
heads=frozenset(
89+
{
90+
"mypackage.domain.6928774480.5676105139.1330171288.7588443317.4661445087" # noqa:E501
91+
}
92+
),
93+
middle=(),
94+
tails=frozenset(
95+
{"mypackage.application.7537183614.3430454356.1518604543"}
96+
),
97+
),
98+
Route(
99+
heads=frozenset(
100+
{"mypackage.domain.6928774480.5676105139.1262087557.3485088613"}
101+
),
102+
middle=(),
103+
tails=frozenset(
104+
{"mypackage.application.7537183614.3430454356.1518604543"}
105+
),
106+
),
107+
Route(
108+
heads=frozenset({"mypackage.domain.2538372545.1186630948"}),
109+
middle=(),
110+
tails=frozenset(
111+
{"mypackage.application.7537183614.8114145747.9320351411"}
112+
),
113+
),
114+
Route(
115+
heads=frozenset(
116+
{
117+
"mypackage.domain.6928774480.1028759677.7960519247.2888779155.7486857426" # noqa:E501
118+
}
119+
),
120+
middle=(),
121+
tails=frozenset(
122+
{"mypackage.application.7537183614.3430454356.1518604543"}
123+
),
124+
),
125+
Route(
126+
heads=frozenset({"mypackage.domain.1330171288.2647367251"}),
127+
middle=(),
128+
tails=frozenset(
129+
{"mypackage.application.7537183614.4619328254.6682701798"}
130+
),
131+
),
132+
Route(
133+
heads=frozenset({"mypackage.domain.2538372545.7264406040.9149218450"}),
134+
middle=(),
135+
tails=frozenset(
136+
{"mypackage.application.7537183614.2538372545.8114145747"}
137+
),
138+
),
139+
Route(
140+
heads=frozenset({"mypackage.domain.1330171288.2647367251"}),
141+
middle=(),
142+
tails=frozenset(
143+
{"mypackage.application.7537183614.7582995238.6180716911"}
144+
),
145+
),
146+
Route(
147+
heads=frozenset({"mypackage.domain.1330171288.2647367251"}),
148+
middle=(),
149+
tails=frozenset(
150+
{"mypackage.application.7537183614.3851022211.5970652803"}
151+
),
152+
),
153+
}
154+
),
155+
),
156+
PackageDependency(
157+
importer="mypackage.domain",
158+
imported="mypackage.plugins",
159+
routes=frozenset(
160+
{
161+
Route(
162+
heads=frozenset({"mypackage.domain.8114145747.6690893472"}),
163+
middle=(),
164+
tails=frozenset(
165+
{"mypackage.plugins.5634303718.6180716911.1810840010.7887344963"}
166+
),
167+
)
168+
}
169+
),
170+
),
171+
PackageDependency(
172+
importer="mypackage.application",
173+
imported="mypackage.plugins",
174+
routes=frozenset(
175+
{
176+
Route(
177+
heads=frozenset(
178+
{
179+
"mypackage.application.7537183614.2538372545.1153384736.6297289996",
180+
"mypackage.application.7537183614.2538372545.1153384736.6404547812.6297289996", # noqa:E501
181+
}
182+
),
183+
middle=("mypackage.6398020133.9075581450.6529869526.6297289996",),
184+
tails=frozenset(
185+
{
186+
"mypackage.plugins.5634303718.6180716911.7582995238.1039461003.2943193489", # noqa:E501
187+
"mypackage.plugins.5634303718.6180716911.7582995238.1039461003.6322703811", # noqa:E501
188+
}
189+
),
190+
)
191+
}
192+
),
193+
),
194+
}
74195

75196

76197
def test_deep_layers_large_graph(large_graph, benchmark):
@@ -217,7 +338,7 @@ def test_deep_layers_large_graph(large_graph, benchmark):
217338

218339
def test_find_descendants(large_graph, benchmark):
219340
result = _run_benchmark(benchmark, large_graph.find_descendants, "mypackage")
220-
assert len(result) == 17348
341+
assert len(result) == 28222
221342

222343

223344
def test_find_downstream_modules(large_graph, benchmark):
@@ -241,7 +362,6 @@ def test_chain_found(self, large_graph, benchmark):
241362
)
242363
assert result is not None
243364

244-
@pytest.mark.xfail("grimp.exceptions.ModuleNotPresent")
245365
def test_no_chain(self, large_graph, benchmark):
246366
result = _run_benchmark(
247367
benchmark,
@@ -263,7 +383,6 @@ def test_chains_found(self, large_graph, benchmark):
263383
)
264384
assert len(result) > 0
265385

266-
@pytest.mark.xfail("grimp.exceptions.ModuleNotPresent")
267386
def test_no_chains(self, large_graph, benchmark):
268387
result = _run_benchmark(
269388
benchmark,

0 commit comments

Comments
 (0)