Skip to content

Commit 157df02

Browse files
jana-selvatkilias
andauthored
#67: Extend unit tests for parameter description (#71)
Co-authored-by: Torsten Kilias <[email protected]>
1 parent 03aa422 commit 157df02

File tree

3 files changed

+256
-2
lines changed

3 files changed

+256
-2
lines changed

doc/changes/unreleased.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
## Internal
44

55
* #68 Update to poetry 2.1.2 and exasol-toolbox 1.1.0
6-
* Update transitive dependencies
6+
* Update transitive dependencies
7+
* #67 Extend unit test to contain test scenarios with different values for the parameter description

exasol/error/_parse.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,11 @@ def _validate_parameter_values(self, parameter_node: ast.Dict, file: str) -> boo
307307
Checks if value of ast dictionary are of expected type.
308308
If the values are of expected type, the method returns True, otherwise False.
309309
"""
310-
311310
ret_val = True
312311
for value in parameter_node.values:
313312
if isinstance(value, ast.Call):
313+
if len(value.args) < 2:
314+
value.args.append(ast.Constant(value=None))
314315
description = value.args[1]
315316
if not self._check_node_type(
316317
ast.Constant, description, "description", file

test/unit/cli_test.py

Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,96 @@
4949
)
5050
],
5151
),
52+
(
53+
cleandoc(
54+
"""
55+
from exasol import error
56+
57+
error1 = error.ExaError(
58+
"E-TEST-1",
59+
"this is an error",
60+
["no mitigation available"],
61+
{"param": error.Parameter("value", "")},
62+
)
63+
"""
64+
),
65+
[
66+
ErrorCodeDetails(
67+
identifier="E-TEST-1",
68+
message="this is an error",
69+
messagePlaceholders=[
70+
Placeholder(placeholder="param", description="")
71+
],
72+
description=None,
73+
internalDescription=None,
74+
potentialCauses=None,
75+
mitigations=["no mitigation available"],
76+
sourceFile="<Unknown>",
77+
sourceLine=3,
78+
contextHash=None,
79+
)
80+
],
81+
),
82+
(
83+
cleandoc(
84+
"""
85+
from exasol import error
86+
87+
error1 = error.ExaError(
88+
"E-TEST-1",
89+
"this is an error",
90+
["no mitigation available"],
91+
{"param": error.Parameter("value", None)},
92+
)
93+
"""
94+
),
95+
[
96+
ErrorCodeDetails(
97+
identifier="E-TEST-1",
98+
message="this is an error",
99+
messagePlaceholders=[
100+
Placeholder(placeholder="param", description="")
101+
],
102+
description=None,
103+
internalDescription=None,
104+
potentialCauses=None,
105+
mitigations=["no mitigation available"],
106+
sourceFile="<Unknown>",
107+
sourceLine=3,
108+
contextHash=None,
109+
)
110+
],
111+
),
112+
(
113+
cleandoc(
114+
"""
115+
from exasol import error
116+
117+
error1 = error.ExaError(
118+
"E-TEST-1",
119+
"this is an error",
120+
["no mitigation available"],
121+
{"param": error.Parameter("value")},
122+
)
123+
"""
124+
),
125+
[
126+
ErrorCodeDetails(
127+
identifier="E-TEST-1",
128+
message="this is an error",
129+
messagePlaceholders=[
130+
Placeholder(placeholder="param", description="")
131+
],
132+
description=None,
133+
internalDescription=None,
134+
potentialCauses=None,
135+
mitigations=["no mitigation available"],
136+
sourceFile="<Unknown>",
137+
sourceLine=3,
138+
contextHash=None,
139+
)
140+
],
141+
),
52142
],
53143
)
54144
def test_ErrorCollector_error_definitions(src, expected):
@@ -211,6 +301,96 @@ def test_ErrorCollector_error_definitions(src, expected):
211301
)
212302
],
213303
),
304+
(
305+
cleandoc(
306+
"""
307+
from exasol import error
308+
from exasol.error import Parameter
309+
310+
var = input("description: ")
311+
312+
error1 = error.ExaError(
313+
"E-TEST-1",
314+
var,
315+
["mitigations"],
316+
{"param": Parameter("value", "")},
317+
)
318+
"""
319+
),
320+
[
321+
Error(
322+
code=INVALID_ERROR_CODE_DEFINITION.identifier,
323+
message=INVALID_ERROR_CODE_DEFINITION.message,
324+
mitigations=INVALID_ERROR_CODE_DEFINITION.mitigations,
325+
parameters={
326+
"error_element": "message",
327+
"file": "<Unknown>",
328+
"line": "8",
329+
"defined_type": f"<class '{AST_NAME_CLASS}'>",
330+
},
331+
)
332+
],
333+
),
334+
(
335+
cleandoc(
336+
"""
337+
from exasol import error
338+
from exasol.error import Parameter
339+
340+
var = input("description: ")
341+
342+
error1 = error.ExaError(
343+
"E-TEST-1",
344+
var,
345+
["mitigations"],
346+
{"param": Parameter("value", None)},
347+
)
348+
"""
349+
),
350+
[
351+
Error(
352+
code=INVALID_ERROR_CODE_DEFINITION.identifier,
353+
message=INVALID_ERROR_CODE_DEFINITION.message,
354+
mitigations=INVALID_ERROR_CODE_DEFINITION.mitigations,
355+
parameters={
356+
"error_element": "message",
357+
"file": "<Unknown>",
358+
"line": "8",
359+
"defined_type": f"<class '{AST_NAME_CLASS}'>",
360+
},
361+
)
362+
],
363+
),
364+
(
365+
cleandoc(
366+
"""
367+
from exasol import error
368+
from exasol.error import Parameter
369+
370+
var = input("description: ")
371+
372+
error1 = error.ExaError(
373+
"E-TEST-1",
374+
var,
375+
["mitigations"],
376+
{"param": Parameter("value")},
377+
)
378+
"""
379+
),
380+
[
381+
Error(
382+
code=INVALID_ERROR_CODE_DEFINITION.identifier,
383+
message=INVALID_ERROR_CODE_DEFINITION.message,
384+
mitigations=INVALID_ERROR_CODE_DEFINITION.mitigations,
385+
parameters={
386+
"error_element": "message",
387+
"file": "<Unknown>",
388+
"line": "8",
389+
"defined_type": f"<class '{AST_NAME_CLASS}'>",
390+
},
391+
)
392+
],
393+
),
214394
],
215395
)
216396
def test_ErrorCollector_errors(src, expected):
@@ -256,6 +436,78 @@ def test_ErrorCollector_errors(src, expected):
256436
),
257437
[],
258438
),
439+
(
440+
cleandoc(
441+
"""
442+
from exasol import error
443+
from exasol.error import Parameter
444+
445+
var = input("description: ")
446+
447+
error1 = error.ExaError(
448+
"E-TEST-1",
449+
"this is an error",
450+
["no mitigation available"],
451+
{"param": Parameter("value", "description")},
452+
)
453+
"""
454+
),
455+
[],
456+
),
457+
(
458+
cleandoc(
459+
"""
460+
from exasol import error
461+
from exasol.error import Parameter
462+
463+
var = input("description: ")
464+
465+
error1 = error.ExaError(
466+
"E-TEST-1",
467+
"this is an error",
468+
["no mitigation available"],
469+
{"param": Parameter("value", "")},
470+
)
471+
"""
472+
),
473+
[],
474+
),
475+
(
476+
cleandoc(
477+
"""
478+
from exasol import error
479+
from exasol.error import Parameter
480+
481+
var = input("description: ")
482+
483+
error1 = error.ExaError(
484+
"E-TEST-1",
485+
"this is an error",
486+
["no mitigation available"],
487+
{"param": Parameter("value", None)},
488+
)
489+
"""
490+
),
491+
[],
492+
),
493+
(
494+
cleandoc(
495+
"""
496+
from exasol import error
497+
from exasol.error import Parameter
498+
499+
var = input("description: ")
500+
501+
error1 = error.ExaError(
502+
"E-TEST-1",
503+
"this is an error",
504+
["no mitigation available"],
505+
{"param": Parameter("value")},
506+
)
507+
"""
508+
),
509+
[],
510+
),
259511
],
260512
)
261513
def test_ErrorCollector_warnings(src, expected):

0 commit comments

Comments
 (0)