From dafd6f4e5e8cfec194db4c036edb99e9949abb97 Mon Sep 17 00:00:00 2001 From: Janaarthanan Selvarajan Date: Thu, 4 Sep 2025 08:37:00 +0000 Subject: [PATCH 1/3] extend unit test #67 --- doc/changes/unreleased.md | 3 +- exasol/error/_parse.py | 3 +- test/unit/cli_test.py | 253 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 257 insertions(+), 2 deletions(-) diff --git a/doc/changes/unreleased.md b/doc/changes/unreleased.md index ea1596f..b8af8b6 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 of 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..e173782 100644 --- a/test/unit/cli_test.py +++ b/test/unit/cli_test.py @@ -49,6 +49,97 @@ ) ], ), + ( + 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 +302,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 +437,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): From a1973bb79b79a6629560419867a31be00aa90087 Mon Sep 17 00:00:00 2001 From: Janaarthanan Selvarajan Date: Thu, 4 Sep 2025 08:41:32 +0000 Subject: [PATCH 2/3] poetry run nox -s project:format --- test/unit/cli_test.py | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/test/unit/cli_test.py b/test/unit/cli_test.py index e173782..57d4016 100644 --- a/test/unit/cli_test.py +++ b/test/unit/cli_test.py @@ -49,7 +49,7 @@ ) ], ), - ( + ( cleandoc( """ from exasol import error @@ -139,7 +139,6 @@ ) ], ), - ], ) def test_ErrorCollector_error_definitions(src, expected): @@ -362,7 +361,7 @@ def test_ErrorCollector_error_definitions(src, expected): ) ], ), -( + ( cleandoc( """ from exasol import error @@ -438,8 +437,8 @@ def test_ErrorCollector_errors(src, expected): [], ), ( - cleandoc( - """ + cleandoc( + """ from exasol import error from exasol.error import Parameter @@ -452,12 +451,12 @@ def test_ErrorCollector_errors(src, expected): {"param": Parameter("value", "description")}, ) """ - ), - [], + ), + [], ), ( - cleandoc( - """ + cleandoc( + """ from exasol import error from exasol.error import Parameter @@ -470,12 +469,12 @@ def test_ErrorCollector_errors(src, expected): {"param": Parameter("value", "")}, ) """ - ), - [], + ), + [], ), ( - cleandoc( - """ + cleandoc( + """ from exasol import error from exasol.error import Parameter @@ -488,12 +487,12 @@ def test_ErrorCollector_errors(src, expected): {"param": Parameter("value", None)}, ) """ - ), - [], + ), + [], ), ( - cleandoc( - """ + cleandoc( + """ from exasol import error from exasol.error import Parameter @@ -506,8 +505,8 @@ def test_ErrorCollector_errors(src, expected): {"param": Parameter("value")}, ) """ - ), - [], + ), + [], ), ], ) From 8578900a56701045fbecc2bae364cead7e2d75f9 Mon Sep 17 00:00:00 2001 From: Janaarthanan Selvarajan Date: Mon, 8 Sep 2025 13:34:28 +0530 Subject: [PATCH 3/3] Apply suggestion from @tkilias Co-authored-by: Torsten Kilias --- doc/changes/unreleased.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/changes/unreleased.md b/doc/changes/unreleased.md index b8af8b6..0b80c8a 100644 --- a/doc/changes/unreleased.md +++ b/doc/changes/unreleased.md @@ -4,4 +4,4 @@ * #68 Update to poetry 2.1.2 and exasol-toolbox 1.1.0 * Update transitive dependencies -* #67 Extend unit test to contain test scenarios with different values of description \ No newline at end of file +* #67 Extend unit test to contain test scenarios with different values for the parameter description \ No newline at end of file