From 05227b28eaea9fe5f4bbb6c9e1f264b94d29e9b2 Mon Sep 17 00:00:00 2001 From: mas2hc Date: Tue, 12 Sep 2023 18:28:17 +0700 Subject: [PATCH 1/4] Add error handing when implicite creation of data structure --- JsonPreprocessor/CJsonPreprocessor.py | 11 ++++++++--- JsonPreprocessor/version.py | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/JsonPreprocessor/CJsonPreprocessor.py b/JsonPreprocessor/CJsonPreprocessor.py index 41b39cec..b02d5f71 100644 --- a/JsonPreprocessor/CJsonPreprocessor.py +++ b/JsonPreprocessor/CJsonPreprocessor.py @@ -527,7 +527,7 @@ def __updateAndReplaceNestedParam(self, oJson : dict, bNested : bool = False, re Output Json object as dictionary with all variables resolved. ''' - def __checkAndCreateNewElement(sKey: str): + def __checkAndCreateNewElement(sKey: str, value): ''' This method check and create new elements if they are not exist. ''' @@ -544,7 +544,12 @@ def __checkAndCreateNewElement(sKey: str): exec(sExec) except: sExec = rootKey + " = {}" - exec(sExec, globals()) + try: + exec(sExec, globals()) + except Exception as error: + self.__reset() + errorMsg = f"Could not set variable '{sKey}' with value '{value}'! Reason: {error}" + raise Exception(errorMsg) else: continue @@ -552,7 +557,7 @@ def __jsonUpdated(k, v, oJson, bNested, keyNested = ''): if keyNested != '': del oJson[keyNested] if '[' in k: - __checkAndCreateNewElement(k) + __checkAndCreateNewElement(k, v) sExec = k + " = \"" + v + "\"" if isinstance(v, str) else k + " = " + str(v) try: exec(sExec, globals()) diff --git a/JsonPreprocessor/version.py b/JsonPreprocessor/version.py index 902a728d..912f823f 100644 --- a/JsonPreprocessor/version.py +++ b/JsonPreprocessor/version.py @@ -19,5 +19,5 @@ # Version and date of JsonPreprocessor # VERSION = "0.3.0" -VERSION_DATE = "06.09.2023" +VERSION_DATE = "12.09.2023" From 816f81919a4dcf512ccf7728da0ac5d188e8055b Mon Sep 17 00:00:00 2001 From: qth2hi Date: Wed, 13 Sep 2023 11:03:29 +0200 Subject: [PATCH 2/4] Added JPP_1000 to test the implicit creation of data structures --- test/JPP_TestUsecases.csv | 18 + test/JPP_TestUsecases.html | 744 ++++++++++++++++-- test/JPP_TestUsecases.rst | 206 ++++- test/JPP_TestUsecases.txt | 86 +- test/component_test.py | 4 +- ...test_03_PARAMETER_SUBSTITUTION_GOODCASE.py | 26 +- .../test_04_PARAMETER_SUBSTITUTION_BADCASE.py | 18 +- .../test_05_VALUE_DETECTION_GOODCASE.py | 26 +- .../test_06_VALUE_DETECTION_BADCASE.py | 58 +- .../test_07_COMPOSITE_EXPRESSIONS_GOODCASE.py | 10 +- .../test_08_COMPOSITE_EXPRESSIONS_BADCASE.py | 40 + ...t_09_COMMON_SYNTAX_VIOLATIONS_GOODCASE.py} | 4 +- ...st_10_COMMON_SYNTAX_VIOLATIONS_BADCASE.py} | 4 +- .../test_11_IMPLICIT_CREATION_GOODCASE.py | 40 + test/testconfig/TestConfig.py | 23 +- ...-test_config_implicit_creation.1.1.1.jsonp | 18 + ...pp-test_config_implicit_creation.1.1.jsonp | 20 + .../jpp-test_config_implicit_creation.1.jsonp | 19 + test/testfiles/jpp-test_config_1000.jsonp | 18 + 19 files changed, 1299 insertions(+), 83 deletions(-) create mode 100644 test/pytest/pytestfiles/test_08_COMPOSITE_EXPRESSIONS_BADCASE.py rename test/pytest/pytestfiles/{test_08_COMMON_SYNTAX_VIOLATIONS_GOODCASE.py => test_09_COMMON_SYNTAX_VIOLATIONS_GOODCASE.py} (96%) rename test/pytest/pytestfiles/{test_09_COMMON_SYNTAX_VIOLATIONS_BADCASE.py => test_10_COMMON_SYNTAX_VIOLATIONS_BADCASE.py} (97%) create mode 100644 test/pytest/pytestfiles/test_11_IMPLICIT_CREATION_GOODCASE.py create mode 100644 test/testfiles/import/import.1/import.1.1/jpp-test_config_implicit_creation.1.1.1.jsonp create mode 100644 test/testfiles/import/import.1/jpp-test_config_implicit_creation.1.1.jsonp create mode 100644 test/testfiles/import/jpp-test_config_implicit_creation.1.jsonp create mode 100644 test/testfiles/jpp-test_config_1000.jsonp diff --git a/test/JPP_TestUsecases.csv b/test/JPP_TestUsecases.csv index eaaa955b..345ed709 100644 --- a/test/JPP_TestUsecases.csv +++ b/test/JPP_TestUsecases.csv @@ -8,25 +8,43 @@ JPP_0101|DATA_INTEGRITY|GOODCASE|JSON file with string containing several separa JPP_0102|DATA_INTEGRITY|GOODCASE|JSON file with string containing more special characters, masked special characters and escape sequences JPP_0200|PARAMETER_SUBSTITUTION|GOODCASE|JSON file with nested parameter / string parameter substitution in parameter value JPP_0201|PARAMETER_SUBSTITUTION|GOODCASE|JSON file with nested parameter / string parameter substitution in parameter name +JPP_0202|PARAMETER_SUBSTITUTION|GOODCASE|JSON file with nested parameter / index parameter substitution in parameter name / standard notation +JPP_0203|PARAMETER_SUBSTITUTION|GOODCASE|JSON file with nested parameter / index parameter substitution in parameter name / dotdict notation +JPP_0204|PARAMETER_SUBSTITUTION|GOODCASE|JSON file with nested parameter / index parameter substitution in parameter value / standard notation JPP_0250|PARAMETER_SUBSTITUTION|BADCASE|JSON file with nested parameter / string parameter substitution in parameter value / innermost parameter not existing JPP_0251|PARAMETER_SUBSTITUTION|BADCASE|JSON file with nested parameter / string parameter substitution in parameter name / in between parameter not existing +JPP_0252|PARAMETER_SUBSTITUTION|BADCASE|JSON file with nested parameter / index parameter substitution in parameter name / standard notation / index parameter not existing JPP_0253|PARAMETER_SUBSTITUTION|BADCASE|JSON file with nested parameter / index parameter substitution in parameter name / dotdict notation / index parameter not existing +JPP_0254|PARAMETER_SUBSTITUTION|BADCASE|JSON file with nested parameter / index parameter substitution in parameter value / standard notation / index parameter not existing JPP_0255|PARAMETER_SUBSTITUTION|BADCASE|JSON file with nested parameter / index parameter substitution in parameter value / dotdict notation / index parameter not existing JPP_0257|PARAMETER_SUBSTITUTION|BADCASE|JSON file with nested parameter / key parameter substitution in parameter name / dotdict notation / milestone number not existing JPP_0259|PARAMETER_SUBSTITUTION|BADCASE|JSON file with nested parameter / key parameter substitution in parameter value / dotdict notation / milestone number not existing JPP_0300|VALUE_DETECTION|GOODCASE|JSON file with parameter of type 'list' / index (in square brackets) defined outside the curly brackets (valid syntax) +JPP_0301|VALUE_DETECTION|GOODCASE|JSON file with expression containing more closing elements '}' than opening elements '${' (valid syntax) +JPP_0302|VALUE_DETECTION|GOODCASE|JSON file with expression starting with '${' and ending with '}' / no further matching '${' and '}' in between (valid syntax) +JPP_0304|VALUE_DETECTION|GOODCASE|JSON file with expression starting with '${' and ending with '}', further matching '${' and '}' in between (not all nested) (valid syntax) JPP_0350|VALUE_DETECTION|BADCASE|JSON file with parameter of type 'list' / index (in square brackets) defined inside the curly brackets (invalid syntax 1) JPP_0351|VALUE_DETECTION|BADCASE|JSON file with parameter of type 'list' / index (in square brackets) defined inside the curly brackets (invalid syntax 2) JPP_0352|VALUE_DETECTION|BADCASE|JSON file with parameter of type 'list' / index (in square brackets) defined inside the curly brackets (invalid syntax 3) JPP_0353|VALUE_DETECTION|BADCASE|JSON file with expression containing more opening elements '${' than closing elements '}' (invalid syntax 1) JPP_0354|VALUE_DETECTION|BADCASE|JSON file with expression containing more opening elements '${' than closing elements '}' (invalid syntax 2) +JPP_0357|VALUE_DETECTION|BADCASE|JSON file with expression containing more opening elements '${' than closing elements '}' (invalid syntax 5) +JPP_0359|VALUE_DETECTION|BADCASE|JSON file with expression containing more opening elements '${' than closing elements '}' (invalid syntax 6) JPP_0361|VALUE_DETECTION|BADCASE|JSON file with expression containing more closing elements '}' than opening elements '${' (invalid syntax 1) +JPP_0367|VALUE_DETECTION|BADCASE|JSON file with expression starting with '${' and ending with '}', further matching '${' and '}' in between (not all nested) (invalid syntax 1) +JPP_0368|VALUE_DETECTION|BADCASE|JSON file with expression starting with '${' and ending with '}', further matching '${' and '}' in between (not all nested) (invalid syntax 2) +JPP_0369|VALUE_DETECTION|BADCASE|JSON file with expression starting with '${' and ending with '}', further matching '${' and '}' in between (not all nested) (invalid syntax 3) +JPP_0370|VALUE_DETECTION|BADCASE|JSON file with expression starting with '${' and ending with '}', further matching '${' and '}' in between (not all nested) (invalid syntax 4) +JPP_0371|VALUE_DETECTION|BADCASE|JSON file with expression starting with '${' and ending with '}', further matching '${' and '}' in between (not all nested) (invalid syntax 5) JPP_0500|COMPOSITE_EXPRESSIONS|GOODCASE|JSON file with composite data structure (nested lists and dictionaries 1) +JPP_0501|COMPOSITE_EXPRESSIONS|GOODCASE|JSON file with composite data structure (nested lists and dictionaries 2) JPP_0502|COMPOSITE_EXPRESSIONS|GOODCASE|JSON file with composite data structure (nested lists and dictionaries 3 / some key names with dots inside) JPP_0506|COMPOSITE_EXPRESSIONS|GOODCASE|JSON file with composite strings containing several combinations of curly brackets and special characters before +JPP_0550|COMPOSITE_EXPRESSIONS|BADCASE|JSON file with composite data structure (nested lists and dictionaries / some key names with dots inside) JPP_0900|COMMON_SYNTAX_VIOLATIONS|GOODCASE|JSON file with syntax error, that is commented out JPP_0950|COMMON_SYNTAX_VIOLATIONS|BADCASE|JSON file with syntax error (1) JPP_0951|COMMON_SYNTAX_VIOLATIONS|BADCASE|JSON file with syntax error (2) JPP_0952|COMMON_SYNTAX_VIOLATIONS|BADCASE|JSON file with syntax error (3) JPP_0953|COMMON_SYNTAX_VIOLATIONS|BADCASE|JSON file with syntax error (4): file is completely empty JPP_0954|COMMON_SYNTAX_VIOLATIONS|BADCASE|JSON file with syntax error (5): file is empty (multiple pairs of brackets only) +JPP_1000|IMPLICIT_CREATION|GOODCASE|JSON file with dictionary keys to be created implicitly diff --git a/test/JPP_TestUsecases.html b/test/JPP_TestUsecases.html index 1e45c189..29042094 100644 --- a/test/JPP_TestUsecases.html +++ b/test/JPP_TestUsecases.html @@ -298,6 +298,105 @@ 9 + + + +JPP_0202 + + + + +PARAMETER_SUBSTITUTION + + + + +GOODCASE + + + + +JSON file with nested parameter / index parameter substitution in parameter name / standard notation
+Expected: JsonPreprocessor creates a new string with all dollar operator expressions resolved as string + + +
+ + + + + + + +10 + + + + + +JPP_0203 + + + + +PARAMETER_SUBSTITUTION + + + + +GOODCASE + + + + +JSON file with nested parameter / index parameter substitution in parameter name / dotdict notation
+Expected: JsonPreprocessor creates a new string with all dollar operator expressions resolved as string + + +
+ + + + + + + +11 + + + + + +JPP_0204 + + + + +PARAMETER_SUBSTITUTION + + + + +GOODCASE + + + + +JSON file with nested parameter / index parameter substitution in parameter value / standard notation
+Expected: JsonPreprocessor creates a new string with all dollar operator expressions resolved as string + + +
+ + + + + + + +12 + + @@ -306,7 +405,407 @@ -PARAMETER_SUBSTITUTION +PARAMETER_SUBSTITUTION + + + + +BADCASE + + + + +JSON file with nested parameter / string parameter substitution in parameter value / innermost parameter not existing
+Expected: No values are returned, and JsonPreprocessor throws an exception + + +
+ + + + + + + +13 + + + + + +JPP_0251 + + + + +PARAMETER_SUBSTITUTION + + + + +BADCASE + + + + +JSON file with nested parameter / string parameter substitution in parameter name / in between parameter not existing
+Expected: No values are returned, and JsonPreprocessor throws an exception + + +
+ + + + + + + +14 + + + + + +JPP_0252 + + + + +PARAMETER_SUBSTITUTION + + + + +BADCASE + + + + +JSON file with nested parameter / index parameter substitution in parameter name / standard notation / index parameter not existing
+Expected: No values are returned, and JsonPreprocessor throws an exception + + +
+ + + + + + + +15 + + + + + +JPP_0253 + + + + +PARAMETER_SUBSTITUTION + + + + +BADCASE + + + + +JSON file with nested parameter / index parameter substitution in parameter name / dotdict notation / index parameter not existing
+Expected: No values are returned, and JsonPreprocessor throws an exception + + +
+ + + + + + + +16 + + + + + +JPP_0254 + + + + +PARAMETER_SUBSTITUTION + + + + +BADCASE + + + + +JSON file with nested parameter / index parameter substitution in parameter value / standard notation / index parameter not existing
+Expected: No values are returned, and JsonPreprocessor throws an exception + + +
+ + + + + + + +17 + + + + + +JPP_0255 + + + + +PARAMETER_SUBSTITUTION + + + + +BADCASE + + + + +JSON file with nested parameter / index parameter substitution in parameter value / dotdict notation / index parameter not existing
+Expected: No values are returned, and JsonPreprocessor throws an exception + + +
+ + + + + + + +18 + + + + + +JPP_0257 + + + + +PARAMETER_SUBSTITUTION + + + + +BADCASE + + + + +JSON file with nested parameter / key parameter substitution in parameter name / dotdict notation / milestone number not existing
+Expected: No values are returned, and JsonPreprocessor throws an exception + + +
+ + + + + + + +19 + + + + + +JPP_0259 + + + + +PARAMETER_SUBSTITUTION + + + + +BADCASE + + + + +JSON file with nested parameter / key parameter substitution in parameter value / dotdict notation / milestone number not existing
+Expected: No values are returned, and JsonPreprocessor throws an exception + + +
+ + + + + + + +20 + + + + + +JPP_0300 + + + + +VALUE_DETECTION + + + + +GOODCASE + + + + +JSON file with parameter of type 'list' / index (in square brackets) defined outside the curly brackets (valid syntax)
+Expected: JsonPreprocessor returns values + +
+Checklist rule 1 +
+ + + + + + + +21 + + + + + +JPP_0301 + + + + +VALUE_DETECTION + + + + +GOODCASE + + + + +JSON file with expression containing more closing elements '}' than opening elements '${' (valid syntax)
+Expected: JsonPreprocessor returns values + +
+Checklist rule 3 +
+ + + + + + + +22 + + + + + +JPP_0302 + + + + +VALUE_DETECTION + + + + +GOODCASE + + + + +JSON file with expression starting with '${' and ending with '}' / no further matching '${' and '}' in between (valid syntax)
+Expected: JsonPreprocessor returns values + +
+Checklist rule 4 +
+ + + + + + + +23 + + + + + +JPP_0304 + + + + +VALUE_DETECTION + + + + +GOODCASE + + + + +JSON file with expression starting with '${' and ending with '}', further matching '${' and '}' in between (not all nested) (valid syntax)
+Expected: JsonPreprocessor returns values + +
+Checklist rule 6 +
+ + + + + + + +24 + + + + + +JPP_0350 + + + + +VALUE_DETECTION @@ -316,10 +815,11 @@ -JSON file with nested parameter / string parameter substitution in parameter value / innermost parameter not existing
+JSON file with parameter of type 'list' / index (in square brackets) defined inside the curly brackets (invalid syntax 1)
Expected: No values are returned, and JsonPreprocessor throws an exception - +
+Checklist rule 1 / pattern 1
@@ -328,18 +828,18 @@ -10 +25 -JPP_0251 +JPP_0351 -PARAMETER_SUBSTITUTION +VALUE_DETECTION @@ -349,10 +849,11 @@ -JSON file with nested parameter / string parameter substitution in parameter name / in between parameter not existing
+JSON file with parameter of type 'list' / index (in square brackets) defined inside the curly brackets (invalid syntax 2)
Expected: No values are returned, and JsonPreprocessor throws an exception - +
+Checklist rule 1 / pattern 2
@@ -361,18 +862,18 @@ -11 +26 -JPP_0253 +JPP_0352 -PARAMETER_SUBSTITUTION +VALUE_DETECTION @@ -382,10 +883,11 @@ -JSON file with nested parameter / index parameter substitution in parameter name / dotdict notation / index parameter not existing
+JSON file with parameter of type 'list' / index (in square brackets) defined inside the curly brackets (invalid syntax 3)
Expected: No values are returned, and JsonPreprocessor throws an exception - +
+Checklist rule 1 / pattern 3
@@ -394,18 +896,18 @@ -12 +27 -JPP_0255 +JPP_0353 -PARAMETER_SUBSTITUTION +VALUE_DETECTION @@ -415,10 +917,11 @@ -JSON file with nested parameter / index parameter substitution in parameter value / dotdict notation / index parameter not existing
+JSON file with expression containing more opening elements '${' than closing elements '}' (invalid syntax 1)
Expected: No values are returned, and JsonPreprocessor throws an exception - +
+Checklist rule 2 / pattern 1
@@ -427,18 +930,18 @@ -13 +28 -JPP_0257 +JPP_0354 -PARAMETER_SUBSTITUTION +VALUE_DETECTION @@ -448,10 +951,11 @@ -JSON file with nested parameter / key parameter substitution in parameter name / dotdict notation / milestone number not existing
+JSON file with expression containing more opening elements '${' than closing elements '}' (invalid syntax 2)
Expected: No values are returned, and JsonPreprocessor throws an exception - +
+Checklist rule 2 / pattern 2
@@ -460,18 +964,18 @@ -14 +29 -JPP_0259 +JPP_0357 -PARAMETER_SUBSTITUTION +VALUE_DETECTION @@ -481,10 +985,11 @@ -JSON file with nested parameter / key parameter substitution in parameter value / dotdict notation / milestone number not existing
+JSON file with expression containing more opening elements '${' than closing elements '}' (invalid syntax 5)
Expected: No values are returned, and JsonPreprocessor throws an exception - +
+Checklist rule 2 / pattern 5
@@ -493,13 +998,13 @@ -15 +30 -JPP_0300 +JPP_0359 @@ -508,17 +1013,17 @@
- -GOODCASE + +BADCASE -JSON file with parameter of type 'list' / index (in square brackets) defined outside the curly brackets (valid syntax)
-Expected: JsonPreprocessor returns values +JSON file with expression containing more opening elements '${' than closing elements '}' (invalid syntax 6)
+Expected: No values are returned, and JsonPreprocessor throws an exception
-Checklist rule 1 +Checklist rule 2 / pattern 7
@@ -527,13 +1032,13 @@ -16 +31 -JPP_0350 +JPP_0361 @@ -548,11 +1053,11 @@ -JSON file with parameter of type 'list' / index (in square brackets) defined inside the curly brackets (invalid syntax 1)
+JSON file with expression containing more closing elements '}' than opening elements '${' (invalid syntax 1)
Expected: No values are returned, and JsonPreprocessor throws an exception
-Checklist rule 1 / pattern 1 +Checklist rule 3 / pattern 1
@@ -561,13 +1066,13 @@ -17 +32 -JPP_0351 +JPP_0367 @@ -582,11 +1087,11 @@ -JSON file with parameter of type 'list' / index (in square brackets) defined inside the curly brackets (invalid syntax 2)
+JSON file with expression starting with '${' and ending with '}', further matching '${' and '}' in between (not all nested) (invalid syntax 1)
Expected: No values are returned, and JsonPreprocessor throws an exception
-Checklist rule 1 / pattern 2 +Checklist rule 6 / pattern 1
@@ -595,13 +1100,13 @@ -18 +33 -JPP_0352 +JPP_0368 @@ -616,11 +1121,11 @@ -JSON file with parameter of type 'list' / index (in square brackets) defined inside the curly brackets (invalid syntax 3)
+JSON file with expression starting with '${' and ending with '}', further matching '${' and '}' in between (not all nested) (invalid syntax 2)
Expected: No values are returned, and JsonPreprocessor throws an exception
-Checklist rule 1 / pattern 3 +Checklist rule 6 / pattern 2
@@ -629,13 +1134,13 @@ -19 +34 -JPP_0353 +JPP_0369 @@ -650,11 +1155,11 @@ -JSON file with expression containing more opening elements '${' than closing elements '}' (invalid syntax 1)
+JSON file with expression starting with '${' and ending with '}', further matching '${' and '}' in between (not all nested) (invalid syntax 3)
Expected: No values are returned, and JsonPreprocessor throws an exception
-Checklist rule 2 / pattern 1 +Checklist rule 6 / pattern 3
@@ -663,13 +1168,13 @@ -20 +35 -JPP_0354 +JPP_0370 @@ -684,11 +1189,11 @@ -JSON file with expression containing more opening elements '${' than closing elements '}' (invalid syntax 2)
+JSON file with expression starting with '${' and ending with '}', further matching '${' and '}' in between (not all nested) (invalid syntax 4)
Expected: No values are returned, and JsonPreprocessor throws an exception
-Checklist rule 2 / pattern 2 +Checklist rule 6 / pattern 4
@@ -697,13 +1202,13 @@ -21 +36 -JPP_0361 +JPP_0371 @@ -718,11 +1223,11 @@ -JSON file with expression containing more closing elements '}' than opening elements '${' (invalid syntax 1)
+JSON file with expression starting with '${' and ending with '}', further matching '${' and '}' in between (not all nested) (invalid syntax 5)
Expected: No values are returned, and JsonPreprocessor throws an exception
-Checklist rule 3 / pattern 1 +Checklist rule 6 / pattern 5
@@ -731,7 +1236,7 @@ -22 +37 @@ -765,7 +1270,41 @@ -23 +38 + + + + + +JPP_0501 + + + + +COMPOSITE_EXPRESSIONS + + + + +GOODCASE + + + + +JSON file with composite data structure (nested lists and dictionaries 2)
+Expected: JsonPreprocessor returns expected value + +
+Dotdict notation +
+ + + + + + + +39 @@ -799,7 +1338,7 @@ -24 +40 @@ -832,7 +1371,41 @@ -25 +41 + + + + + +JPP_0550 + + + + +COMPOSITE_EXPRESSIONS + + + + +BADCASE + + + + +JSON file with composite data structure (nested lists and dictionaries / some key names with dots inside)
+Expected: No values are returned, and JsonPreprocessor throws an exception + +
+Dotdict notation (ambiguous in this case) +
+ + + + + + + +42 @@ -865,7 +1438,7 @@ -26 +43 @@ -898,7 +1471,7 @@ -27 +44 @@ -931,7 +1504,7 @@ -28 +45 @@ -964,7 +1537,7 @@ -29 +46 @@ -997,7 +1570,7 @@ -30 +47 @@ -1025,12 +1598,45 @@
+ + + + + +48 + + + + + +JPP_1000 + + + + +IMPLICIT_CREATION + + + + +GOODCASE + + + + +JSON file with dictionary keys to be created implicitly
+Expected: JsonPreprocessor returns values + + +
+ +
 

-
Generated: 17.08.2023 - 14:06:12
+
Generated: 13.09.2023 - 10:58:36
 
diff --git a/test/JPP_TestUsecases.rst b/test/JPP_TestUsecases.rst index c8ea0473..dec15fc8 100644 --- a/test/JPP_TestUsecases.rst +++ b/test/JPP_TestUsecases.rst @@ -95,6 +95,36 @@ Test Use Cases ---- +* **Test JPP_0202** + + [PARAMETER_SUBSTITUTION / GOODCASE] + + **JSON file with nested parameter / index parameter substitution in parameter name / standard notation** + + Expected: JsonPreprocessor creates a new string with all dollar operator expressions resolved as string + +---- + +* **Test JPP_0203** + + [PARAMETER_SUBSTITUTION / GOODCASE] + + **JSON file with nested parameter / index parameter substitution in parameter name / dotdict notation** + + Expected: JsonPreprocessor creates a new string with all dollar operator expressions resolved as string + +---- + +* **Test JPP_0204** + + [PARAMETER_SUBSTITUTION / GOODCASE] + + **JSON file with nested parameter / index parameter substitution in parameter value / standard notation** + + Expected: JsonPreprocessor creates a new string with all dollar operator expressions resolved as string + +---- + * **Test JPP_0250** [PARAMETER_SUBSTITUTION / BADCASE] @@ -115,6 +145,16 @@ Test Use Cases ---- +* **Test JPP_0252** + + [PARAMETER_SUBSTITUTION / BADCASE] + + **JSON file with nested parameter / index parameter substitution in parameter name / standard notation / index parameter not existing** + + Expected: No values are returned, and JsonPreprocessor throws an exception + +---- + * **Test JPP_0253** [PARAMETER_SUBSTITUTION / BADCASE] @@ -125,6 +165,16 @@ Test Use Cases ---- +* **Test JPP_0254** + + [PARAMETER_SUBSTITUTION / BADCASE] + + **JSON file with nested parameter / index parameter substitution in parameter value / standard notation / index parameter not existing** + + Expected: No values are returned, and JsonPreprocessor throws an exception + +---- + * **Test JPP_0255** [PARAMETER_SUBSTITUTION / BADCASE] @@ -167,6 +217,42 @@ Test Use Cases ---- +* **Test JPP_0301** + + [VALUE_DETECTION / GOODCASE] + + **JSON file with expression containing more closing elements '}' than opening elements '${' (valid syntax)** + + Expected: JsonPreprocessor returns values + + *Hint: Checklist rule 3* + +---- + +* **Test JPP_0302** + + [VALUE_DETECTION / GOODCASE] + + **JSON file with expression starting with '${' and ending with '}' / no further matching '${' and '}' in between (valid syntax)** + + Expected: JsonPreprocessor returns values + + *Hint: Checklist rule 4* + +---- + +* **Test JPP_0304** + + [VALUE_DETECTION / GOODCASE] + + **JSON file with expression starting with '${' and ending with '}', further matching '${' and '}' in between (not all nested) (valid syntax)** + + Expected: JsonPreprocessor returns values + + *Hint: Checklist rule 6* + +---- + * **Test JPP_0350** [VALUE_DETECTION / BADCASE] @@ -227,6 +313,30 @@ Test Use Cases ---- +* **Test JPP_0357** + + [VALUE_DETECTION / BADCASE] + + **JSON file with expression containing more opening elements '${' than closing elements '}' (invalid syntax 5)** + + Expected: No values are returned, and JsonPreprocessor throws an exception + + *Hint: Checklist rule 2 / pattern 5* + +---- + +* **Test JPP_0359** + + [VALUE_DETECTION / BADCASE] + + **JSON file with expression containing more opening elements '${' than closing elements '}' (invalid syntax 6)** + + Expected: No values are returned, and JsonPreprocessor throws an exception + + *Hint: Checklist rule 2 / pattern 7* + +---- + * **Test JPP_0361** [VALUE_DETECTION / BADCASE] @@ -239,6 +349,66 @@ Test Use Cases ---- +* **Test JPP_0367** + + [VALUE_DETECTION / BADCASE] + + **JSON file with expression starting with '${' and ending with '}', further matching '${' and '}' in between (not all nested) (invalid syntax 1)** + + Expected: No values are returned, and JsonPreprocessor throws an exception + + *Hint: Checklist rule 6 / pattern 1* + +---- + +* **Test JPP_0368** + + [VALUE_DETECTION / BADCASE] + + **JSON file with expression starting with '${' and ending with '}', further matching '${' and '}' in between (not all nested) (invalid syntax 2)** + + Expected: No values are returned, and JsonPreprocessor throws an exception + + *Hint: Checklist rule 6 / pattern 2* + +---- + +* **Test JPP_0369** + + [VALUE_DETECTION / BADCASE] + + **JSON file with expression starting with '${' and ending with '}', further matching '${' and '}' in between (not all nested) (invalid syntax 3)** + + Expected: No values are returned, and JsonPreprocessor throws an exception + + *Hint: Checklist rule 6 / pattern 3* + +---- + +* **Test JPP_0370** + + [VALUE_DETECTION / BADCASE] + + **JSON file with expression starting with '${' and ending with '}', further matching '${' and '}' in between (not all nested) (invalid syntax 4)** + + Expected: No values are returned, and JsonPreprocessor throws an exception + + *Hint: Checklist rule 6 / pattern 4* + +---- + +* **Test JPP_0371** + + [VALUE_DETECTION / BADCASE] + + **JSON file with expression starting with '${' and ending with '}', further matching '${' and '}' in between (not all nested) (invalid syntax 5)** + + Expected: No values are returned, and JsonPreprocessor throws an exception + + *Hint: Checklist rule 6 / pattern 5* + +---- + * **Test JPP_0500** [COMPOSITE_EXPRESSIONS / GOODCASE] @@ -251,6 +421,18 @@ Test Use Cases ---- +* **Test JPP_0501** + + [COMPOSITE_EXPRESSIONS / GOODCASE] + + **JSON file with composite data structure (nested lists and dictionaries 2)** + + Expected: JsonPreprocessor returns expected value + + *Hint: Dotdict notation* + +---- + * **Test JPP_0502** [COMPOSITE_EXPRESSIONS / GOODCASE] @@ -273,6 +455,18 @@ Test Use Cases ---- +* **Test JPP_0550** + + [COMPOSITE_EXPRESSIONS / BADCASE] + + **JSON file with composite data structure (nested lists and dictionaries / some key names with dots inside)** + + Expected: No values are returned, and JsonPreprocessor throws an exception + + *Hint: Dotdict notation (ambiguous in this case)* + +---- + * **Test JPP_0900** [COMMON_SYNTAX_VIOLATIONS / GOODCASE] @@ -333,5 +527,15 @@ Test Use Cases ---- -Generated: 17.08.2023 - 14:06:12 +* **Test JPP_1000** + + [IMPLICIT_CREATION / GOODCASE] + + **JSON file with dictionary keys to be created implicitly** + + Expected: JsonPreprocessor returns values + +---- + +Generated: 13.09.2023 - 10:58:36 diff --git a/test/JPP_TestUsecases.txt b/test/JPP_TestUsecases.txt index 5afce81d..190200f8 100644 --- a/test/JPP_TestUsecases.txt +++ b/test/JPP_TestUsecases.txt @@ -47,6 +47,18 @@ Test JPP_0201 / PARAMETER_SUBSTITUTION / GOODCASE Description: JSON file with nested parameter / string parameter substitution in parameter name Expectation: JsonPreprocessor creates a new string with all dollar operator expressions resolved as string ------------------------------------------------------------------------------------------------------------------------ +Test JPP_0202 / PARAMETER_SUBSTITUTION / GOODCASE +Description: JSON file with nested parameter / index parameter substitution in parameter name / standard notation +Expectation: JsonPreprocessor creates a new string with all dollar operator expressions resolved as string +------------------------------------------------------------------------------------------------------------------------ +Test JPP_0203 / PARAMETER_SUBSTITUTION / GOODCASE +Description: JSON file with nested parameter / index parameter substitution in parameter name / dotdict notation +Expectation: JsonPreprocessor creates a new string with all dollar operator expressions resolved as string +------------------------------------------------------------------------------------------------------------------------ +Test JPP_0204 / PARAMETER_SUBSTITUTION / GOODCASE +Description: JSON file with nested parameter / index parameter substitution in parameter value / standard notation +Expectation: JsonPreprocessor creates a new string with all dollar operator expressions resolved as string +------------------------------------------------------------------------------------------------------------------------ Test JPP_0250 / PARAMETER_SUBSTITUTION / BADCASE Description: JSON file with nested parameter / string parameter substitution in parameter value / innermost parameter not existing Expectation: No values are returned, and JsonPreprocessor throws an exception @@ -55,10 +67,18 @@ Test JPP_0251 / PARAMETER_SUBSTITUTION / BADCASE Description: JSON file with nested parameter / string parameter substitution in parameter name / in between parameter not existing Expectation: No values are returned, and JsonPreprocessor throws an exception ------------------------------------------------------------------------------------------------------------------------ +Test JPP_0252 / PARAMETER_SUBSTITUTION / BADCASE +Description: JSON file with nested parameter / index parameter substitution in parameter name / standard notation / index parameter not existing +Expectation: No values are returned, and JsonPreprocessor throws an exception +------------------------------------------------------------------------------------------------------------------------ Test JPP_0253 / PARAMETER_SUBSTITUTION / BADCASE Description: JSON file with nested parameter / index parameter substitution in parameter name / dotdict notation / index parameter not existing Expectation: No values are returned, and JsonPreprocessor throws an exception ------------------------------------------------------------------------------------------------------------------------ +Test JPP_0254 / PARAMETER_SUBSTITUTION / BADCASE +Description: JSON file with nested parameter / index parameter substitution in parameter value / standard notation / index parameter not existing +Expectation: No values are returned, and JsonPreprocessor throws an exception +------------------------------------------------------------------------------------------------------------------------ Test JPP_0255 / PARAMETER_SUBSTITUTION / BADCASE Description: JSON file with nested parameter / index parameter substitution in parameter value / dotdict notation / index parameter not existing Expectation: No values are returned, and JsonPreprocessor throws an exception @@ -76,6 +96,21 @@ Description: JSON file with parameter of type 'list' / index (in square brackets Expectation: JsonPreprocessor returns values Hint.......: Checklist rule 1 ------------------------------------------------------------------------------------------------------------------------ +Test JPP_0301 / VALUE_DETECTION / GOODCASE +Description: JSON file with expression containing more closing elements '}' than opening elements '${' (valid syntax) +Expectation: JsonPreprocessor returns values +Hint.......: Checklist rule 3 +------------------------------------------------------------------------------------------------------------------------ +Test JPP_0302 / VALUE_DETECTION / GOODCASE +Description: JSON file with expression starting with '${' and ending with '}' / no further matching '${' and '}' in between (valid syntax) +Expectation: JsonPreprocessor returns values +Hint.......: Checklist rule 4 +------------------------------------------------------------------------------------------------------------------------ +Test JPP_0304 / VALUE_DETECTION / GOODCASE +Description: JSON file with expression starting with '${' and ending with '}', further matching '${' and '}' in between (not all nested) (valid syntax) +Expectation: JsonPreprocessor returns values +Hint.......: Checklist rule 6 +------------------------------------------------------------------------------------------------------------------------ Test JPP_0350 / VALUE_DETECTION / BADCASE Description: JSON file with parameter of type 'list' / index (in square brackets) defined inside the curly brackets (invalid syntax 1) Expectation: No values are returned, and JsonPreprocessor throws an exception @@ -101,16 +136,56 @@ Description: JSON file with expression containing more opening elements '${' tha Expectation: No values are returned, and JsonPreprocessor throws an exception Hint.......: Checklist rule 2 / pattern 2 ------------------------------------------------------------------------------------------------------------------------ +Test JPP_0357 / VALUE_DETECTION / BADCASE +Description: JSON file with expression containing more opening elements '${' than closing elements '}' (invalid syntax 5) +Expectation: No values are returned, and JsonPreprocessor throws an exception +Hint.......: Checklist rule 2 / pattern 5 +------------------------------------------------------------------------------------------------------------------------ +Test JPP_0359 / VALUE_DETECTION / BADCASE +Description: JSON file with expression containing more opening elements '${' than closing elements '}' (invalid syntax 6) +Expectation: No values are returned, and JsonPreprocessor throws an exception +Hint.......: Checklist rule 2 / pattern 7 +------------------------------------------------------------------------------------------------------------------------ Test JPP_0361 / VALUE_DETECTION / BADCASE Description: JSON file with expression containing more closing elements '}' than opening elements '${' (invalid syntax 1) Expectation: No values are returned, and JsonPreprocessor throws an exception Hint.......: Checklist rule 3 / pattern 1 ------------------------------------------------------------------------------------------------------------------------ +Test JPP_0367 / VALUE_DETECTION / BADCASE +Description: JSON file with expression starting with '${' and ending with '}', further matching '${' and '}' in between (not all nested) (invalid syntax 1) +Expectation: No values are returned, and JsonPreprocessor throws an exception +Hint.......: Checklist rule 6 / pattern 1 +------------------------------------------------------------------------------------------------------------------------ +Test JPP_0368 / VALUE_DETECTION / BADCASE +Description: JSON file with expression starting with '${' and ending with '}', further matching '${' and '}' in between (not all nested) (invalid syntax 2) +Expectation: No values are returned, and JsonPreprocessor throws an exception +Hint.......: Checklist rule 6 / pattern 2 +------------------------------------------------------------------------------------------------------------------------ +Test JPP_0369 / VALUE_DETECTION / BADCASE +Description: JSON file with expression starting with '${' and ending with '}', further matching '${' and '}' in between (not all nested) (invalid syntax 3) +Expectation: No values are returned, and JsonPreprocessor throws an exception +Hint.......: Checklist rule 6 / pattern 3 +------------------------------------------------------------------------------------------------------------------------ +Test JPP_0370 / VALUE_DETECTION / BADCASE +Description: JSON file with expression starting with '${' and ending with '}', further matching '${' and '}' in between (not all nested) (invalid syntax 4) +Expectation: No values are returned, and JsonPreprocessor throws an exception +Hint.......: Checklist rule 6 / pattern 4 +------------------------------------------------------------------------------------------------------------------------ +Test JPP_0371 / VALUE_DETECTION / BADCASE +Description: JSON file with expression starting with '${' and ending with '}', further matching '${' and '}' in between (not all nested) (invalid syntax 5) +Expectation: No values are returned, and JsonPreprocessor throws an exception +Hint.......: Checklist rule 6 / pattern 5 +------------------------------------------------------------------------------------------------------------------------ Test JPP_0500 / COMPOSITE_EXPRESSIONS / GOODCASE Description: JSON file with composite data structure (nested lists and dictionaries 1) Expectation: JsonPreprocessor returns expected value Hint.......: Standard notation ------------------------------------------------------------------------------------------------------------------------ +Test JPP_0501 / COMPOSITE_EXPRESSIONS / GOODCASE +Description: JSON file with composite data structure (nested lists and dictionaries 2) +Expectation: JsonPreprocessor returns expected value +Hint.......: Dotdict notation +------------------------------------------------------------------------------------------------------------------------ Test JPP_0502 / COMPOSITE_EXPRESSIONS / GOODCASE Description: JSON file with composite data structure (nested lists and dictionaries 3 / some key names with dots inside) Expectation: JsonPreprocessor returns expected value @@ -120,6 +195,11 @@ Test JPP_0506 / COMPOSITE_EXPRESSIONS / GOODCASE Description: JSON file with composite strings containing several combinations of curly brackets and special characters before Expectation: JsonPreprocessor returns expected value ------------------------------------------------------------------------------------------------------------------------ +Test JPP_0550 / COMPOSITE_EXPRESSIONS / BADCASE +Description: JSON file with composite data structure (nested lists and dictionaries / some key names with dots inside) +Expectation: No values are returned, and JsonPreprocessor throws an exception +Hint.......: Dotdict notation (ambiguous in this case) +------------------------------------------------------------------------------------------------------------------------ Test JPP_0900 / COMMON_SYNTAX_VIOLATIONS / GOODCASE Description: JSON file with syntax error, that is commented out Expectation: JsonPreprocessor returns remaining content of JSON file (valid parameters) @@ -144,5 +224,9 @@ Test JPP_0954 / COMMON_SYNTAX_VIOLATIONS / BADCASE Description: JSON file with syntax error (5): file is empty (multiple pairs of brackets only) Expectation: No values are returned, and JsonPreprocessor throws an exception ------------------------------------------------------------------------------------------------------------------------ -Generated: 17.08.2023 - 14:06:12 +Test JPP_1000 / IMPLICIT_CREATION / GOODCASE +Description: JSON file with dictionary keys to be created implicitly +Expectation: JsonPreprocessor returns values +------------------------------------------------------------------------------------------------------------------------ +Generated: 13.09.2023 - 10:58:36 diff --git a/test/component_test.py b/test/component_test.py index 6a83a89e..6d93d514 100644 --- a/test/component_test.py +++ b/test/component_test.py @@ -22,8 +22,8 @@ # # -------------------------------------------------------------------------------------------------------------- # -VERSION = "0.7.0" -VERSION_DATE = "07.09.2023" +VERSION = "0.8.0" +VERSION_DATE = "13.09.2023" # # -------------------------------------------------------------------------------------------------------------- #TM*** diff --git a/test/pytest/pytestfiles/test_03_PARAMETER_SUBSTITUTION_GOODCASE.py b/test/pytest/pytestfiles/test_03_PARAMETER_SUBSTITUTION_GOODCASE.py index 949b1ec0..937f94cf 100644 --- a/test/pytest/pytestfiles/test_03_PARAMETER_SUBSTITUTION_GOODCASE.py +++ b/test/pytest/pytestfiles/test_03_PARAMETER_SUBSTITUTION_GOODCASE.py @@ -18,7 +18,7 @@ # # XC-CT/ECA3-Queckenstedt # -# 09.08.2023 - 17:28:15 +# 13.09.2023 - 10:58:36 # # -------------------------------------------------------------------------------------------------------------- @@ -45,4 +45,28 @@ def test_JPP_0200(self, Description): def test_JPP_0201(self, Description): nReturn = CExecute.Execute("JPP_0201") assert nReturn == 0 +# -------------------------------------------------------------------------------------------------------------- + # Expected: JsonPreprocessor creates a new string with all dollar operator expressions resolved as string + @pytest.mark.parametrize( + "Description", ["JSON file with nested parameter / index parameter substitution in parameter name / standard notation",] + ) + def test_JPP_0202(self, Description): + nReturn = CExecute.Execute("JPP_0202") + assert nReturn == 0 +# -------------------------------------------------------------------------------------------------------------- + # Expected: JsonPreprocessor creates a new string with all dollar operator expressions resolved as string + @pytest.mark.parametrize( + "Description", ["JSON file with nested parameter / index parameter substitution in parameter name / dotdict notation",] + ) + def test_JPP_0203(self, Description): + nReturn = CExecute.Execute("JPP_0203") + assert nReturn == 0 +# -------------------------------------------------------------------------------------------------------------- + # Expected: JsonPreprocessor creates a new string with all dollar operator expressions resolved as string + @pytest.mark.parametrize( + "Description", ["JSON file with nested parameter / index parameter substitution in parameter value / standard notation",] + ) + def test_JPP_0204(self, Description): + nReturn = CExecute.Execute("JPP_0204") + assert nReturn == 0 # -------------------------------------------------------------------------------------------------------------- diff --git a/test/pytest/pytestfiles/test_04_PARAMETER_SUBSTITUTION_BADCASE.py b/test/pytest/pytestfiles/test_04_PARAMETER_SUBSTITUTION_BADCASE.py index d59f28fd..36b834ff 100644 --- a/test/pytest/pytestfiles/test_04_PARAMETER_SUBSTITUTION_BADCASE.py +++ b/test/pytest/pytestfiles/test_04_PARAMETER_SUBSTITUTION_BADCASE.py @@ -18,7 +18,7 @@ # # XC-CT/ECA3-Queckenstedt # -# 09.08.2023 - 17:28:15 +# 13.09.2023 - 10:58:36 # # -------------------------------------------------------------------------------------------------------------- @@ -45,6 +45,14 @@ def test_JPP_0250(self, Description): def test_JPP_0251(self, Description): nReturn = CExecute.Execute("JPP_0251") assert nReturn == 0 +# -------------------------------------------------------------------------------------------------------------- + # Expected: No values are returned, and JsonPreprocessor throws an exception + @pytest.mark.parametrize( + "Description", ["JSON file with nested parameter / index parameter substitution in parameter name / standard notation / index parameter not existing",] + ) + def test_JPP_0252(self, Description): + nReturn = CExecute.Execute("JPP_0252") + assert nReturn == 0 # -------------------------------------------------------------------------------------------------------------- # Expected: No values are returned, and JsonPreprocessor throws an exception @pytest.mark.parametrize( @@ -53,6 +61,14 @@ def test_JPP_0251(self, Description): def test_JPP_0253(self, Description): nReturn = CExecute.Execute("JPP_0253") assert nReturn == 0 +# -------------------------------------------------------------------------------------------------------------- + # Expected: No values are returned, and JsonPreprocessor throws an exception + @pytest.mark.parametrize( + "Description", ["JSON file with nested parameter / index parameter substitution in parameter value / standard notation / index parameter not existing",] + ) + def test_JPP_0254(self, Description): + nReturn = CExecute.Execute("JPP_0254") + assert nReturn == 0 # -------------------------------------------------------------------------------------------------------------- # Expected: No values are returned, and JsonPreprocessor throws an exception @pytest.mark.parametrize( diff --git a/test/pytest/pytestfiles/test_05_VALUE_DETECTION_GOODCASE.py b/test/pytest/pytestfiles/test_05_VALUE_DETECTION_GOODCASE.py index 2028652e..e8841a91 100644 --- a/test/pytest/pytestfiles/test_05_VALUE_DETECTION_GOODCASE.py +++ b/test/pytest/pytestfiles/test_05_VALUE_DETECTION_GOODCASE.py @@ -18,7 +18,7 @@ # # XC-CT/ECA3-Queckenstedt # -# 09.08.2023 - 17:28:15 +# 13.09.2023 - 10:58:36 # # -------------------------------------------------------------------------------------------------------------- @@ -37,4 +37,28 @@ class Test_VALUE_DETECTION_GOODCASE: def test_JPP_0300(self, Description): nReturn = CExecute.Execute("JPP_0300") assert nReturn == 0 +# -------------------------------------------------------------------------------------------------------------- + # Expected: JsonPreprocessor returns values + @pytest.mark.parametrize( + "Description", ["JSON file with expression containing more closing elements '}' than opening elements '${' (valid syntax)",] + ) + def test_JPP_0301(self, Description): + nReturn = CExecute.Execute("JPP_0301") + assert nReturn == 0 +# -------------------------------------------------------------------------------------------------------------- + # Expected: JsonPreprocessor returns values + @pytest.mark.parametrize( + "Description", ["JSON file with expression starting with '${' and ending with '}' / no further matching '${' and '}' in between (valid syntax)",] + ) + def test_JPP_0302(self, Description): + nReturn = CExecute.Execute("JPP_0302") + assert nReturn == 0 +# -------------------------------------------------------------------------------------------------------------- + # Expected: JsonPreprocessor returns values + @pytest.mark.parametrize( + "Description", ["JSON file with expression starting with '${' and ending with '}', further matching '${' and '}' in between (not all nested) (valid syntax)",] + ) + def test_JPP_0304(self, Description): + nReturn = CExecute.Execute("JPP_0304") + assert nReturn == 0 # -------------------------------------------------------------------------------------------------------------- diff --git a/test/pytest/pytestfiles/test_06_VALUE_DETECTION_BADCASE.py b/test/pytest/pytestfiles/test_06_VALUE_DETECTION_BADCASE.py index 1072ff51..f05ae9f6 100644 --- a/test/pytest/pytestfiles/test_06_VALUE_DETECTION_BADCASE.py +++ b/test/pytest/pytestfiles/test_06_VALUE_DETECTION_BADCASE.py @@ -18,7 +18,7 @@ # # XC-CT/ECA3-Queckenstedt # -# 17.08.2023 - 14:06:12 +# 13.09.2023 - 10:58:36 # # -------------------------------------------------------------------------------------------------------------- @@ -69,6 +69,22 @@ def test_JPP_0353(self, Description): def test_JPP_0354(self, Description): nReturn = CExecute.Execute("JPP_0354") assert nReturn == 0 +# -------------------------------------------------------------------------------------------------------------- + # Expected: No values are returned, and JsonPreprocessor throws an exception + @pytest.mark.parametrize( + "Description", ["JSON file with expression containing more opening elements '${' than closing elements '}' (invalid syntax 5)",] + ) + def test_JPP_0357(self, Description): + nReturn = CExecute.Execute("JPP_0357") + assert nReturn == 0 +# -------------------------------------------------------------------------------------------------------------- + # Expected: No values are returned, and JsonPreprocessor throws an exception + @pytest.mark.parametrize( + "Description", ["JSON file with expression containing more opening elements '${' than closing elements '}' (invalid syntax 6)",] + ) + def test_JPP_0359(self, Description): + nReturn = CExecute.Execute("JPP_0359") + assert nReturn == 0 # -------------------------------------------------------------------------------------------------------------- # Expected: No values are returned, and JsonPreprocessor throws an exception @pytest.mark.parametrize( @@ -77,4 +93,44 @@ def test_JPP_0354(self, Description): def test_JPP_0361(self, Description): nReturn = CExecute.Execute("JPP_0361") assert nReturn == 0 +# -------------------------------------------------------------------------------------------------------------- + # Expected: No values are returned, and JsonPreprocessor throws an exception + @pytest.mark.parametrize( + "Description", ["JSON file with expression starting with '${' and ending with '}', further matching '${' and '}' in between (not all nested) (invalid syntax 1)",] + ) + def test_JPP_0367(self, Description): + nReturn = CExecute.Execute("JPP_0367") + assert nReturn == 0 +# -------------------------------------------------------------------------------------------------------------- + # Expected: No values are returned, and JsonPreprocessor throws an exception + @pytest.mark.parametrize( + "Description", ["JSON file with expression starting with '${' and ending with '}', further matching '${' and '}' in between (not all nested) (invalid syntax 2)",] + ) + def test_JPP_0368(self, Description): + nReturn = CExecute.Execute("JPP_0368") + assert nReturn == 0 +# -------------------------------------------------------------------------------------------------------------- + # Expected: No values are returned, and JsonPreprocessor throws an exception + @pytest.mark.parametrize( + "Description", ["JSON file with expression starting with '${' and ending with '}', further matching '${' and '}' in between (not all nested) (invalid syntax 3)",] + ) + def test_JPP_0369(self, Description): + nReturn = CExecute.Execute("JPP_0369") + assert nReturn == 0 +# -------------------------------------------------------------------------------------------------------------- + # Expected: No values are returned, and JsonPreprocessor throws an exception + @pytest.mark.parametrize( + "Description", ["JSON file with expression starting with '${' and ending with '}', further matching '${' and '}' in between (not all nested) (invalid syntax 4)",] + ) + def test_JPP_0370(self, Description): + nReturn = CExecute.Execute("JPP_0370") + assert nReturn == 0 +# -------------------------------------------------------------------------------------------------------------- + # Expected: No values are returned, and JsonPreprocessor throws an exception + @pytest.mark.parametrize( + "Description", ["JSON file with expression starting with '${' and ending with '}', further matching '${' and '}' in between (not all nested) (invalid syntax 5)",] + ) + def test_JPP_0371(self, Description): + nReturn = CExecute.Execute("JPP_0371") + assert nReturn == 0 # -------------------------------------------------------------------------------------------------------------- diff --git a/test/pytest/pytestfiles/test_07_COMPOSITE_EXPRESSIONS_GOODCASE.py b/test/pytest/pytestfiles/test_07_COMPOSITE_EXPRESSIONS_GOODCASE.py index 87b5a53e..c7842aba 100644 --- a/test/pytest/pytestfiles/test_07_COMPOSITE_EXPRESSIONS_GOODCASE.py +++ b/test/pytest/pytestfiles/test_07_COMPOSITE_EXPRESSIONS_GOODCASE.py @@ -18,7 +18,7 @@ # # XC-CT/ECA3-Queckenstedt # -# 09.08.2023 - 17:28:15 +# 13.09.2023 - 10:58:36 # # -------------------------------------------------------------------------------------------------------------- @@ -37,6 +37,14 @@ class Test_COMPOSITE_EXPRESSIONS_GOODCASE: def test_JPP_0500(self, Description): nReturn = CExecute.Execute("JPP_0500") assert nReturn == 0 +# -------------------------------------------------------------------------------------------------------------- + # Expected: JsonPreprocessor returns expected value + @pytest.mark.parametrize( + "Description", ["JSON file with composite data structure (nested lists and dictionaries 2)",] + ) + def test_JPP_0501(self, Description): + nReturn = CExecute.Execute("JPP_0501") + assert nReturn == 0 # -------------------------------------------------------------------------------------------------------------- # Expected: JsonPreprocessor returns expected value @pytest.mark.parametrize( diff --git a/test/pytest/pytestfiles/test_08_COMPOSITE_EXPRESSIONS_BADCASE.py b/test/pytest/pytestfiles/test_08_COMPOSITE_EXPRESSIONS_BADCASE.py new file mode 100644 index 00000000..86ceae60 --- /dev/null +++ b/test/pytest/pytestfiles/test_08_COMPOSITE_EXPRESSIONS_BADCASE.py @@ -0,0 +1,40 @@ +# ************************************************************************************************************** +# Copyright 2020-2023 Robert Bosch GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# -------------------------------------------------------------------------------------------------------------- +# +# test_08_COMPOSITE_EXPRESSIONS_BADCASE.py +# +# XC-CT/ECA3-Queckenstedt +# +# 13.09.2023 - 10:58:36 +# +# -------------------------------------------------------------------------------------------------------------- + +import pytest +from pytestlibs.CExecute import CExecute + +# -------------------------------------------------------------------------------------------------------------- + +class Test_COMPOSITE_EXPRESSIONS_BADCASE: + +# -------------------------------------------------------------------------------------------------------------- + # Expected: No values are returned, and JsonPreprocessor throws an exception + @pytest.mark.parametrize( + "Description", ["JSON file with composite data structure (nested lists and dictionaries / some key names with dots inside)",] + ) + def test_JPP_0550(self, Description): + nReturn = CExecute.Execute("JPP_0550") + assert nReturn == 0 +# -------------------------------------------------------------------------------------------------------------- diff --git a/test/pytest/pytestfiles/test_08_COMMON_SYNTAX_VIOLATIONS_GOODCASE.py b/test/pytest/pytestfiles/test_09_COMMON_SYNTAX_VIOLATIONS_GOODCASE.py similarity index 96% rename from test/pytest/pytestfiles/test_08_COMMON_SYNTAX_VIOLATIONS_GOODCASE.py rename to test/pytest/pytestfiles/test_09_COMMON_SYNTAX_VIOLATIONS_GOODCASE.py index 334fddc2..d9a32821 100644 --- a/test/pytest/pytestfiles/test_08_COMMON_SYNTAX_VIOLATIONS_GOODCASE.py +++ b/test/pytest/pytestfiles/test_09_COMMON_SYNTAX_VIOLATIONS_GOODCASE.py @@ -14,11 +14,11 @@ # limitations under the License. # -------------------------------------------------------------------------------------------------------------- # -# test_08_COMMON_SYNTAX_VIOLATIONS_GOODCASE.py +# test_09_COMMON_SYNTAX_VIOLATIONS_GOODCASE.py # # XC-CT/ECA3-Queckenstedt # -# 09.08.2023 - 17:28:15 +# 13.09.2023 - 10:58:36 # # -------------------------------------------------------------------------------------------------------------- diff --git a/test/pytest/pytestfiles/test_09_COMMON_SYNTAX_VIOLATIONS_BADCASE.py b/test/pytest/pytestfiles/test_10_COMMON_SYNTAX_VIOLATIONS_BADCASE.py similarity index 97% rename from test/pytest/pytestfiles/test_09_COMMON_SYNTAX_VIOLATIONS_BADCASE.py rename to test/pytest/pytestfiles/test_10_COMMON_SYNTAX_VIOLATIONS_BADCASE.py index 1e972078..8a20da13 100644 --- a/test/pytest/pytestfiles/test_09_COMMON_SYNTAX_VIOLATIONS_BADCASE.py +++ b/test/pytest/pytestfiles/test_10_COMMON_SYNTAX_VIOLATIONS_BADCASE.py @@ -14,11 +14,11 @@ # limitations under the License. # -------------------------------------------------------------------------------------------------------------- # -# test_09_COMMON_SYNTAX_VIOLATIONS_BADCASE.py +# test_10_COMMON_SYNTAX_VIOLATIONS_BADCASE.py # # XC-CT/ECA3-Queckenstedt # -# 09.08.2023 - 17:28:15 +# 13.09.2023 - 10:58:36 # # -------------------------------------------------------------------------------------------------------------- diff --git a/test/pytest/pytestfiles/test_11_IMPLICIT_CREATION_GOODCASE.py b/test/pytest/pytestfiles/test_11_IMPLICIT_CREATION_GOODCASE.py new file mode 100644 index 00000000..21ea46e1 --- /dev/null +++ b/test/pytest/pytestfiles/test_11_IMPLICIT_CREATION_GOODCASE.py @@ -0,0 +1,40 @@ +# ************************************************************************************************************** +# Copyright 2020-2023 Robert Bosch GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# -------------------------------------------------------------------------------------------------------------- +# +# test_11_IMPLICIT_CREATION_GOODCASE.py +# +# XC-CT/ECA3-Queckenstedt +# +# 13.09.2023 - 10:58:36 +# +# -------------------------------------------------------------------------------------------------------------- + +import pytest +from pytestlibs.CExecute import CExecute + +# -------------------------------------------------------------------------------------------------------------- + +class Test_IMPLICIT_CREATION_GOODCASE: + +# -------------------------------------------------------------------------------------------------------------- + # Expected: JsonPreprocessor returns values + @pytest.mark.parametrize( + "Description", ["JSON file with dictionary keys to be created implicitly",] + ) + def test_JPP_1000(self, Description): + nReturn = CExecute.Execute("JPP_1000") + assert nReturn == 0 +# -------------------------------------------------------------------------------------------------------------- diff --git a/test/testconfig/TestConfig.py b/test/testconfig/TestConfig.py index 0de2208a..b7c3f251 100644 --- a/test/testconfig/TestConfig.py +++ b/test/testconfig/TestConfig.py @@ -22,7 +22,7 @@ # # -------------------------------------------------------------------------------------------------------------- # -# 07.09.2023 +# 13.09.2023 # # !!! Temporarily tests are deactivated by the following line commented out: # # # listofdictUsecases.append(dictUsecase) @@ -1976,6 +1976,27 @@ # dictUsecase['EXPECTEDRETURN'] = None # listofdictUsecases.append(dictUsecase) # del dictUsecase +# -------------------------------------------------------------------------------------------------------------- +# -------------------------------------------------------------------------------------------------------------- +dictUsecase = {} +dictUsecase['TESTID'] = "JPP_1000" +dictUsecase['DESCRIPTION'] = "JSON file with dictionary keys to be created implicitly" +dictUsecase['EXPECTATION'] = "JsonPreprocessor returns values" +dictUsecase['SECTION'] = "IMPLICIT_CREATION" +dictUsecase['SUBSECTION'] = "GOODCASE" +dictUsecase['HINT'] = None +dictUsecase['COMMENT'] = None +dictUsecase['JSONFILE'] = r"..\testfiles\jpp-test_config_1000.jsonp" +dictUsecase['EXPECTEDEXCEPTION'] = None +dictUsecase['EXPECTEDRETURN'] = """ +[DICT] (2/1) > {dTestDict} [DICT] (3/1) > {kVal_1} [STR] : 'Val_1' +[DICT] (2/1) > {dTestDict} [DICT] (3/2) > {kVal_2} [DICT] (1/1) > {I-am-not-existing-1} [DICT] (1/1) > {I-am-not-existing-2} [STR] : 'Val_1' +[DICT] (2/1) > {dTestDict} [DICT] (3/3) > {kVal_3} [DICT] (1/1) > {I-am-not-existing-3} [DICT] (1/1) > {I-am-not-existing-4} [STR] : 'Val_1' +[DICT] (2/2) > {Val_1} [STR] : 'Val_1' +""" +listofdictUsecases.append(dictUsecase) +del dictUsecase + diff --git a/test/testfiles/import/import.1/import.1.1/jpp-test_config_implicit_creation.1.1.1.jsonp b/test/testfiles/import/import.1/import.1.1/jpp-test_config_implicit_creation.1.1.1.jsonp new file mode 100644 index 00000000..c90a3199 --- /dev/null +++ b/test/testfiles/import/import.1/import.1.1/jpp-test_config_implicit_creation.1.1.1.jsonp @@ -0,0 +1,18 @@ +// Copyright 2020-2023 Robert Bosch GmbH +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//************************************************************************** + +{ + "${dTestDict.kVal_3.I-am-not-existing-3.I-am-not-existing-4}" : "${dTestDict}['kVal_2']['I-am-not-existing-1']['I-am-not-existing-2']" +} diff --git a/test/testfiles/import/import.1/jpp-test_config_implicit_creation.1.1.jsonp b/test/testfiles/import/import.1/jpp-test_config_implicit_creation.1.1.jsonp new file mode 100644 index 00000000..a8d6f60e --- /dev/null +++ b/test/testfiles/import/import.1/jpp-test_config_implicit_creation.1.1.jsonp @@ -0,0 +1,20 @@ +// Copyright 2020-2023 Robert Bosch GmbH +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//************************************************************************** + +{ + ${dTestDict}['kVal_2']['I-am-not-existing-1']['I-am-not-existing-2'] : ${dTestDict}['kVal_1'], + ${dTestDict.kVal_3.I-am-not-existing-3.I-am-not-existing-4} : ${dTestDict}['kVal_2']['I-am-not-existing-1']['I-am-not-existing-2'], + "[import]" : "./import.1.1/jpp-test_config_implicit_creation.1.1.1.jsonp" +} diff --git a/test/testfiles/import/jpp-test_config_implicit_creation.1.jsonp b/test/testfiles/import/jpp-test_config_implicit_creation.1.jsonp new file mode 100644 index 00000000..11d3414f --- /dev/null +++ b/test/testfiles/import/jpp-test_config_implicit_creation.1.jsonp @@ -0,0 +1,19 @@ +// Copyright 2020-2023 Robert Bosch GmbH +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//************************************************************************** + +{ + "dTestDict" : {"kVal_1" : "Val_1"}, + "[import]" : "./import.1/jpp-test_config_implicit_creation.1.1.jsonp" +} diff --git a/test/testfiles/jpp-test_config_1000.jsonp b/test/testfiles/jpp-test_config_1000.jsonp new file mode 100644 index 00000000..ee878c43 --- /dev/null +++ b/test/testfiles/jpp-test_config_1000.jsonp @@ -0,0 +1,18 @@ +// Copyright 2020-2023 Robert Bosch GmbH +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//************************************************************************** + +{ + "[import]" : "./import/jpp-test_config_implicit_creation.1.jsonp" +} From 51e48ea7e511743a095de1aa8d8c45ce75ca4538 Mon Sep 17 00:00:00 2001 From: qth2hi Date: Wed, 13 Sep 2023 14:44:05 +0200 Subject: [PATCH 3/4] Self test maintenance (log files) (to be aligned with self tests in other components) --- test/component_test.py | 3 +-- test/libs/CConfig.py | 57 ++++++++++++++++++++++++------------------ 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/test/component_test.py b/test/component_test.py index 6d93d514..0a6f89ea 100644 --- a/test/component_test.py +++ b/test/component_test.py @@ -22,7 +22,7 @@ # # -------------------------------------------------------------------------------------------------------------- # -VERSION = "0.8.0" +VERSION = "0.9.0" VERSION_DATE = "13.09.2023" # # -------------------------------------------------------------------------------------------------------------- @@ -403,7 +403,6 @@ def AnalyzeExceptions(EXPECTEDEXCEPTION=None, sException=None): EXPECTEDEXCEPTION = dictUsecase['EXPECTEDEXCEPTION'] EXPECTEDRETURN = dictUsecase['EXPECTEDRETURN'] - # TODO: make this depend on test case; in some BADCASE test cases this might not be wanted: JSONFILE = CString.NormalizePath(JSONFILE, sReferencePathAbs=TESTCONFIGPATH) # get optional parameters diff --git a/test/libs/CConfig.py b/test/libs/CConfig.py index def107b0..b8a6ea9d 100644 --- a/test/libs/CConfig.py +++ b/test/libs/CConfig.py @@ -20,7 +20,7 @@ # # XC-CT/ECA3-Queckenstedt # -# 03.08.2023 +# 13.09.2023 # # -------------------------------------------------------------------------------------------------------------- @@ -69,7 +69,7 @@ def __init__(self, sCalledBy=None): # -- configuration init self.__dictConfig = {} - # -- configuration: basic environment + # -- configuration: common environment THISSCRIPT = CString.NormalizePath(sCalledBy) self.__dictConfig['THISSCRIPT'] = THISSCRIPT @@ -77,14 +77,11 @@ def __init__(self, sCalledBy=None): REFERENCEPATH = os.path.dirname(THISSCRIPT) # position of main() script is reference for all relative paths self.__dictConfig['REFERENCEPATH'] = REFERENCEPATH self.__dictConfig['TESTCONFIGPATH'] = f"{REFERENCEPATH}/testconfig" # reference for all relative paths inside TestConfig.py - OSNAME = os.name - self.__dictConfig['OSNAME'] = OSNAME - PLATFORMSYSTEM = platform.system() - self.__dictConfig['PLATFORMSYSTEM'] = PLATFORMSYSTEM + self.__dictConfig['OSNAME'] = os.name + self.__dictConfig['PLATFORMSYSTEM'] = platform.system() PYTHON = CString.NormalizePath(sys.executable) self.__dictConfig['PYTHON'] = PYTHON - PYTHONPATH = os.path.dirname(PYTHON) - self.__dictConfig['PYTHONPATH'] = PYTHONPATH + self.__dictConfig['PYTHONPATH'] = os.path.dirname(PYTHON) self.__dictConfig['PYTHONVERSION'] = sys.version # -- configuration: command line @@ -103,38 +100,48 @@ def __init__(self, sCalledBy=None): TESTID = str(oCmdLineArgs.testid).strip() self.__dictConfig['TESTID'] = TESTID - bCodeDump = False + CODEDUMP = False if oCmdLineArgs.codedump != None: - bCodeDump = oCmdLineArgs.codedump - self.__dictConfig['CODEDUMP'] = bCodeDump + CODEDUMP = oCmdLineArgs.codedump + self.__dictConfig['CODEDUMP'] = CODEDUMP # if True: script quits after config dump - bConfigDump = False + CONFIGDUMP = False if oCmdLineArgs.configdump != None: - bConfigDump = oCmdLineArgs.configdump - self.__dictConfig['CONFIGDUMP'] = bConfigDump + CONFIGDUMP = oCmdLineArgs.configdump + self.__dictConfig['CONFIGDUMP'] = CONFIGDUMP # if True: script quits after config dump - bRecreateInstance = False + RECREATEINSTANCE = False if oCmdLineArgs.recreateinstance != None: - bRecreateInstance = oCmdLineArgs.recreateinstance - self.__dictConfig['RECREATEINSTANCE'] = bRecreateInstance + RECREATEINSTANCE = oCmdLineArgs.recreateinstance + self.__dictConfig['RECREATEINSTANCE'] = RECREATEINSTANCE + + # -- log file and output folders + sLogFileName = "JPP_SelfTest.log" + if TESTID is not None: + if ';' not in TESTID: + # in case of a single TESTID is given in command line, we add this ID to the log file name + # (support of pytest, where every test case is executed separately) + sLogFileName = f"JPP_SelfTest_{TESTID}.log" + + SELFTESTLOGFILE = f"{REFERENCEPATH}/testlogfiles/{sLogFileName}" - # self test log file: default settings - TESTLOGFILESFOLDER = f"{REFERENCEPATH}/testlogfiles" - SELFTESTLOGFILE = f"{TESTLOGFILESFOLDER}/JPP_SelfTest.log" if oCmdLineArgs.logfile != None: - SELFTESTLOGFILE = oCmdLineArgs.logfile - SELFTESTLOGFILE = CString.NormalizePath(SELFTESTLOGFILE, sReferencePathAbs=REFERENCEPATH) - TESTLOGFILESFOLDER = os.path.dirname(SELFTESTLOGFILE) + # command line overwrites default log file location + SELFTESTLOGFILE = CString.NormalizePath(oCmdLineArgs.logfile, sReferencePathAbs=REFERENCEPATH) + TESTLOGFILESFOLDER = os.path.dirname(SELFTESTLOGFILE) + # update default values in config + self.__dictConfig['SELFTESTLOGFILE'] = SELFTESTLOGFILE + self.__dictConfig['TESTLOGFILESFOLDER'] = TESTLOGFILESFOLDER + + # -- create output folder oFolder = CFolder(TESTLOGFILESFOLDER) bSuccess, sResult = oFolder.Create(bOverwrite=False, bRecursive=True) del oFolder if bSuccess is not True: raise Exception(CString.FormatResult(sMethod, bSuccess, sResult)) - self.__dictConfig['TESTLOGFILESFOLDER'] = TESTLOGFILESFOLDER - self.__dictConfig['SELFTESTLOGFILE'] = SELFTESTLOGFILE # dump of basic configuration parameters to console # self.DumpConfig() # done in main script now! From 7c1352a202813fc8968c13b8e223a19bbed8d108 Mon Sep 17 00:00:00 2001 From: mas2hc Date: Thu, 14 Sep 2023 17:17:54 +0700 Subject: [PATCH 4/4] Fixed the issue implicit creation of data structures fail --- JsonPreprocessor/CJsonPreprocessor.py | 62 +++++++++++++++------------ 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/JsonPreprocessor/CJsonPreprocessor.py b/JsonPreprocessor/CJsonPreprocessor.py index b02d5f71..d0b167d3 100644 --- a/JsonPreprocessor/CJsonPreprocessor.py +++ b/JsonPreprocessor/CJsonPreprocessor.py @@ -509,6 +509,32 @@ def __handleDotdictFormat(self, lInputListParams : list, lParams: list = []) -> else: return self.__handleDotdictFormat(lInputListParams, lParams) + def __checkAndCreateNewElement(self, sKey: str, value): + ''' + This method check and create new elements if they are not exist. + ''' + rootKey = re.sub("\[.*\]", "", sKey) + subElements = re.findall("\[\s*'([0-9A-Za-z_]+[0-9A-Za-z\.\-_]*)'\s*\]", sKey) + if len(subElements) <= 1: + return + else: + for index, element in enumerate(subElements): + if index < len(subElements) - 1: + rootKey = rootKey + "['" + element + "']" + sExec = "dumpData = " + rootKey + try: + exec(sExec) + except: + sExec = rootKey + " = {}" + try: + exec(sExec, globals()) + except Exception as error: + self.__reset() + errorMsg = f"Could not set variable '{sKey}' with value '{value}'! Reason: {error}" + raise Exception(errorMsg) + else: + continue + def __updateAndReplaceNestedParam(self, oJson : dict, bNested : bool = False, recursive : bool = False): ''' This method replaces all nested parameters in key and value of a json object . @@ -527,37 +553,11 @@ def __updateAndReplaceNestedParam(self, oJson : dict, bNested : bool = False, re Output Json object as dictionary with all variables resolved. ''' - def __checkAndCreateNewElement(sKey: str, value): - ''' - This method check and create new elements if they are not exist. - ''' - rootKey = re.sub("\[.*\]", "", sKey) - subElements = re.findall("\[\s*'([0-9A-Za-z_]+[0-9A-Za-z\.\-_]*)'\s*\]", sKey) - if len(subElements) <= 1: - return - else: - for index, element in enumerate(subElements): - if index < len(subElements) - 1: - rootKey = rootKey + "['" + element + "']" - sExec = "dumpData = " + rootKey - try: - exec(sExec) - except: - sExec = rootKey + " = {}" - try: - exec(sExec, globals()) - except Exception as error: - self.__reset() - errorMsg = f"Could not set variable '{sKey}' with value '{value}'! Reason: {error}" - raise Exception(errorMsg) - else: - continue - def __jsonUpdated(k, v, oJson, bNested, keyNested = ''): if keyNested != '': del oJson[keyNested] if '[' in k: - __checkAndCreateNewElement(k, v) + self.__checkAndCreateNewElement(k, v) sExec = k + " = \"" + v + "\"" if isinstance(v, str) else k + " = " + str(v) try: exec(sExec, globals()) @@ -941,6 +941,14 @@ def __handleListElements(sInput : str) -> str: oJson, bNested = self.__updateAndReplaceNestedParam(oJson) for k, v in self.dUpdatedParams.items(): if '[' in k: + rootElement = k.split('[', 1)[0] + if rootElement in oJson: + self.__checkAndCreateNewElement(k, v) + sExec = "oJson['" + rootElement + "'] = " + rootElement + try: + exec(sExec) + except: + pass if isinstance(v, str): sExec = "oJson['" + k.split('[', 1)[0] + "'][" + k.split('[', 1)[1] + " = \"" + v + "\"" else: