-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathreport_test.py
More file actions
156 lines (131 loc) · 5 KB
/
report_test.py
File metadata and controls
156 lines (131 loc) · 5 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
from inspect import cleandoc
import pytest
from exasol.toolbox.metrics import (
Rating,
_bandit_scoring,
_static_code_analysis,
)
@pytest.mark.parametrize(
"rating,expected",
[
(Rating.A, "A"),
(Rating.B, "B"),
(Rating.C, "C"),
(Rating.D, "D"),
(Rating.E, "E"),
(Rating.F, "F"),
(Rating.NotAvailable, "N/A"),
],
)
def test_format_rating(rating, expected):
actual = f"{rating:n}"
assert actual == expected
@pytest.mark.parametrize(
"score,expected",
[
(0.0, Rating.F),
(0.9, Rating.F),
(1.0, Rating.E),
(2.9, Rating.E),
(3.0, Rating.D),
(3.9, Rating.D),
(4.0, Rating.C),
(5.9, Rating.C),
(6.0, Rating.B),
(7.9, Rating.B),
(8.0, Rating.A),
(10.0, Rating.A),
],
)
def test_rating_from_score(score, expected):
actual = Rating.from_score(score)
assert actual == expected
def test_rating_from_score_throws_exception_for_unknown_value():
with pytest.raises(ValueError):
_ = Rating.from_score(100)
@pytest.fixture
def named_temp_file(tmp_path):
files = []
def _factory(name, content):
path = tmp_path / name
mode = "w" if not isinstance(content, bytes) else "wb"
with open(path, mode) as f:
f.write(content)
files.append(path)
return path
yield _factory
for file in files:
file.unlink()
@pytest.mark.parametrize(
"content,expected",
[
(
cleandoc("""
************* Module doc.user_guide.modules.sphinx.multiversion.conf
doc/user_guide/modules/sphinx/multiversion/conf.py:8:0: W0622: Redefining built-in 'copyright' (redefined-builtin)
doc/user_guide/modules/sphinx/multiversion/conf.py:4:0: C0103: Constant name "author" doesn't conform to UPPER_CASE naming style (invalid-name)
doc/user_guide/modules/sphinx/multiversion/conf.py:5:0: C0103: Constant name "project" doesn't conform to UPPER_CASE naming style (invalid-name)
doc/user_guide/modules/sphinx/multiversion/conf.py:6:0: C0103: Constant name "release" doesn't conform to UPPER_CASE naming style (invalid-name)
doc/user_guide/modules/sphinx/multiversion/conf.py:7:0: C0103: Constant name "version" doesn't conform to UPPER_CASE naming style (invalid-name)
doc/user_guide/modules/sphinx/multiversion/conf.py:8:12: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
doc/user_guide/modules/sphinx/multiversion/conf.py:10:0: C0103: Constant name "html_theme" doesn't conform to UPPER_CASE naming style (invalid-name)
doc/user_guide/modules/sphinx/multiversion/conf.py:19:0: C0103: Constant name "html_last_updated_fmt" doesn't conform to UPPER_CASE naming style (invalid-name)
doc/user_guide/modules/sphinx/multiversion/conf.py:20:0: C0103: Constant name "master_doc" doesn't conform to UPPER_CASE naming style (invalid-name)
doc/user_guide/modules/sphinx/multiversion/conf.py:21:0: C0103: Constant name "pygments_style" doesn't conform to UPPER_CASE naming style (invalid-name)
doc/user_guide/modules/sphinx/multiversion/conf.py:41:0: C0103: Constant name "smv_remote_whitelist" doesn't conform to UPPER_CASE naming style (invalid-name)
doc/user_guide/modules/sphinx/multiversion/conf.py:42:0: C0103: Constant name "smv_branch_whitelist" doesn't conform to UPPER_CASE naming style (invalid-name)
doc/user_guide/modules/sphinx/multiversion/conf.py:43:0: C0103: Constant name "smv_tag_whitelist" doesn't conform to UPPER_CASE naming style (invalid-name)
------------------------------------------------------------------
Your code has been rated at 7.80/10 (previous run: 7.86/10, -0.05)
"""),
Rating.B,
),
(
"",
Rating.NotAvailable,
),
],
)
def test_static_code_analysis(
named_temp_file, content, expected
): # pylint: disable=redefined-outer-name
coverage_report = named_temp_file(name=".lint.txt", content=content)
actual = _static_code_analysis(coverage_report)
assert actual == expected
def _level(char):
levels = {"H": "HIGH", "M": "MEDIUM", "L": "LOW"}
return levels[char]
def _ratings(cases):
output = []
for rating in cases:
output.append(
{
"issue_severity": _level(rating[0]),
"issue_confidence": _level(rating[1]),
}
)
return output
@pytest.mark.parametrize(
"given,expected",
[
(["HH", "LL"], 0),
(["HM", "LM", "ML"], 0),
(["HL", "MH"], 0),
([], 6),
],
)
def test_bandit_value(given, expected):
assert _bandit_scoring(_ratings(given)) == expected
@pytest.mark.parametrize(
"lower,higher",
[
(["HL"], ["MH"]),
(["MH"], ["MM"]),
(["MM"], ["ML"]),
(["HL"], ["LL"]),
(["LL"], []),
(["MH", "LL"], ["MH"]),
],
)
def test_bandit_order(lower, higher):
assert _bandit_scoring(_ratings(lower)) < _bandit_scoring(_ratings(higher))