diff --git a/JsonPreprocessor/JsonPreprocessor.pdf b/JsonPreprocessor/JsonPreprocessor.pdf index 2e05d68..b3c1f23 100644 Binary files a/JsonPreprocessor/JsonPreprocessor.pdf and b/JsonPreprocessor/JsonPreprocessor.pdf differ diff --git a/JsonPreprocessor/version.py b/JsonPreprocessor/version.py index 05969b4..760e491 100644 --- a/JsonPreprocessor/version.py +++ b/JsonPreprocessor/version.py @@ -18,5 +18,5 @@ # # Version and date of JsonPreprocessor # -VERSION = "0.9.3" -VERSION_DATE = "3.7.2025" +VERSION = "0.10.0" +VERSION_DATE = "25.07.2025" diff --git a/config/robotframework_aio/release_items_JsonPreprocessor.json b/config/robotframework_aio/release_items_JsonPreprocessor.json index a1fbc4f..5b3b5b5 100644 --- a/config/robotframework_aio/release_items_JsonPreprocessor.json +++ b/config/robotframework_aio/release_items_JsonPreprocessor.json @@ -1,6 +1,6 @@ # ************************************************************************************************************** # -# Copyright 2020-2023 Robert Bosch GmbH +# Copyright 2020-2025 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. @@ -202,6 +202,23 @@ This feature is an option. If the user does not define the parameter ``keyPatter * Improved and aligned error messages * Added and updated the self test according to the changed features " - ] + ], + "0.14.2.;0.15.0." : [ +" +**Python inline code** + +**JsonPreprocessor** enables to use Python inline code inside JSONP files. + +*Example* + +| ``\"A\" : [1,2,3],`` +| ``\"B\" : [4,5,6],`` +| ``\"C\" : <>`` + +*Result* + +| ``DotDict({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [1, 2, 3, 4, 5, 6]})`` +" + ] } } diff --git a/packagedoc/additional_docs/History.tex b/packagedoc/additional_docs/History.tex index cfb9b9e..6c50ac9 100644 --- a/packagedoc/additional_docs/History.tex +++ b/packagedoc/additional_docs/History.tex @@ -112,4 +112,7 @@ \historychange{- Allowed unicode digits to get a list element\newline - Updated error messages} +\historyversiondate{0.10.0}{07/2025} +\historychange{Added possibility to use Python inline code inside JSONP files} + \end{packagehistory} diff --git a/packagedoc/additional_docs/The JSONP format.tex b/packagedoc/additional_docs/The JSONP format.tex index 70e8748..09670c8 100644 --- a/packagedoc/additional_docs/The JSONP format.tex +++ b/packagedoc/additional_docs/The JSONP format.tex @@ -1188,8 +1188,6 @@ \section{Dynamic key names} A substitution in key names is not allowed! Please update the key name "${strval}_2" \end{pythonlog} - - % -------------------------------------------------------------------------------------------------------------- \newpage @@ -1369,12 +1367,49 @@ \section{Implicit creation of dictionaries}\label{implicit-creation} } \end{pythoncode} +% -------------------------------------------------------------------------------------------------------------- + +\newpage + +\section{Python inline code} + +It might be required to have access to Python builtin functions, e.g. for combining multiple lists into a single list. +In pure Python this can be realized in the following way: + +\begin{pythoncode} +A = [1,2,3] +B = [4,5,6] +C = A + B +print(C) +\end{pythoncode} + +With result: + +\begin{pythonlog} +[1, 2, 3, 4, 5, 6] +\end{pythonlog} + +In JSONP files, the implementation looks as follows: +\begin{pythoncode} +"A" : [1,2,3], +"B" : [4,5,6], +"C" : <\textless{}\textless{}>eval ${A} + ${B}<\textgreater{}\textgreater{}> +\end{pythoncode} +The expression \pcode{$\{A\} + $\{B\}} is handled as Python inline code. It is possible to use dollar operator expressions +inside Python inline code to access any other parameter defined in JSONP files. +\vspace{2ex} +The syntax of Python inline code is: +\begin{pythoncode} +<\textless{}\textless{}>eval <(\emph{Python expression})><\textgreater{}\textgreater{}> +\end{pythoncode} +The usage of Python inline code is limited to the right hand side of the colon (\emph{key values}). +This feature cannot be used to create key names. % -------------------------------------------------------------------------------------------------------------- diff --git a/test/JPP_TestUsecases.csv b/test/JPP_TestUsecases.csv index 4cbf5d3..89f68e5 100644 --- a/test/JPP_TestUsecases.csv +++ b/test/JPP_TestUsecases.csv @@ -202,3 +202,4 @@ JPP_2055|PARAMETER_SCOPE|BADCASE|JSON file containing a parameter with missing s JPP_2056|PARAMETER_SCOPE|BADCASE|JSON file containing a parameter with missing scope (7) JPP_2057|PARAMETER_SCOPE|BADCASE|JSON file containing a parameter with missing scope (8) JPP_2058|PARAMETER_SCOPE|BADCASE|JSON file containing a parameter with missing scope (9) +JPP_2100|INLINE_CODE|GOODCASE|JSON file containing Python inline code diff --git a/test/JPP_TestUsecases.html b/test/JPP_TestUsecases.html index d201679..5c61962 100644 --- a/test/JPP_TestUsecases.html +++ b/test/JPP_TestUsecases.html @@ -6737,12 +6737,47 @@ + + + + + +203 + + + + + +JPP_2100 + + + + +INLINE_CODE + + + + +GOODCASE + + + + +JSON file containing Python inline code
+Expected: JsonPreprocessor returns expected values +
+https://github.com/test-fullautomation/python-jsonpreprocessor/issues/454 +
+Test needs to be adapted after bugfixing +
+ +
 

