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
11 
12  maxDiff = None
13 
14  # exceptions
16  with pytest.raises(ValueError):
17  RB = rpt()
18  RB.__init__()
19 
20  # empty report
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
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
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
48  with pytest.raises(Exception):
49  RB = rpt()
50  RB.addIssue(None, "LOW", "test")
51  report = RB.generateReport() # noqa: F841
52 
53  # basic report
55  with pytest.raises(Exception):
56  RB = rpt()
57  RB.addIssue("", "LOW", "test")
58  report = RB.generateReport() # noqa: F841
59 
60  # basic report
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
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
76  with pytest.raises(Exception):
77  RB = rpt()
78  RB.addIssue("a.txt", "LOW", "")
79  report = RB.generateReport() # noqa: F841
80 
81  # basic report
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
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
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
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
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
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
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
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
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
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
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
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()
This module provides utlilities related to creating Jenkins' warnings-ng-plugin-compatible reports fr...
Definition: reports.py:1