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
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.50.0"
VERSION_DATE = "06.11.2024"
VERSION = "0.51.0"
VERSION_DATE = "07.11.2024"
#
# --------------------------------------------------------------------------------------------------------------
#TM***
Expand Down
32 changes: 24 additions & 8 deletions test/testconfig/TestConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#
# --------------------------------------------------------------------------------------------------------------
#
# 06.11.2024
# 07.11.2024
#
# !!! Temporarily tests are deactivated by the following line commented out:
# # # listofdictUsecases.append(dictUsecase)
Expand Down Expand Up @@ -2865,7 +2865,7 @@
del dictUsecase
# --------------------------------------------------------------------------------------------------------------
dictUsecase = {}
dictUsecase['TESTID'] = "JPP_1103"
dictUsecase['TESTID'] = "JPP_1103" # similar to JPP_1111, but with simple data types
dictUsecase['DESCRIPTION'] = "JSON file import based on parameters (dynamic import (4))"
dictUsecase['EXPECTATION'] = "JsonPreprocessor returns values"
dictUsecase['SECTION'] = "FILE_IMPORTS"
Expand All @@ -2875,12 +2875,14 @@
dictUsecase['JSONFILE'] = r"..\testfiles\jpp-test_config_1103.jsonp"
dictUsecase['EXPECTEDEXCEPTION'] = None
dictUsecase['EXPECTEDRETURN'] = """
[DOTDICT] (6/1) > {AA} [STR] : 'AA'
[DOTDICT] (6/2) > {BB} [STR] : 'BB'
[DOTDICT] (6/3) > {CC} [STR] : 'CC'
[DOTDICT] (6/4) > {DD} [STR] : 'DD'
[DOTDICT] (6/5) > {level_up} [STR] : '../../../../'
[DOTDICT] (6/6) > {level} [STR] : 'DD.1'
[DOTDICT] (8/1) > {dynamic_imports} [STR] : 'dynamic_imports'
[DOTDICT] (8/2) > {global_defs} [STR] : 'global_defs'
[DOTDICT] (8/3) > {level_up} [STR] : '../../../../'
[DOTDICT] (8/4) > {AA} [STR] : 'AA'
[DOTDICT] (8/5) > {BB} [STR] : 'BB'
[DOTDICT] (8/6) > {CC} [STR] : 'CC'
[DOTDICT] (8/7) > {DD} [STR] : 'DD'
[DOTDICT] (8/8) > {level} [STR] : 'DD.1'
"""
listofdictUsecases.append(dictUsecase)
del dictUsecase
Expand Down Expand Up @@ -2990,6 +2992,20 @@
# # # listofdictUsecases.append(dictUsecase)
del dictUsecase
# --------------------------------------------------------------------------------------------------------------
dictUsecase = {}
dictUsecase['TESTID'] = "JPP_1111" # similar to JPP_1103, but with composite data types
dictUsecase['DESCRIPTION'] = "JSON file import based on parameters (dynamic import (7))"
dictUsecase['EXPECTATION'] = "JsonPreprocessor returns values"
dictUsecase['SECTION'] = "FILE_IMPORTS"
dictUsecase['SUBSECTION'] = "GOODCASE"
dictUsecase['HINT'] = None
dictUsecase['COMMENT'] = None
dictUsecase['JSONFILE'] = r"..\testfiles\jpp-test_config_1111.jsonp"
dictUsecase['EXPECTEDEXCEPTION'] = None # currently: 'maximum recursion depth exceeded while calling a Python object
dictUsecase['EXPECTEDRETURN'] = None
# # # listofdictUsecases.append(dictUsecase)
del dictUsecase
# --------------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------------
dictUsecase = {}
dictUsecase['TESTID'] = "JPP_1150"
Expand Down
8 changes: 5 additions & 3 deletions test/testfiles/jpp-test_config_1103.jsonp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
// limitations under the License.
//**************************************************************************
{
"[import]" : "./dynamic_imports/global_defs/global_defs_1.jsonp",
"level_up" : "../../../../",
"[import]" : "./dynamic_imports/${AA}/${BB}/${CC}/${DD}/${level_up}${AA}/${BB}/${CC}/${DD}/imported.DD.1.jsonp"
"dynamic_imports" : "dynamic_imports",
"global_defs" : "global_defs",
"level_up" : "../../../../",
"[import]" : "./${dynamic_imports}/${global_defs}/${global_defs}_1.jsonp",
"[import]" : "./${dynamic_imports}/${AA}/${BB}/${CC}/${DD}/${level_up}${AA}/${BB}/${CC}/${DD}/imported.DD.1.jsonp"
}
20 changes: 20 additions & 0 deletions test/testfiles/jpp-test_config_1111.jsonp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2020-2024 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.
//**************************************************************************
{
"dynamic_imports" : "dynamic_imports",
"global_defs" : "global_defs",
"[import]" : "./${dynamic_imports}/${global_defs}/${global_defs}_2.jsonp",
"[import]" : "./${imports_dir}/${dictDirs.AA}/${listDirs.1}/imported.BB.jsonp"
}
209 changes: 202 additions & 7 deletions test/testtools/GenSnippetsJPP.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#
# **************************************************************************************************************
#
VERSION = "0.31.0"
VERSION_DATE = "29.10.2024"
VERSION = "0.32.0"
VERSION_DATE = "07.11.2024"
#
# **************************************************************************************************************