-
Generated: 10.04.2025 - 17:21:06
+
Generated: 18.07.2025 - 16:02:56
 
diff --git a/test/JPP_TestUsecases.rst b/test/JPP_TestUsecases.rst index 51ec9ce..3a48202 100644 --- a/test/JPP_TestUsecases.rst +++ b/test/JPP_TestUsecases.rst @@ -2125,5 +2125,19 @@ Test Use Cases ---- -Generated: 10.04.2025 - 17:21:06 +* **Test JPP_2100** + + [INLINE_CODE / GOODCASE] + + **JSON file containing Python inline code** + + Expected: JsonPreprocessor returns expected values + + *Comment: https://github.com/test-fullautomation/python-jsonpreprocessor/issues/454* + + *Hint: Test needs to be adapted after bugfixing* + +---- + +Generated: 18.07.2025 - 16:02:56 diff --git a/test/JPP_TestUsecases.txt b/test/JPP_TestUsecases.txt index 73e9a1c..6c7bc27 100644 --- a/test/JPP_TestUsecases.txt +++ b/test/JPP_TestUsecases.txt @@ -868,5 +868,11 @@ Test JPP_2058 / PARAMETER_SCOPE / BADCASE Description: JSON file containing a parameter with missing scope (9) Expectation: No values are returned, and JsonPreprocessor throws an exception ------------------------------------------------------------------------------------------------------------------------ -Generated: 10.04.2025 - 17:21:06 +Test JPP_2100 / INLINE_CODE / GOODCASE +Description: JSON file containing Python inline code +Expectation: JsonPreprocessor returns expected values +Comment....: https://github.com/test-fullautomation/python-jsonpreprocessor/issues/454 +Hint.......: Test needs to be adapted after bugfixing +------------------------------------------------------------------------------------------------------------------------ +Generated: 18.07.2025 - 16:02:56 diff --git a/test/component_test.py b/test/component_test.py index 1ff943a..d198208 100644 --- a/test/component_test.py +++ b/test/component_test.py @@ -22,8 +22,8 @@ # # -------------------------------------------------------------------------------------------------------------- # -VERSION = "0.60.0" -VERSION_DATE = "23.04.2025" +VERSION = "0.61.0" +VERSION_DATE = "18.07.2025" # # -------------------------------------------------------------------------------------------------------------- #TM*** diff --git a/test/pytest/pytestfiles/test_27_INLINE_CODE_GOODCASE.py b/test/pytest/pytestfiles/test_27_INLINE_CODE_GOODCASE.py new file mode 100644 index 0000000..2d0decd --- /dev/null +++ b/test/pytest/pytestfiles/test_27_INLINE_CODE_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_27_INLINE_CODE_GOODCASE.py +# +# XC-HWP/ESW3-Queckenstedt +# +# 18.07.2025 - 16:02:56 +# +# -------------------------------------------------------------------------------------------------------------- + +import pytest +from pytestlibs.CExecute import CExecute + +# -------------------------------------------------------------------------------------------------------------- + +class Test_INLINE_CODE_GOODCASE: + +# -------------------------------------------------------------------------------------------------------------- + # Expected: JsonPreprocessor returns expected values + @pytest.mark.parametrize( + "Description", ["JSON file containing Python inline code",] + ) + def test_JPP_2100(self, Description): + nReturn = CExecute.Execute("JPP_2100") + assert nReturn == 0 +# -------------------------------------------------------------------------------------------------------------- diff --git a/test/testconfig/TestConfig.py b/test/testconfig/TestConfig.py index 2dd8b59..ddf952e 100644 --- a/test/testconfig/TestConfig.py +++ b/test/testconfig/TestConfig.py @@ -22,7 +22,7 @@ # # -------------------------------------------------------------------------------------------------------------- # -# 23.04.2025 +# 18.07.2025 # # !!! Temporarily tests are deactivated by the following line commented out: # # # listofdictUsecases.append(dictUsecase) @@ -4425,3 +4425,52 @@ del dictUsecase # -------------------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------------------- +dictUsecase = {} +dictUsecase['TESTID'] = "JPP_2100" +dictUsecase['DESCRIPTION'] = "JSON file containing Python inline code" +dictUsecase['EXPECTATION'] = "JsonPreprocessor returns expected values" +dictUsecase['SECTION'] = "INLINE_CODE" +dictUsecase['SUBSECTION'] = "GOODCASE" +dictUsecase['HINT'] = "Test needs to be adapted after bugfixing" +dictUsecase['COMMENT'] = "https://github.com/test-fullautomation/python-jsonpreprocessor/issues/454" +dictUsecase['JSONFILE'] = r"..\testfiles\jpp-test_config_2100.jsonp" +dictUsecase['EXPECTEDEXCEPTION'] = None +dictUsecase['EXPECTEDRETURN'] = """ +[DOTDICT] (18/1) > {A} [INT] : 0 +[DOTDICT] (18/2) > {B} [INT] : 1 +[DOTDICT] (18/3) > {L1} [LIST] (3/1) > [INT] : 1 +[DOTDICT] (18/3) > {L1} [LIST] (3/2) > [INT] : 2 +[DOTDICT] (18/3) > {L1} [LIST] (3/3) > [INT] : 3 +[DOTDICT] (18/4) > {L2} [LIST] (3/1) > [INT] : 4 +[DOTDICT] (18/4) > {L2} [LIST] (3/2) > [INT] : 5 +[DOTDICT] (18/4) > {L2} [LIST] (3/3) > [INT] : 6 +[DOTDICT] (18/5) > {kA} [STR] : 'kA' +[DOTDICT] (18/6) > {kB} [STR] : 'kB' +[DOTDICT] (18/7) > {D1} [DOTDICT] (2/1) > {kA} [STR] : 'vA' +[DOTDICT] (18/7) > {D1} [DOTDICT] (2/2) > {kB} [STR] : 'vB' +[DOTDICT] (18/8) > {choice} [BOOL] : True +[DOTDICT] (18/9) > {value01} [INT] : 10 +[DOTDICT] (18/10) > {value02} [LIST] (2/1) > [INT] : 1 +[DOTDICT] (18/10) > {value02} [LIST] (2/2) > [INT] : 2 +[DOTDICT] (18/11) > {value04} [INT] : 4 +[DOTDICT] (18/12) > {code04} [STR] : '0 if True else 1' +[DOTDICT] (18/13) > {value04b} [INT] : 4 +[DOTDICT] (18/14) > {value05} [INT] : 5 +[DOTDICT] (18/15) > {code05} [STR] : '0 if not True else 1' +[DOTDICT] (18/16) > {value05b} [INT] : 5 +[DOTDICT] (18/17) > {values01} [DOTDICT] (3/1) > {kA} [STR] : 'A' +[DOTDICT] (18/17) > {values01} [DOTDICT] (3/2) > {kB} [INT] : 0 +[DOTDICT] (18/17) > {values01} [DOTDICT] (3/3) > {kC} [STR] : 'Z' +[DOTDICT] (18/18) > {values02} [LIST] (4/1) > [INT] : 1 +[DOTDICT] (18/18) > {values02} [LIST] (4/2) > [INT] : 2 +[DOTDICT] (18/18) > {values02} [LIST] (4/3) > [INT] : 3 +[DOTDICT] (18/18) > {values02} [LIST] (4/4) > [LIST] (6/1) > [INT] : 4 +[DOTDICT] (18/18) > {values02} [LIST] (4/4) > [LIST] (6/2) > [INT] : 5 +[DOTDICT] (18/18) > {values02} [LIST] (4/4) > [LIST] (6/3) > [INT] : 6 +[DOTDICT] (18/18) > {values02} [LIST] (4/4) > [LIST] (6/4) > [INT] : 1 +[DOTDICT] (18/18) > {values02} [LIST] (4/4) > [LIST] (6/5) > [INT] : 2 +[DOTDICT] (18/18) > {values02} [LIST] (4/4) > [LIST] (6/6) > [INT] : 3 +""" +listofdictUsecases.append(dictUsecase) +del dictUsecase +# -------------------------------------------------------------------------------------------------------------- diff --git a/test/testfiles/jpp-test_config_2100.jsonp b/test/testfiles/jpp-test_config_2100.jsonp new file mode 100644 index 0000000..1fa3aa9 --- /dev/null +++ b/test/testfiles/jpp-test_config_2100.jsonp @@ -0,0 +1,48 @@ +// Copyright 2020-2025 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 needs to be adapted after bugfixing + // https://github.com/test-fullautomation/python-jsonpreprocessor/issues/454 + // + "A" : 0, + "B" : 1, + "L1" : [1,2,3], + "L2" : [4,5,6], + "kA" : "kA", + "kB" : "kB", + "D1" : {"kA" : "vA", "kB" : "vB"}, + "choice" : True, + // + "value01" : <>, + "value02" : <>, + // !err! "value03" : <>, + // + "value04" : <>, + "code04" : "${A} if ${choice} else ${B}", + "value04b" : <>, + "value05" : <>, + "code05" : "${A} if not ${choice} else ${B}", + "value05b" : <>, + // + "values01" : {"kA" : "A", + "kB" : <>, + "kC" : "Z"}, + // + "values02" : <> + // + // !err! "value06" : ${L1}[<>] + // + // !err! "value07" : ${D1}[<>] +}