/
test_benchmark.py
63 lines (44 loc) · 1.41 KB
/
test_benchmark.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
from __future__ import (
absolute_import,
division,
print_function,
unicode_literals,
)
import os
import sys
import unittest
import pytest
# Since extension imports dlint we cannot add it to the module or else we'll
# have circular imports. Thus we must come up with some tricks to import it
sys.path.append(
os.path.join(
os.path.dirname(os.path.dirname(os.path.dirname(__file__))),
"dlint"
)
)
import extension # noqa: E402
def get_single_linter_extension(linter):
class SingleLinterExtention(extension.Flake8Extension):
@classmethod
def get_linter_classes(cls):
return [linter]
return SingleLinterExtention
def test_benchmark_run(benchmark_py_file, benchmark):
ext = extension.Flake8Extension(benchmark_py_file, "unused")
benchmark(lambda: list(ext.run()))
assert ext
@pytest.mark.parametrize(
'linter',
sorted(extension.dlint.linters.ALL, key=lambda l: l._code),
ids=lambda l: "{}-{}".format(l._code, l.__name__)
)
def test_benchmark_individual(benchmark_py_file, benchmark_group_base_class, benchmark, linter):
if benchmark_group_base_class:
benchmark.group = str(linter.__bases__)
ext_class = get_single_linter_extension(linter)
ext = ext_class(benchmark_py_file, "unused")
benchmark(lambda: list(ext.run()))
assert ext
if __name__ == "__main__":
unittest.main()