caellion-python-commons: tests/test_codeanalysis_reports.py Source File

caellion-python-commons

test_codeanalysis_reports.py
Go to the documentation of this file.
1 # test framework
2 import unittest
3 import pytest
4
5 # package
6 from caellion.pycommons.codeanalysis.reports import ReportBuilder as rpt # noqa
7
8
9 # test cases
10 class TestCodeAnalysisReportsReportBuilder:
11
12 maxDiff = None
13
14 # exceptions
15 def test_cannot_init_twice(self):
16 with pytest.raises(ValueError):
17 RB = rpt()
18 RB.__init__()
19
20 # empty report
21 def test_build_empty_report(self):
22 RB = rpt()
23 report = RB.generateReport()
24 assert (
25 report
26 == '{"_class": "io.jenkins.plugins.analysis.core.restapi.ReportApi", "issues": [], "size": 0}'
27 )
28
29 # basic report
30 def test_build_basic_report(self):
31 RB = rpt()
32 RB.addIssue("some/file/path.py", "LOW", "test")
33 report = RB.generateReport()
34 assert (
35 report
36 == '{"_class": "io.jenkins.plugins.analysis.core.restapi.ReportApi", "issues": [{"fileName": "some/file/path.py", "directory": "some/file/", "severity": "LOW", "message": "test"}], "size": 1}'
37 )
38
39 # basic report
40 def test_build_basic_report_invalid_path_fails(self):
41 with pytest.raises(Exception):
42 RB = rpt()
43 RB.addIssue("/some/file/path/", "LOW", "test")
44 report = RB.generateReport() # noqa: F841
45
46 # basic report
47 def test_build_basic_report_none_path_fails(self):
48 with pytest.raises(Exception):
49 RB = rpt()
50 RB.addIssue(None, "LOW", "test")
51 report = RB.generateReport() # noqa: F841
52
53 # basic report
54 def test_build_basic_report_empty_path_fails(self):
55 with pytest.raises(Exception):
56 RB = rpt()
57 RB.addIssue("", "LOW", "test")
58 report = RB.generateReport() # noqa: F841
59
60 # basic report
61 def test_build_basic_report_unknown_severity_fails(self):
62 with pytest.raises(Exception):
63 RB = rpt()
64 RB.addIssue("a.txt", "severityunk", "test")
65 report = RB.generateReport() # noqa: F841
66
67 # basic report
68 def test_build_basic_report_none_message_fails(self):
69 with pytest.raises(Exception):
70 RB = rpt()
71 RB.addIssue("a.txt", "LOW", None)
72 report = RB.generateReport() # noqa: F841
73
74 # basic report
75 def test_build_basic_report_none_empty_message_fails(self):
76 with pytest.raises(Exception):
77 RB = rpt()
78 RB.addIssue("a.txt", "LOW", "")
79 report = RB.generateReport() # noqa: F841
80
81 # basic report
82 def test_build_full_report_lineStart(self):
83 RB = rpt()
84 RB.addIssue("some/file/path.py", "LOW", "test", lineStart=1)
85 report = RB.generateReport()
86 assert (
87 report
88 == '{"_class": "io.jenkins.plugins.analysis.core.restapi.ReportApi", "issues": [{"fileName": "some/file/path.py", "directory": "some/file/", "severity": "LOW", "message": "test", "lineStart": 1}], "size": 1}'
89 )
90
91 # basic report
92 def test_build_full_report_lineStartEnd(self):
93 RB = rpt()
94 RB.addIssue("some/file/path.py", "LOW", "test", lineStart=1, lineEnd=2)
95 report = RB.generateReport()
96 assert (
97 report
98 == '{"_class": "io.jenkins.plugins.analysis.core.restapi.ReportApi", "issues": [{"fileName": "some/file/path.py", "directory": "some/file/", "severity": "LOW", "message": "test", "lineStart": 1, "lineEnd": 2}], "size": 1}'
99 )
100
101 # basic report
102 def test_build_full_report_lineStartEnd_fails_noStart(self):
103 RB = rpt()
104 RB.addIssue("some/file/path.py", "LOW", "test", lineEnd=2)
105 report = RB.generateReport()
106 assert (
107 report
108 == '{"_class": "io.jenkins.plugins.analysis.core.restapi.ReportApi", "issues": [{"fileName": "some/file/path.py", "directory": "some/file/", "severity": "LOW", "message": "test"}], "size": 1}'
109 )
110
111 # basic report
112 def test_build_full_report_lineStartEndcolStart(self):
113 RB = rpt()
114 RB.addIssue(
115 "some/file/path.py", "LOW", "test", lineStart=1, lineEnd=2, columnStart=3
116 )
117 report = RB.generateReport()
118 assert (
119 report
120 == '{"_class": "io.jenkins.plugins.analysis.core.restapi.ReportApi", "issues": [{"fileName": "some/file/path.py", "directory": "some/file/", "severity": "LOW", "message": "test", "lineStart": 1, "lineEnd": 2, "columnStart": 3}], "size": 1}'
121 )
122
123 # basic report
124 def test_build_full_report_lineStartEndcolStartEnd(self):
125 RB = rpt()
126 RB.addIssue(
127 "some/file/path.py",
128 "LOW",
129 "test",
130 lineStart=1,
131 lineEnd=2,
132 columnStart=3,
133 columnEnd=4,
134 )
135 report = RB.generateReport()
136 assert (
137 report
138 == '{"_class": "io.jenkins.plugins.analysis.core.restapi.ReportApi", "issues": [{"fileName": "some/file/path.py", "directory": "some/file/", "severity": "LOW", "message": "test", "lineStart": 1, "lineEnd": 2, "columnStart": 3, "columnEnd": 4}], "size": 1}'
139 )
140
141 # basic report
142 def test_build_full_report_lineStartEndcolStartEnd_fails_noStart(self):
143 RB = rpt()
144 RB.addIssue(
145 "some/file/path.py", "LOW", "test", lineStart=1, lineEnd=2, columnEnd=4
146 )
147 report = RB.generateReport()
148 assert (
149 report
150 == '{"_class": "io.jenkins.plugins.analysis.core.restapi.ReportApi", "issues": [{"fileName": "some/file/path.py", "directory": "some/file/", "severity": "LOW", "message": "test", "lineStart": 1, "lineEnd": 2}], "size": 1}'
151 )
152
153 # basic report
154 def test_build_full_report_lineStartEndcolStartEndCatg(self):
155 RB = rpt()
156 RB.addIssue(
157 "some/file/path.py",
158 "LOW",
159 "test",
160 lineStart=1,
161 lineEnd=2,
162 columnStart=3,
163 columnEnd=4,
164 category="category",
165 )
166 report = RB.generateReport()
167 assert (
168 report
169 == '{"_class": "io.jenkins.plugins.analysis.core.restapi.ReportApi", "issues": [{"fileName": "some/file/path.py", "directory": "some/file/", "severity": "LOW", "message": "test", "lineStart": 1, "lineEnd": 2, "columnStart": 3, "columnEnd": 4, "category": "category"}], "size": 1}'
170 )
171
172 # basic report
173 def test_build_full_report_lineStartEndcolStartEndCatgType(self):
174 RB = rpt()
175 RB.addIssue(
176 "some/file/path.py",
177 "LOW",
178 "test",
179 lineStart=1,
180 lineEnd=2,
181 columnStart=3,
182 columnEnd=4,
183 category="category",
184 type="type",
185 )
186 report = RB.generateReport()
187 assert (
188 report
189 == '{"_class": "io.jenkins.plugins.analysis.core.restapi.ReportApi", "issues": [{"fileName": "some/file/path.py", "directory": "some/file/", "severity": "LOW", "message": "test", "lineStart": 1, "lineEnd": 2, "columnStart": 3, "columnEnd": 4, "category": "category", "type": "type"}], "size": 1}'
190 )
191
192 # basic report
193 def test_build_full_report_lineStartEndcolStartEndCatgTypeDescr(self):
194 RB = rpt()
195 RB.addIssue(
196 "some/file/path.py",
197 "LOW",
198 "test",
199 lineStart=1,
200 lineEnd=2,
201 columnStart=3,
202 columnEnd=4,
203 category="category",
204 type="type",
205 description="description",
206 )
207 report = RB.generateReport()
208 assert (
209 report
210 == '{"_class": "io.jenkins.plugins.analysis.core.restapi.ReportApi", "issues": [{"fileName": "some/file/path.py", "directory": "some/file/", "severity": "LOW", "message": "test", "lineStart": 1, "lineEnd": 2, "columnStart": 3, "columnEnd": 4, "category": "category", "type": "type", "description": "description"}], "size": 1}'
211 )
212
213 # basic report
214 def test_build_full_report_lineStartEndcolStartEndCatgTypeDescrPack(self):
215 RB = rpt()
216 RB.addIssue(
217 "some/file/path.py",
218 "LOW",
219 "test",
220 lineStart=1,
221 lineEnd=2,
222 columnStart=3,
223 columnEnd=4,
224 category="category",
225 type="type",
226 description="description",
227 packageName="package",
228 )
229 report = RB.generateReport()
230 assert (
231 report
232 == '{"_class": "io.jenkins.plugins.analysis.core.restapi.ReportApi", "issues": [{"fileName": "some/file/path.py", "directory": "some/file/", "severity": "LOW", "message": "test", "lineStart": 1, "lineEnd": 2, "columnStart": 3, "columnEnd": 4, "category": "category", "type": "type", "description": "description", "packageName": "package"}], "size": 1}'
233 )
234
235 # basic report
236 def test_build_full_report_lineStartEndcolStartEndCatgTypeDescrPackMod(self):
237 RB = rpt()
238 RB.addIssue(
239 "some/file/path.py",
240 "LOW",
241 "test",
242 lineStart=1,
243 lineEnd=2,
244 columnStart=3,
245 columnEnd=4,
246 category="category",
247 type="type",
248 description="description",
249 packageName="package",
250 moduleName="module",
251 )
252 report = RB.generateReport()
253 assert (
254 report
255 == '{"_class": "io.jenkins.plugins.analysis.core.restapi.ReportApi", "issues": [{"fileName": "some/file/path.py", "directory": "some/file/", "severity": "LOW", "message": "test", "lineStart": 1, "lineEnd": 2, "columnStart": 3, "columnEnd": 4, "category": "category", "type": "type", "description": "description", "packageName": "package", "moduleName": "module"}], "size": 1}'
256 )
257
258 # basic report
259 def test_build_full_report(self):
260 RB = rpt()
261 RB.addIssue(
262 "some/file/path.py",
263 "LOW",
264 "test",
265 lineStart=1,
266 lineEnd=2,
267 columnStart=3,
268 columnEnd=4,
269 category="category",
270 type="type",
271 description="description",
272 packageName="package",
273 moduleName="module",
274 additionalProperties="adds",
275 )
276 report = RB.generateReport()
277 assert (
278 report
279 == '{"_class": "io.jenkins.plugins.analysis.core.restapi.ReportApi", "issues": [{"fileName": "some/file/path.py", "directory": "some/file/", "severity": "LOW", "message": "test", "lineStart": 1, "lineEnd": 2, "columnStart": 3, "columnEnd": 4, "category": "category", "type": "type", "description": "description", "packageName": "package", "moduleName": "module", "additionalProperties": "adds"}], "size": 1}'
280 )
281
282
283 if __name__ == "__main__":
284 unittest.main()
tests.test_codeanalysis_reports.TestCodeAnalysisReportsReportBuilder
Definition: test_codeanalysis_reports.py:10
tests.test_codeanalysis_reports.TestCodeAnalysisReportsReportBuilder.test_build_basic_report_empty_path_fails
def test_build_basic_report_empty_path_fails(self)
Definition: test_codeanalysis_reports.py:54
tests.test_codeanalysis_reports.TestCodeAnalysisReportsReportBuilder.test_build_basic_report_none_path_fails
def test_build_basic_report_none_path_fails(self)
Definition: test_codeanalysis_reports.py:47
tests.test_codeanalysis_reports.TestCodeAnalysisReportsReportBuilder.test_build_basic_report_unknown_severity_fails
def test_build_basic_report_unknown_severity_fails(self)
Definition: test_codeanalysis_reports.py:61
tests.test_codeanalysis_reports.TestCodeAnalysisReportsReportBuilder.test_build_full_report_lineStartEnd_fails_noStart
def test_build_full_report_lineStartEnd_fails_noStart(self)
Definition: test_codeanalysis_reports.py:102
tests.test_codeanalysis_reports.TestCodeAnalysisReportsReportBuilder.test_build_full_report_lineStartEnd
def test_build_full_report_lineStartEnd(self)
Definition: test_codeanalysis_reports.py:92
tests.test_codeanalysis_reports.TestCodeAnalysisReportsReportBuilder.test_build_full_report_lineStartEndcolStartEndCatgType
def test_build_full_report_lineStartEndcolStartEndCatgType(self)
Definition: test_codeanalysis_reports.py:173
tests.test_codeanalysis_reports.TestCodeAnalysisReportsReportBuilder.test_build_full_report_lineStartEndcolStartEndCatg
def test_build_full_report_lineStartEndcolStartEndCatg(self)
Definition: test_codeanalysis_reports.py:154
tests.test_codeanalysis_reports.TestCodeAnalysisReportsReportBuilder.test_build_full_report_lineStartEndcolStartEndCatgTypeDescr
def test_build_full_report_lineStartEndcolStartEndCatgTypeDescr(self)
Definition: test_codeanalysis_reports.py:193
tests.test_codeanalysis_reports.TestCodeAnalysisReportsReportBuilder.test_build_basic_report
def test_build_basic_report(self)
Definition: test_codeanalysis_reports.py:30
tests.test_codeanalysis_reports.TestCodeAnalysisReportsReportBuilder.test_build_full_report
def test_build_full_report(self)
Definition: test_codeanalysis_reports.py:259
tests.test_codeanalysis_reports.TestCodeAnalysisReportsReportBuilder.test_build_full_report_lineStart
def test_build_full_report_lineStart(self)
Definition: test_codeanalysis_reports.py:82
tests.test_codeanalysis_reports.TestCodeAnalysisReportsReportBuilder.test_build_full_report_lineStartEndcolStartEndCatgTypeDescrPack
def test_build_full_report_lineStartEndcolStartEndCatgTypeDescrPack(self)
Definition: test_codeanalysis_reports.py:214
tests.test_codeanalysis_reports.TestCodeAnalysisReportsReportBuilder.test_build_full_report_lineStartEndcolStartEnd_fails_noStart
def test_build_full_report_lineStartEndcolStartEnd_fails_noStart(self)
Definition: test_codeanalysis_reports.py:142
tests.test_codeanalysis_reports.TestCodeAnalysisReportsReportBuilder.test_build_empty_report
def test_build_empty_report(self)
Definition: test_codeanalysis_reports.py:21
tests.test_codeanalysis_reports.TestCodeAnalysisReportsReportBuilder.test_build_full_report_lineStartEndcolStartEndCatgTypeDescrPackMod
def test_build_full_report_lineStartEndcolStartEndCatgTypeDescrPackMod(self)
Definition: test_codeanalysis_reports.py:236
tests.test_codeanalysis_reports.TestCodeAnalysisReportsReportBuilder.test_build_full_report_lineStartEndcolStart
def test_build_full_report_lineStartEndcolStart(self)
Definition: test_codeanalysis_reports.py:112
tests.test_codeanalysis_reports.TestCodeAnalysisReportsReportBuilder.test_build_basic_report_invalid_path_fails
def test_build_basic_report_invalid_path_fails(self)
Definition: test_codeanalysis_reports.py:40
tests.test_codeanalysis_reports.TestCodeAnalysisReportsReportBuilder.test_build_full_report_lineStartEndcolStartEnd
def test_build_full_report_lineStartEndcolStartEnd(self)
Definition: test_codeanalysis_reports.py:124
tests.test_codeanalysis_reports.TestCodeAnalysisReportsReportBuilder.test_build_basic_report_none_empty_message_fails
def test_build_basic_report_none_empty_message_fails(self)
Definition: test_codeanalysis_reports.py:75
tests.test_codeanalysis_reports.TestCodeAnalysisReportsReportBuilder.test_cannot_init_twice
def test_cannot_init_twice(self)
Definition: test_codeanalysis_reports.py:15
tests.test_codeanalysis_reports.TestCodeAnalysisReportsReportBuilder.test_build_basic_report_none_message_fails
def test_build_basic_report_none_message_fails(self)
Definition: test_codeanalysis_reports.py:68
caellion.pycommons.codeanalysis.reports
This module provides utlilities related to creating Jenkins' warnings-ng-plugin-compatible reports fr...
Definition: reports.py:1