Expand Down Expand Up @@ -105,7 +105,7 @@ def __init__(self, sCalledBy=None):
THISAPP = CString.NormalizePath(sCalledBy)
self.__dictConfig['THISAPP'] = THISAPP
self.__dictConfig['THISAPPNAME'] = os.path.basename(THISAPP)
REFERENCEPATH = os.path.dirname(THISAPP) # position of main() app is reference for all relative paths
REFERENCEPATH = os.path.dirname(THISAPP) # position of main() app is reference for all relative paths in this script
self.__dictConfig['REFERENCEPATH'] = REFERENCEPATH
self.__dictConfig['TMPFILESPATH'] = f"{REFERENCEPATH}/tmp_files"
self.__dictConfig['OUTPUTPATH'] = f"{REFERENCEPATH}" # /output
Expand All @@ -121,6 +121,21 @@ def __init__(self, sCalledBy=None):
self.__dictConfig['PYTHONVERSION'] = sys.version
self.__dictConfig['NOW'] = time.strftime('%d.%m.%Y - %H:%M:%S')

# JSONP snippets may contain the '[import]' key. For relative import paths we need to define a reference folder.
# We predefine three possible positions for reference folders that will be checked for existence. The first hit will be used.
JSONSNIPPET_REFERENCEPATH = None
listImportRootPaths = [REFERENCEPATH, f"{REFERENCEPATH}/..", f"{REFERENCEPATH}/../testfiles"]
importFolder = "dynamic_imports" # the subfolder containing all imported JSONP files
for sImportRootPath in listImportRootPaths:
sImportRootPath = CString.NormalizePath(sImportRootPath)
sImportPath = f"{sImportRootPath}/{importFolder}"
# print(f"checking additional import file path '{sImportFolder}'")
if os.path.isdir(sImportPath):
JSONSNIPPET_REFERENCEPATH = sImportRootPath
break
if JSONSNIPPET_REFERENCEPATH is not None:
self.__dictConfig['JSONSNIPPET_REFERENCEPATH'] = JSONSNIPPET_REFERENCEPATH

# --------------------------------------------------------------------------------------------------------------
#TM***

Expand Down Expand Up @@ -438,7 +453,7 @@ def __ExecuteJPPSnippets(self, sHeadline="UNKNOWN", listCodeSnippets=[]):
# dictReturned, sException, bSuccess, sResult = self.__ExecuteJPPFile(JPPJSONFILE)
#
# === (alternative 2) execute temporary JSON string
dictReturned, sException, bSuccess, sResult = self.__ExecuteJPPString(sCodeSnippet)
dictReturned, sException, bSuccess, sResult = self.__ExecuteJPPString(sCodeSnippet, self.__oConfig.Get('JSONSNIPPET_REFERENCEPATH'))
# --------------------------------------------------------------------------------------------------------------

# PrettyPrint(bSuccess, sPrefix="(bSuccess)")
Expand Down Expand Up @@ -516,7 +531,7 @@ def __ExecuteJPPFile(self, sJSONFile=None):

# eof def __ExecuteJPPFile(self, sJSONFile=None):

def __ExecuteJPPString(self, sJSONString=None):
def __ExecuteJPPString(self, sJSONString=None, referenceDir=""):

sMethod = "__ExecuteJPPString"

Expand All @@ -540,7 +555,7 @@ def __ExecuteJPPString(self, sJSONString=None):
dictReturned = None
sException = None
try:
dictReturned = oJsonPreprocessor.jsonLoads(sJSONString)
dictReturned = oJsonPreprocessor.jsonLoads(sJSONString, referenceDir)
except Exception as reason:
sException = f"'{reason}'"

