diff --git a/doc/changes/unreleased.md b/doc/changes/unreleased.md index ea1596f..0b80c8a 100644 --- a/doc/changes/unreleased.md +++ b/doc/changes/unreleased.md @@ -3,4 +3,5 @@ ## Internal * #68 Update to poetry 2.1.2 and exasol-toolbox 1.1.0 -* Update transitive dependencies \ No newline at end of file +* Update transitive dependencies +* #67 Extend unit test to contain test scenarios with different values for the parameter description \ No newline at end of file diff --git a/exasol/error/_parse.py b/exasol/error/_parse.py index c745574..b541421 100644 --- a/exasol/error/_parse.py +++ b/exasol/error/_parse.py @@ -307,10 +307,11 @@ def _validate_parameter_values(self, parameter_node: ast.Dict, file: str) -> boo Checks if value of ast dictionary are of expected type. If the values are of expected type, the method returns True, otherwise False. """ - ret_val = True for value in parameter_node.values: if isinstance(value, ast.Call): + if len(value.args) < 2: + value.args.append(ast.Constant(value=None)) description = value.args[1] if not self._check_node_type( ast.Constant, description, "description", file diff --git a/test/unit/cli_test.py b/test/unit/cli_test.py index 3254e04..57d4016 100644 --- a/test/unit/cli_test.py +++ b/test/unit/cli_test.py @@ -49,6 +49,96 @@ ) ], ), + ( + cleandoc( + """ + from exasol import error + + error1 = error.ExaError( + "E-TEST-1", + "this is an error", + ["no mitigation available"], + {"param": error.Parameter("value", "")}, + ) + """ + ), + [ + ErrorCodeDetails( + identifier="E-TEST-1", + message="this is an error", + messagePlaceholders=[ + Placeholder(placeholder="param", description="") + ], + description=None, + internalDescription=None, + potentialCauses=None, + mitigations=["no mitigation available"], + sourceFile="", + sourceLine=3, + contextHash=None, + ) + ], + ), + ( + cleandoc( + """ + from exasol import error + + error1 = error.ExaError( + "E-TEST-1", + "this is an error", + ["no mitigation available"], + {"param": error.Parameter("value", None)}, + ) + """ + ), + [ + ErrorCodeDetails( + identifier="E-TEST-1", + message="this is an error", + messagePlaceholders=[ + Placeholder(placeholder="param", description="") + ], + description=None, + internalDescription=None, + potentialCauses=None, + mitigations=["no mitigation available"], + sourceFile="", + sourceLine=3, + contextHash=None, + ) + ], + ), + ( + cleandoc( + """ + from exasol import error + + error1 = error.ExaError( + "E-TEST-1", + "this is an error", + ["no mitigation available"], + {"param": error.Parameter("value")}, + ) + """ + ), + [ + ErrorCodeDetails( + identifier="E-TEST-1", + message="this is an error", + messagePlaceholders=[ + Placeholder(placeholder="param", description="") + ], + description=None, + internalDescription=None, + potentialCauses=None, + mitigations=["no mitigation available"], + sourceFile="", + sourceLine=3, + contextHash=None, + ) + ], + ), ], ) def test_ErrorCollector_error_definitions(src, expected): @@ -211,6 +301,96 @@ def test_ErrorCollector_error_definitions(src, expected): ) ], ), + ( + cleandoc( + """ + from exasol import error + from exasol.error import Parameter + + var = input("description: ") + + error1 = error.ExaError( + "E-TEST-1", + var, + ["mitigations"], + {"param": Parameter("value", "")}, + ) + """ + ), + [ + Error( + code=INVALID_ERROR_CODE_DEFINITION.identifier, + message=INVALID_ERROR_CODE_DEFINITION.message, + mitigations=INVALID_ERROR_CODE_DEFINITION.mitigations, + parameters={ + "error_element": "message", + "file": "", + "line": "8", + "defined_type": f"", + }, + ) + ], + ), + ( + cleandoc( + """ + from exasol import error + from exasol.error import Parameter + + var = input("description: ") + + error1 = error.ExaError( + "E-TEST-1", + var, + ["mitigations"], + {"param": Parameter("value", None)}, + ) + """ + ), + [ + Error( + code=INVALID_ERROR_CODE_DEFINITION.identifier, + message=INVALID_ERROR_CODE_DEFINITION.message, + mitigations=INVALID_ERROR_CODE_DEFINITION.mitigations, + parameters={ + "error_element": "message", + "file": "", + "line": "8", + "defined_type": f"", + }, + ) + ], + ), + ( + cleandoc( + """ + from exasol import error + from exasol.error import Parameter + + var = input("description: ") + + error1 = error.ExaError( + "E-TEST-1", + var, + ["mitigations"], + {"param": Parameter("value")}, + ) + """ + ), + [ + Error( + code=INVALID_ERROR_CODE_DEFINITION.identifier, + message=INVALID_ERROR_CODE_DEFINITION.message, + mitigations=INVALID_ERROR_CODE_DEFINITION.mitigations, + parameters={ + "error_element": "message", + "file": "", + "line": "8", + "defined_type": f"", + }, + ) + ], + ), ], ) def test_ErrorCollector_errors(src, expected): @@ -256,6 +436,78 @@ def test_ErrorCollector_errors(src, expected): ), [], ), + ( + 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"], + {"param": Parameter("value", "description")}, + ) + """ + ), + [], + ), + ( + 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"], + {"param": Parameter("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"], + {"param": Parameter("value", None)}, + ) + """ + ), + [], + ), + ( + 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"], + {"param": Parameter("value")}, + ) + """ + ), + [], + ), ], ) def test_ErrorCollector_warnings(src, expected):