Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified JsonPreprocessor/JsonPreprocessor.pdf
Binary file not shown.
4 changes: 2 additions & 2 deletions JsonPreprocessor/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link

Copilot AI Jul 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version date (25.07.2025) is inconsistent with other files in this PR which use 18.07.2025. Consider using a consistent date across all version updates.

Suggested change
VERSION_DATE = "25.07.2025"
VERSION_DATE = "18.07.2025"

Copilot uses AI. Check for mistakes.
21 changes: 19 additions & 2 deletions config/robotframework_aio/release_items_JsonPreprocessor.json
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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\" : <<eval ${A} + ${B}>>``

*Result*

| ``DotDict({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [1, 2, 3, 4, 5, 6]})``
"
]
}
}
3 changes: 3 additions & 0 deletions packagedoc/additional_docs/History.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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}
39 changes: 37 additions & 2 deletions packagedoc/additional_docs/The JSONP format.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.


% --------------------------------------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions test/JPP_TestUsecases.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
37 changes: 36 additions & 1 deletion test/JPP_TestUsecases.html
Original file line number Diff line number Diff line change
Expand Up @@ -6737,12 +6737,47 @@
</i></font></td>


</tr>
<tr valign="middle" align="left">
<td colspan="1" valign="center" bgcolor="#F5F5F5" align="right">
<font size="2" face="Arial" color="#FF0000">
<b>
203
</b></font></td>

<td colspan="1" valign="center" bgcolor="#F5F5F5" align="middle">
<font size="2" face="Arial" color="#595959">
<b>
<a target="_blank" href="https://github.com/test-fullautomation/python-jsonpreprocessor/blob/develop/test/testfiles/jpp-test_config_2100.jsonp">JPP_2100</a>
</b></font></td>

<td colspan="1" valign="center" bgcolor="#F5F5F5" align="middle">
<font size="2" face="Arial" color="#4169E1">
INLINE_CODE
</font></td>

<td colspan="1" valign="center" bgcolor="#F5F5F5" align="middle">
<font size="2" face="Arial" color="#008000">
GOODCASE
</font></td>

<td colspan="1" valign="center" bgcolor="#F5F5F5" align="left">
<font size="2" face="Arial" color="#595959"><i>
<b>JSON file containing Python inline code</b><br>
Expected: JsonPreprocessor returns expected values
<br>
https://github.com/test-fullautomation/python-jsonpreprocessor/issues/454
<br>
Test needs to be adapted after bugfixing
</i></font></td>


</tr>

</tbody></table></div>
<div>&nbsp;</div>
<hr width="100%" color="#FF8C00" align="center">
<div align="center"><font size="2" color="#27408B">Generated: 10.04.2025 - 17:21:06</font></div>
<div align="center"><font size="2" color="#27408B">Generated: 18.07.2025 - 16:02:56</font></div>
<div>&nbsp;</div>
</body></html>

16 changes: 15 additions & 1 deletion test/JPP_TestUsecases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

8 changes: 7 additions & 1 deletion test/JPP_TestUsecases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

4 changes: 2 additions & 2 deletions test/component_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#
# --------------------------------------------------------------------------------------------------------------
#
VERSION = "0.60.0"
VERSION_DATE = "23.04.2025"
VERSION = "0.61.0"
VERSION_DATE = "18.07.2025"
#
# --------------------------------------------------------------------------------------------------------------
#TM***
Expand Down
40 changes: 40 additions & 0 deletions test/pytest/pytestfiles/test_27_INLINE_CODE_GOODCASE.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# **************************************************************************************************************
# Copyright 2020-2023 Robert Bosch GmbH
Copy link

Copilot AI Jul 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyright year range should be updated to 2020-2025 to match other files in the PR.

Suggested change
# Copyright 2020-2023 Robert Bosch GmbH
# Copyright 2020-2025 Robert Bosch GmbH

Copilot uses AI. Check for mistakes.
#
# 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
# --------------------------------------------------------------------------------------------------------------
51 changes: 50 additions & 1 deletion test/testconfig/TestConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#
# --------------------------------------------------------------------------------------------------------------
#
# 23.04.2025
# 18.07.2025
#
# !!! Temporarily tests are deactivated by the following line commented out:
# # # listofdictUsecases.append(dictUsecase)
Expand Down Expand Up @@ -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
# --------------------------------------------------------------------------------------------------------------
48 changes: 48 additions & 0 deletions test/testfiles/jpp-test_config_2100.jsonp
Original file line number Diff line number Diff line change
@@ -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" : <<eval 10>>,
"value02" : <<eval [1,2]>>,
// !err! "value03" : <<eval {"A" : 1, "B" : 2}>>,
//
"value04" : <<eval (${A} if ${choice} else ${B}) + 4>>,
"code04" : "${A} if ${choice} else ${B}",
"value04b" : <<eval (${code04}) + 4>>,
"value05" : <<eval (${A} if not ${choice} else ${B}) + 4>>,
"code05" : "${A} if not ${choice} else ${B}",
"value05b" : <<eval (${code05}) + 4>>,
//
"values01" : {"kA" : "A",
"kB" : <<eval ${A} if ${choice} else ${B}>>,
"kC" : "Z"},
//
"values02" : <<eval ${L1} + [${L2} + ${L1}]>>
//
// !err! "value06" : ${L1}[<<eval ${A} if ${choice} else ${B}>>]
//
// !err! "value07" : ${D1}[<<eval "${kA}" if ${choice} else "${kB}">>]
}