Skip to content

Commit 3a95fe3

Browse files
committed
Remove _run_benchmark function
This indirection wasn't useful.
1 parent 5c58290 commit 3a95fe3

1 file changed

Lines changed: 35 additions & 51 deletions

File tree

tests/benchmarking/test_benchmarking.py

Lines changed: 35 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
from .adaptors import PrefixMissingCache
1212

1313

14-
def _run_benchmark(benchmark, fn, *args, **kwargs):
15-
return benchmark(fn, *args, **kwargs)
16-
17-
1814
@pytest.fixture(scope="module")
1915
def large_graph():
2016
raw_json = (Path(__file__).parent / "large_graph.json").read_text()
@@ -59,14 +55,16 @@ def large_graph():
5955
middle=(),
6056
tails=frozenset(
6157
{
62-
"mypackage.application.7537183614.6928774480.5676105139.3275676604" # noqa:E501
58+
"mypackage.application.7537183614.6928774480.5676105139.3275676604"
59+
# noqa:E501
6360
}
6461
),
6562
),
6663
Route(
6764
heads=frozenset(
6865
{
69-
"mypackage.domain.6928774480.5676105139.1330171288.7588443317.4661445087" # noqa:E501
66+
"mypackage.domain.6928774480.5676105139.1330171288.7588443317.4661445087"
67+
# noqa:E501
7068
}
7169
),
7270
middle=(),
@@ -87,7 +85,8 @@ def large_graph():
8785
Route(
8886
heads=frozenset(
8987
{
90-
"mypackage.domain.6928774480.1028759677.7960519247.2888779155.7486857426" # noqa:E501
88+
"mypackage.domain.6928774480.1028759677.7960519247.2888779155.7486857426"
89+
# noqa:E501
9190
}
9291
),
9392
middle=(),
@@ -139,15 +138,19 @@ def large_graph():
139138
Route(
140139
heads=frozenset(
141140
{
142-
"mypackage.application.7537183614.2538372545.1153384736.6297289996", # noqa:E501
143-
"mypackage.application.7537183614.2538372545.1153384736.6404547812.6297289996", # noqa:E501
141+
"mypackage.application.7537183614.2538372545.1153384736.6297289996",
142+
# noqa:E501
143+
"mypackage.application.7537183614.2538372545.1153384736.6404547812.6297289996",
144+
# noqa:E501
144145
}
145146
),
146147
middle=("mypackage.6398020133.9075581450.6529869526.6297289996",),
147148
tails=frozenset(
148149
{
149-
"mypackage.plugins.5634303718.6180716911.7582995238.1039461003.2943193489", # noqa:E501
150-
"mypackage.plugins.5634303718.6180716911.7582995238.1039461003.6322703811", # noqa:E501
150+
"mypackage.plugins.5634303718.6180716911.7582995238.1039461003.2943193489",
151+
# noqa:E501
152+
"mypackage.plugins.5634303718.6180716911.7582995238.1039461003.6322703811",
153+
# noqa:E501
151154
}
152155
),
153156
)
@@ -300,7 +303,7 @@ def test_build_django_uncached(benchmark):
300303
301304
In this benchmark, the cache is turned off.
302305
"""
303-
_run_benchmark(benchmark, grimp.build_graph, "django", cache_dir=None)
306+
benchmark(grimp.build_graph, "django", cache_dir=None)
304307

305308

306309
def test_build_django_from_cache_no_misses(benchmark):
@@ -312,7 +315,7 @@ def test_build_django_from_cache_no_misses(benchmark):
312315
# Populate the cache first, before beginning the benchmark.
313316
grimp.build_graph("django")
314317

315-
_run_benchmark(benchmark, grimp.build_graph, "django")
318+
benchmark(grimp.build_graph, "django")
316319

317320

318321
@pytest.mark.parametrize(
@@ -349,7 +352,7 @@ def test_build_django_from_cache_a_few_misses(benchmark, number_of_misses):
349352
# Populate the cache.
350353
grimp.build_graph("django")
351354

352-
_run_benchmark(benchmark, grimp.build_graph, "django")
355+
benchmark(grimp.build_graph, "django")
353356

354357
# Clean up.
355358
[module.unlink() for module in extra_modules]
@@ -371,8 +374,7 @@ def _remove_package_dependencies(graph, package_dependencies):
371374
return graph
372375

373376
def test_top_level_large_graph_violated(self, large_graph, benchmark):
374-
result = _run_benchmark(
375-
benchmark,
377+
result = benchmark(
376378
large_graph.find_illegal_dependencies_for_layers,
377379
layers=TOP_LEVEL_LAYERS,
378380
containers=("mypackage",),
@@ -383,59 +385,47 @@ def test_top_level_large_graph_kept(self, large_graph, benchmark):
383385
large_graph = self._remove_package_dependencies(
384386
large_graph, TOP_LEVEL_PACKAGE_DEPENDENCIES
385387
)
386-
result = _run_benchmark(
387-
benchmark,
388+
result = benchmark(
388389
large_graph.find_illegal_dependencies_for_layers,
389390
layers=TOP_LEVEL_LAYERS,
390391
containers=("mypackage",),
391392
)
392393
assert result == set()
393394

394395
def test_deep_layers_large_graph_violated(self, large_graph, benchmark):
395-
result = _run_benchmark(
396-
benchmark, large_graph.find_illegal_dependencies_for_layers, layers=DEEP_LAYERS
397-
)
396+
result = benchmark(large_graph.find_illegal_dependencies_for_layers, layers=DEEP_LAYERS)
398397
assert result == DEEP_LAYER_PACKAGE_DEPENDENCIES
399398

400399
def test_deep_layers_large_graph_kept(self, large_graph, benchmark):
401400
large_graph = self._remove_package_dependencies(
402401
large_graph, DEEP_LAYER_PACKAGE_DEPENDENCIES
403402
)
404-
result = _run_benchmark(
405-
benchmark, large_graph.find_illegal_dependencies_for_layers, layers=DEEP_LAYERS
406-
)
403+
result = benchmark(large_graph.find_illegal_dependencies_for_layers, layers=DEEP_LAYERS)
407404
assert result == set()
408405

409406

410407
def test_find_descendants(large_graph, benchmark):
411-
result = _run_benchmark(benchmark, large_graph.find_descendants, "mypackage")
408+
result = benchmark(large_graph.find_descendants, "mypackage")
412409
assert len(result) == 28222
413410

414411

415412
def test_find_downstream_modules(large_graph, benchmark):
416-
result = _run_benchmark(
417-
benchmark, large_graph.find_downstream_modules, DEEP_LAYERS[0], as_package=True
418-
)
413+
result = benchmark(large_graph.find_downstream_modules, DEEP_LAYERS[0], as_package=True)
419414
assert len(result) == 80
420415

421416

422417
def test_find_upstream_modules(large_graph, benchmark):
423-
result = _run_benchmark(
424-
benchmark, large_graph.find_upstream_modules, DEEP_LAYERS[0], as_package=True
425-
)
418+
result = benchmark(large_graph.find_upstream_modules, DEEP_LAYERS[0], as_package=True)
426419
assert len(result) == 2159
427420

428421

429422
class TestFindShortestChain:
430423
def test_chain_found(self, large_graph, benchmark):
431-
result = _run_benchmark(
432-
benchmark, large_graph.find_shortest_chain, DEEP_LAYERS[0], DEEP_LAYERS[1]
433-
)
424+
result = benchmark(large_graph.find_shortest_chain, DEEP_LAYERS[0], DEEP_LAYERS[1])
434425
assert result is not None
435426

436427
def test_no_chain(self, large_graph, benchmark):
437-
result = _run_benchmark(
438-
benchmark,
428+
result = benchmark(
439429
large_graph.find_shortest_chain,
440430
DEEP_LAYERS[0],
441431
"mypackage.data.vendors.4053192739.6373932949",
@@ -445,8 +435,7 @@ def test_no_chain(self, large_graph, benchmark):
445435

446436
class TestFindShortestChains:
447437
def test_chains_found(self, large_graph, benchmark):
448-
result = _run_benchmark(
449-
benchmark,
438+
result = benchmark(
450439
large_graph.find_shortest_chains,
451440
DEEP_LAYERS[0],
452441
DEEP_LAYERS[1],
@@ -455,8 +444,7 @@ def test_chains_found(self, large_graph, benchmark):
455444
assert len(result) > 0
456445

457446
def test_no_chains(self, large_graph, benchmark):
458-
result = _run_benchmark(
459-
benchmark,
447+
result = benchmark(
460448
large_graph.find_shortest_chains,
461449
DEEP_LAYERS[0],
462450
"mypackage.data.vendors.4053192739.6373932949",
@@ -489,8 +477,7 @@ def test_chains_found_sparse_imports(self, benchmark):
489477
graph.add_import(importer=f"a.m{i}", imported=f"b.m{i}")
490478
graph.add_import(importer=f"b.m{i}", imported=f"c.m{i}")
491479

492-
result = _run_benchmark(
493-
benchmark,
480+
result = benchmark(
494481
graph.find_shortest_chains,
495482
"a",
496483
"c",
@@ -500,7 +487,7 @@ def test_chains_found_sparse_imports(self, benchmark):
500487

501488

502489
def test_copy_graph(large_graph, benchmark):
503-
_run_benchmark(benchmark, lambda: deepcopy(large_graph))
490+
benchmark(lambda: deepcopy(large_graph))
504491

505492

506493
def test_modules_property_first_access(large_graph, benchmark):
@@ -512,7 +499,7 @@ def f():
512499
# Accessing the modules property is what we're benchmarking.
513500
_ = large_graph.modules
514501

515-
_run_benchmark(benchmark, f)
502+
benchmark(f)
516503

517504

518505
def test_modules_property_many_accesses(large_graph, benchmark):
@@ -525,7 +512,7 @@ def f():
525512
for i in range(1000):
526513
_ = large_graph.modules
527514

528-
_run_benchmark(benchmark, f)
515+
benchmark(f)
529516

530517

531518
def test_get_import_details(benchmark):
@@ -540,19 +527,16 @@ def f():
540527
for i in range(iterations):
541528
graph.get_import_details(importer=f"blue_{i}", imported=f"green_{i}")
542529

543-
_run_benchmark(benchmark, f)
530+
benchmark(f)
544531

545532

546533
def test_find_matching_modules(benchmark, large_graph):
547-
matching_modules = _run_benchmark(
548-
benchmark, lambda: large_graph.find_matching_modules("mypackage.domain.**")
549-
)
534+
matching_modules = benchmark(lambda: large_graph.find_matching_modules("mypackage.domain.**"))
550535
assert len(matching_modules) == 2519
551536

552537

553538
def test_find_matching_direct_imports(benchmark, large_graph):
554-
matching_imports = _run_benchmark(
555-
benchmark,
539+
matching_imports = benchmark(
556540
lambda: large_graph.find_matching_direct_imports(
557541
"mypackage.domain.** -> mypackage.data.**"
558542
),

0 commit comments

Comments
 (0)