Skip to content

Commit

Permalink
Fix support for single mitigation (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicoretti authored Jun 6, 2024
1 parent 7934de8 commit bb514e1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
9 changes: 7 additions & 2 deletions exasol/error/_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,11 @@ def normalize(params):
description=None,
internalDescription=None,
potentialCauses=None,
mitigations=[m.value for m in mitigations.elts]
mitigations=(
[m.value for m in mitigations.elts]
if isinstance(mitigations, ast.List)
else [mitigations.value]
)
if not isinstance(mitigations, str)
else [mitigations],
sourceFile=self._filename,
Expand Down Expand Up @@ -229,7 +233,8 @@ def parse_file(
else stack.enter_context(open(file, "r"))
)
root_node = ast.parse(f.read())
collector = ErrorCollector(root_node, f.name)
name = f.name if hasattr(f, 'name') else f'<{f.__class__.__name__}>'
collector = ErrorCollector(root_node, name)
collector.collect()

return collector.error_definitions, collector.warnings, collector.errors
46 changes: 46 additions & 0 deletions test/unit/regression_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import io
from inspect import cleandoc

from exasol.error._parse import parse_file
from exasol.error._report import ErrorCodeDetails


# regression test for GitHub Issue #26
def test_single_mitigation():
f = io.StringIO(initial_value=cleandoc(
"""
from exasol import error
from exasol.error import Parameter
var = input("description: ")
error1 = error.ExaError(
"E-TEST-1",
"this is an error",
"no mitigation available",
{},
)
"""
))

expected_definitions = [
ErrorCodeDetails(
identifier='E-TEST-1',
message='this is an error',
messagePlaceholders=[],
description=None,
internalDescription=None,
potentialCauses=None,
mitigations=['no mitigation available'],
sourceFile='<StringIO>',
sourceLine=6,
contextHash=None),
]
expected_warnings = []
expected_errors = []

definitions, warnings, errors = parse_file(f)

assert expected_definitions == definitions
assert expected_warnings == warnings
assert expected_errors == errors

0 comments on commit bb514e1

Please sign in to comment.