diff --git a/JsonPreprocessor/CJsonPreprocessor.py b/JsonPreprocessor/CJsonPreprocessor.py index aa88d60b..5301cd22 100644 --- a/JsonPreprocessor/CJsonPreprocessor.py +++ b/JsonPreprocessor/CJsonPreprocessor.py @@ -55,6 +55,7 @@ from PythonExtensionsCollection.String.CString import CString from enum import Enum +from JsonPreprocessor.version import VERSION, VERSION_DATE class CSyntaxType(): python = "python" @@ -173,6 +174,12 @@ class CJsonPreprocessor(): - Allow Python data types ``True``, ``False`` and ``None`` """ + def getVersion(self): + return VERSION + + def getVersionDate(self): + return VERSION_DATE + def __init__(self, syntax: CSyntaxType = CSyntaxType.python , currentCfg : dict = {}) -> None: """ Constructor @@ -958,7 +965,7 @@ def __recursiveNestedHandling(sInputStr: str, lNestedParam: list) -> str: self.lNestedParams.append(nestedParam) newInputStr = newInputStr + item if tmpItem==items[len(items)-1] else newInputStr + item + "," sInputStr = newInputStr - elif re.search("\${\s*}", sInputStr) or re.search("\${.+}\.", sInputStr) \ + elif re.search("\${\s*}", sInputStr) \ or (nestedKey and (sInputStr.count("{") != sInputStr.count("}") or sInputStr.count("[") != sInputStr.count("]"))): self.__reset(bCleanGlobalVars=True) raise Exception(f"Invalid parameter format: {sInputStr}") diff --git a/JsonPreprocessor/JsonPreprocessor.pdf b/JsonPreprocessor/JsonPreprocessor.pdf index d14e5a3a..fd5849bd 100644 Binary files a/JsonPreprocessor/JsonPreprocessor.pdf and b/JsonPreprocessor/JsonPreprocessor.pdf differ diff --git a/JsonPreprocessor/version.py b/JsonPreprocessor/version.py index 55c6035b..361bd6ce 100644 --- a/JsonPreprocessor/version.py +++ b/JsonPreprocessor/version.py @@ -18,6 +18,6 @@ # # Version and date of JsonPreprocessor # -VERSION = "0.3.2" -VERSION_DATE = "17.01.2024" +VERSION = "0.3.3" +VERSION_DATE = "23.01.2024" diff --git a/config/robotframework_aio/release_items_JsonPreprocessor.json b/config/robotframework_aio/release_items_JsonPreprocessor.json index e26f3a94..9065d4b9 100644 --- a/config/robotframework_aio/release_items_JsonPreprocessor.json +++ b/config/robotframework_aio/release_items_JsonPreprocessor.json @@ -57,6 +57,7 @@ json_preprocessor = CJsonPreprocessor() json_preprocessor.jsonDump(dictTest, \"./OutputFile.json\") +* Added ``getVersion`` and ``getVersionDate`` methods to get current version and the date of the version. * Improved format of nested parameters; improved error messages * Some bugs fixed in implicitly created data structures * Improved index handling together with nested parameters diff --git a/packagedoc/additional_docs/History.tex b/packagedoc/additional_docs/History.tex index 86b8eb48..24896b64 100644 --- a/packagedoc/additional_docs/History.tex +++ b/packagedoc/additional_docs/History.tex @@ -41,9 +41,10 @@ - Fix bugs of data structures implicitly\newline - Improve index handling together with nested parameters} -\historyversiondate{0.3.2}{01/2024} +\historyversiondate{0.3.3}{01/2024} \historychange{- Some bugs fixed in implicitly created data structures\newline - Improved index handling together with nested parameters\newline -- Improved format of nested parameters; improved error messages} +- Improved format of nested parameters; improved error messages\newline +- Added getVersion and getVersionDate methods to get current version and the date of the version} \end{packagehistory} diff --git a/packagedoc/additional_docs/The JSONP format.tex b/packagedoc/additional_docs/The JSONP format.tex index b92ccb1d..af89857d 100644 --- a/packagedoc/additional_docs/The JSONP format.tex +++ b/packagedoc/additional_docs/The JSONP format.tex @@ -1191,5 +1191,75 @@ \section{Implicite creation of dictionaries} {'paramA': 'ABC', 'subKey': 'ABC', 'testdict': {'subKey': {'subKey': {'paramA': 'DEF'}}}} \end{pythonlog} +\vspace{2ex} + +\textbf{Reference to existing keys} + +It is possible to use parameters to refer to \textit{already existing} keys. + +\begin{pythoncode} +{ + // + ${testdict.subKey_1.subKey_2.subKey_3} : "ABC", + + // + "keyName_3" : "subKey_3", + + // + ${testdict.subKey_1.subKey_2.${keyName_3}} : "XYZ" +} +\end{pythoncode} + +\vspace{2ex} + +\textbf{Outcome:} + +\begin{pythonlog} +{'keyName_3': 'subKey_3', + 'testdict': {'subKey_1': {'subKey_2': {'subKey_3': 'XYZ'}}}} +\end{pythonlog} + +\vspace{2ex} + +Parameters cannot be used to create new keys. + +\begin{pythoncode} +{ + // + ${testdict.subKey_1.subKey_2.subKey_3} : "ABC", + + // + "keyName_4" : "subKey_4", + + // + ${testdict.subKey_1.subKey_2.subKey_3.${keyName_4}} : "XYZ" +} +\end{pythoncode} + +\vspace{2ex} + +\textbf{Outcome is the following error:} + +\begin{pythonlog} +"The implicit creation of data structures based on nested parameter is not supported ..." +\end{pythonlog} + +The same error will happen in case of the standard notation is used: + +\begin{pythoncode} +{ + // + ${testdict}['subKey_1']['subKey_2']['subKey_3'][${keyName_4}] : "XYZ" +} +\end{pythoncode} + + + + + + + + + % -------------------------------------------------------------------------------------------------------------- diff --git a/test/testfiles/jpp-test_config_1002.jsonp b/test/testfiles/jpp-test_config_1002.jsonp index fe94987c..079052fb 100644 --- a/test/testfiles/jpp-test_config_1002.jsonp +++ b/test/testfiles/jpp-test_config_1002.jsonp @@ -31,10 +31,11 @@ "paramD" : "D", "paramE" : "E", ${testdict_3.paramD.paramE.paramD} : {"E" : 5}, - ${testdict_3.paramD.paramE.paramD}[${paramE}] : {"F" : 6} // if not implicit, usage of parameters for key names is allowed // - // needs to be clarified (currently throws an implicit creation error) - // ${testdict_4} : {}, - // ${testdict_4}[${paramD}] : {"G" : 7} + // usage of parameters allowed only in case of a key with this name already exists + + + + ${testdict_3.paramD.paramE.paramD}[${paramE}] : {"F" : 6} // ${paramE} is accepted because the value is "E" and a key with this name already exists } diff --git a/test/testfiles/jpp-test_config_1051.jsonp b/test/testfiles/jpp-test_config_1051.jsonp index 1d63e26b..766b2245 100644 --- a/test/testfiles/jpp-test_config_1051.jsonp +++ b/test/testfiles/jpp-test_config_1051.jsonp @@ -15,7 +15,7 @@ { "testdict" : {"A" : 1}, - "name" : "C", + "name" : "C", ${testdict.B.${name}} : 2 } diff --git a/test/testfiles/jpp-test_config_1052.jsonp b/test/testfiles/jpp-test_config_1052.jsonp index 4028d7da..90940d10 100644 --- a/test/testfiles/jpp-test_config_1052.jsonp +++ b/test/testfiles/jpp-test_config_1052.jsonp @@ -15,7 +15,7 @@ { "testdict" : {"A" : 1}, - "name" : "C", + "name" : "C", ${testdict}['${name}']['${name}'] : 2 } diff --git a/test/testfiles/jpp-test_config_1053.jsonp b/test/testfiles/jpp-test_config_1053.jsonp index 29b69f56..3e0620ea 100644 --- a/test/testfiles/jpp-test_config_1053.jsonp +++ b/test/testfiles/jpp-test_config_1053.jsonp @@ -14,7 +14,7 @@ //************************************************************************** { - "name" : "C", + "name" : "C", "testdict2" : {"B" : 2}, ${somethingnotexisting.${testdict2}}['${name}'] : 4 } diff --git a/test/testfiles/jpp-test_config_1054.jsonp b/test/testfiles/jpp-test_config_1054.jsonp index 60fcd02e..5faab86a 100644 --- a/test/testfiles/jpp-test_config_1054.jsonp +++ b/test/testfiles/jpp-test_config_1054.jsonp @@ -14,7 +14,7 @@ //************************************************************************** { - "name" : "C", + "name" : "C", "testdict" : {"B" : 2}, ${testdict.${testdict}}['${name}'] : 4 } diff --git a/test/testfiles/jpp-test_config_1055.jsonp b/test/testfiles/jpp-test_config_1055.jsonp index 4bd33f3b..7ec80248 100644 --- a/test/testfiles/jpp-test_config_1055.jsonp +++ b/test/testfiles/jpp-test_config_1055.jsonp @@ -14,7 +14,7 @@ //************************************************************************** { - "name" : "C", + "name" : "C", "testlist" : ["B", 2], ${testlist.${testlist}}['${name}'] : 4 } diff --git a/test/testfiles/jpp-test_config_1056.jsonp b/test/testfiles/jpp-test_config_1056.jsonp index f96893a0..1dbab24c 100644 --- a/test/testfiles/jpp-test_config_1056.jsonp +++ b/test/testfiles/jpp-test_config_1056.jsonp @@ -15,7 +15,7 @@ { "testdict" : {"A" : 1}, - "name" : "C", + "name" : "C", ${testdict.${name}}['${name}'] : 5 } diff --git a/test/testfiles/jpp-test_config_1057.jsonp b/test/testfiles/jpp-test_config_1057.jsonp index 00f03ef0..9027cd19 100644 --- a/test/testfiles/jpp-test_config_1057.jsonp +++ b/test/testfiles/jpp-test_config_1057.jsonp @@ -15,7 +15,7 @@ { "testdict" : {"A" : 1}, - "name" : "C", + "name" : "C", ${testdict}[${name}][${name}] : 4 } diff --git a/test/testfiles/jpp-test_config_1058.jsonp b/test/testfiles/jpp-test_config_1058.jsonp index 49e1a75e..41c6db28 100644 --- a/test/testfiles/jpp-test_config_1058.jsonp +++ b/test/testfiles/jpp-test_config_1058.jsonp @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. //************************************************************************** + { "testdict" : {"A" : 1}, "name" : "C",