Expand Down Expand Up @@ -3191,7 +3206,6 @@ def GetSeveralParticularSnippets(self):
}
""")


listCodeSnippets.append("""{
"A" : [1, 2],
"A" : [3, 4]
Expand All @@ -3216,6 +3230,187 @@ def GetSeveralParticularSnippets(self):
"listvalues" : [1, 2, 3],
"param" : ${listvalues}[+${index}]
}
""")

# --------------------------------------------------------------------------------------------------------------

# -- dynamic imports

listCodeSnippets.append("""{
"import_folder" : "dynamic_imports",
"file_name" : "imported.AA.jsonp",
"[import]" : "./${import_folder}/AA/${file_name}"
}
""")

listCodeSnippets.append("""{
"dictDirs" : {"AA" : "AA", "BB" : "BB", "CC" : "CC", "DD" : "DD"},
"listDirs" : ["AA", "BB", "CC", "DD"],
"[import]" : "./dynamic_imports/${dictDirs}['AA']/${listDirs}[1]/${dictDirs.CC}/${listDirs.3}/imported.${listDirs.3}.1.jsonp"
}
""")

listCodeSnippets.append("""{
"AA" : "AA",
"[import]" : "./dynamic_imports/${${${AA}}}/imported.${${${AA}}}.jsonp"
}
""")

listCodeSnippets.append("""{
"[import]" : "./dynamic_imports/global_defs/global_defs_1.jsonp",
"level_up" : "../../../../",
"[import]" : "./dynamic_imports/${AA}/${BB}/${CC}/${DD}/${level_up}${AA}/${BB}/${CC}/${DD}/imported.DD.1.jsonp"
}
""")

listCodeSnippets.append("""{
"dynamic_imports" : "dynamic_imports",
"global_defs" : "global_defs",
"level_up" : "../../../../",
"[import]" : "./${dynamic_imports}/${global_defs}/${global_defs}_1.jsonp",
"[import]" : "./${dynamic_imports}/${AA}/${BB}/${CC}/${DD}/${level_up}${AA}/${BB}/${CC}/${DD}/imported.DD.1.jsonp"
}
""")

listCodeSnippets.append("""{
"cwd" : ".",
"path_sep_1" : "/",
"path_sep_2" : "\\",
"[import]" : "${cwd}${path_sep_1}dynamic_imports${path_sep_2}AA${path_sep_1}imported.AA.jsonp"
}
""")

listCodeSnippets.append("""{
"P1" : "./dynamic",
"P2" : "_import",
"P3" : "s/AA/imp",
"P4" : "orted.A",
"P5" : "A.jsonp",
"[import]" : "${P1}${P2}${P3}${P4}${P5}"
}
""")

listCodeSnippets.append("""{
"[import]" : "./dynamic_imports/dynamic_import.R.D.jsonp"
}
""")

listCodeSnippets.append("""{
"[import]" : "./dynamic_imports/mixed_import.jsonp"
}
""")

listCodeSnippets.append("""{
"[import]" : "./dynamic_imports/parallel_import.jsonp"
}
""")

listCodeSnippets.append("""{
"import_files" : {
"fileAA" : "./dynamic_imports/AA/imported.AA.jsonp",
"fileBB" : "./dynamic_imports/AA/BB/imported.BB.jsonp"
},
"[import]" : ${import_files}['fileAA'],
"[import]" : "${import_files}['fileBB']"
}
""")

listCodeSnippets.append("""{
"import_files" : [
"./dynamic_imports/AA/imported.AA.jsonp",
"./dynamic_imports/AA/BB/imported.BB.jsonp"
],
"[import]" : ${import_files}[0],
"[import]" : "${import_files}[1]"
}
""")

listCodeSnippets.append("""{
"dynamic_imports" : "dynamic_imports",
"global_defs" : "global_defs",
"[import]" : "./${dynamic_imports}/${global_defs}/${global_defs}_2.jsonp",
"[import]" : "./${imports_dir}/${dictDirs.AA}/${listDirs.1}/imported.BB.jsonp"
}
""")

listCodeSnippets.append("""{
"imports_dir" : "dynamic_imports",
"[import]" : "./${imports_dir}/cyclic_import_itself.jsonp"
}
""")

listCodeSnippets.append("""{
"imports_dir" : "dynamic_imports",
"[import]" : "./${imports_dir}/cyclic_import.jsonp"
}
""")

listCodeSnippets.append("""{
"[import]" : "./${I_AM_NOT_EXISTING}/imported.jsonp"
}
""")

listCodeSnippets.append("""{
"[import]" : "./I_AM_NOT_EXISTING/I_AM_NOT_EXISTING.jsonp"
}
""")

listCodeSnippets.append("""{
"AA" : "AA",
"[import]" : "./dynamic_imports/${AA/imported.AA.jsonp"
}
""")

# !!! FREEZE !!!
# listCodeSnippets.append("""{
# "AA" : "AA",
# "[import]" : "./dynamic_imports/${${AA/imported.AA.jsonp"
# }
# """)

listCodeSnippets.append("""{
"AA" : "AA",
"[import]__" : "./dynamic_imports/${AA}/imported.${AA}.jsonp"
}
""")

listCodeSnippets.append("""{
"AA" : "AA",
"__[import]" : "./dynamic_imports/${AA}/imported.${AA}.jsonp"
}
""")

listCodeSnippets.append("""{
"AA" : "AA",
"[import]" : "./dynamic_imports/import_err_1.jsonp"
}
""")

listCodeSnippets.append("""{
"[import]" : 123
}
""")

listCodeSnippets.append("""{
"[import]" : [1,2,3]
}
""")

listCodeSnippets.append("""{
"[import]" : {"A" : 1, "B" : 2}
}
""")

listCodeSnippets.append("""{
"values" : {"A" : 1, "B" : 2},
"[import]" : ${values}['A']
}
""")

listCodeSnippets.append("""{
"values" : ["A", "B"],
"[import]" : ${values}[0]
}
""")

# listCodeSnippets.append("""{
Expand Down