Skip to content

Commit

Permalink
Merge pull request #394 from test-fullautomation/namsonx/task/stabi_b…
Browse files Browse the repository at this point in the history
…ranch

Namsonx/task/stabi branch
  • Loading branch information
test-fullautomation authored Nov 27, 2024
2 parents 86dd7af + 4dfa4e8 commit d294a0e
Show file tree
Hide file tree
Showing 35 changed files with 1,363 additions and 104 deletions.
33 changes: 23 additions & 10 deletions JsonPreprocessor/CJsonPreprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ def __processImportFiles(self, input_data : dict) -> dict:
for key, value in input_data:
if re.match('^\s*\[\s*import\s*\]\s*', key.lower()):
if not isinstance(value, str):
errorMsg = f"The value of [import] parameter must be 'str' but receiving the value '{value}'"
typeValue = re.search(r"^<class\s*('.+')>$", str(type(value)))
typeValue = typeValue[1] if typeValue is not None else type(value)
errorMsg = f"The [import] key requires a value of type 'str', but the type is {typeValue}"
self.__reset()
raise Exception(errorMsg)
if '${' in value:
Expand All @@ -299,8 +301,6 @@ def __processImportFiles(self, input_data : dict) -> dict:
out_dict[key] = value
if '${' not in value:
if re.match(r'^\[\s*import\s*\]_\d+$', key):
if value in self.lDynamicImports:
raise Exception(f"Cyclic imported json file '{value}'!")
dynamicIpmportIndex = re.search(r'_(\d+)$', key)[1]
self.lDynamicImports[int(dynamicIpmportIndex)-1] = value
currJsonPath = self.jsonPath
Expand All @@ -316,6 +316,11 @@ def __processImportFiles(self, input_data : dict) -> dict:
raise Exception(f"Cyclic imported json file '{abs_path_file}'!")

oJsonImport = self.jsonLoad(abs_path_file)
bDynamicImportCheck = False
for k, v in oJsonImport.items():
if re.match('^\s*\[\s*import\s*\]\s*', k) and '${' in v:
bDynamicImportCheck = True
break
self.jsonPath = currJsonPath
tmpOutdict = copy.deepcopy(out_dict)
for k1, v1 in tmpOutdict.items():
Expand All @@ -324,8 +329,8 @@ def __processImportFiles(self, input_data : dict) -> dict:
del out_dict[k1]
del tmpOutdict
out_dict.update(oJsonImport)

self.recursive_level = self.recursive_level - 1 # descrease recursive level
if not bDynamicImportCheck:
self.recursive_level = self.recursive_level - 1 # descrease recursive level
else:
if not self.bJSONPreCheck:
specialCharacters = r'$[]{}'
Expand Down Expand Up @@ -1201,16 +1206,22 @@ def __handleList(lInput : list, bNested : bool) -> list:
if re.search(r'\${.+\..+}', v):
paramInValue = self.__handleDotInNestedParam(v)
paramInValue = self.__multipleReplace(paramInValue, {'${':'', '}':''})
# Check datatype of [import] value
if re.match(r'^\[\s*import\s*\]_\d+$', k):
dynamicImported = re.search(rf'^(.*){CNameMangling.DYNAMICIMPORTED.value}(.*)$', v)
importValue = dynamicImported[2]
importValue = __loadNestedValue(importValue, importValue)
if not isinstance(importValue, str):
typeValue = re.search(r"^<class\s*('.+')>$", str(type(importValue)))
typeValue = typeValue[1] if typeValue is not None else type(importValue)
errorMsg = f"The [import] key requires a value of type 'str', but the type is {typeValue}"
self.__reset()
raise Exception(errorMsg)
v = __loadNestedValue(initValue, v, key=k)
# Handle dynamic import value
if re.match(r'^\[\s*import\s*\]_\d+$', k):
if '${' not in v and CNameMangling.DYNAMICIMPORTED.value in v:
dynamicImported = re.search(rf'^(.*){CNameMangling.DYNAMICIMPORTED.value}(.*)$', v)
if re.match(r'^[\d\.]+$', dynamicImported[2]) or \
re.search(r'(\[[^\[]+\])|(\([^\(]+\))|({[^{]+})', dynamicImported[2]):
errorMsg = f"The value of [import] parameter must be 'str' but receiving the value '{dynamicImported[2]}'"
self.__reset()
raise Exception(errorMsg)
if re.match(r'^[/|\\].+$', dynamicImported[2]):
v = dynamicImported[2]
else:
Expand Down Expand Up @@ -1858,6 +1869,8 @@ def __handleLastElement(sInput : str) -> str:
self.bJSONPreCheck = True
sDummyData = self.__preCheckJsonFile(sJsonDataUpdated, CJSONDecoder)
self.iDynamicImport = 0
self.recursive_level = 0
self.lImportedFiles = [] if self.masterFile is None else [self.masterFile]
self.bJSONPreCheck = False

# Load Json object with checking duplicated keys feature is enabled.
Expand Down
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,6 +18,6 @@
#
# Version and date of JsonPreprocessor
#
VERSION = "0.8.2"
VERSION_DATE = "30.10.2024"
VERSION = "0.8.3"
VERSION_DATE = "25.11.2024"

3 changes: 3 additions & 0 deletions packagedoc/additional_docs/History.tex
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,7 @@
\historyversiondate{0.8.2}{10/2024}
\historychange{- Enhanced import JSON file feature which allows dynamic path of imported file}

\historyversiondate{0.8.3}{11/2024}
\historychange{- Fixed bugs and updated error messages related to dynamic imports}

\end{packagehistory}
12 changes: 12 additions & 0 deletions test/JPP_TestUsecases.csv
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,25 @@ JPP_1108|FILE_IMPORTS|GOODCASE|JSON file import based on parameters (dynamic imp
JPP_1109|FILE_IMPORTS|GOODCASE|JSON file import based on dictionary key values
JPP_1110|FILE_IMPORTS|GOODCASE|JSON file import based on list elemens
JPP_1111|FILE_IMPORTS|GOODCASE|JSON file import based on parameters (dynamic import (7))
JPP_1112|FILE_IMPORTS|GOODCASE|JSON file containing an import of the same file in different levels (within the same file)
JPP_1113|FILE_IMPORTS|GOODCASE|JSON file containing an import of the same file in different levels (within imported files)
JPP_1150|FILE_IMPORTS|BADCASE|JSON file with cyclic imports (JSON file imports itself, fix path)
JPP_1151|FILE_IMPORTS|BADCASE|JSON file with cyclic imports (JSON file imports another file, that is already imported, fix path)
JPP_1152|FILE_IMPORTS|BADCASE|JSON file with cyclic imports (JSON file imports itself, dynamic path)
JPP_1153|FILE_IMPORTS|BADCASE|JSON file with cyclic imports (JSON file imports another file, that is already imported, dynamic path)
JPP_1154|FILE_IMPORTS|BADCASE|JSON file with not existing parameter within dynamic import path
JPP_1155|FILE_IMPORTS|BADCASE|JSON file with not existing import file
JPP_1156|FILE_IMPORTS|BADCASE|JSON file with syntax error in import path (1)
JPP_1157|FILE_IMPORTS|BADCASE|JSON file with syntax error in import path (2)
JPP_1158|FILE_IMPORTS|BADCASE|JSON file with error in [import] key (1)
JPP_1159|FILE_IMPORTS|BADCASE|JSON file with error in [import] key (2)
JPP_1160|FILE_IMPORTS|BADCASE|JSON file with error in imported file
JPP_1161|FILE_IMPORTS|BADCASE|JSON file with invalid data type of [import] key (1)
JPP_1162|FILE_IMPORTS|BADCASE|JSON file with invalid data type of [import] key (2)
JPP_1163|FILE_IMPORTS|BADCASE|JSON file with invalid data type of [import] key (3)
JPP_1164|FILE_IMPORTS|BADCASE|JSON file with invalid data type of [import] key (4)
JPP_1165|FILE_IMPORTS|BADCASE|JSON file with cyclic imports (sawtooth, stopped)
JPP_1166|FILE_IMPORTS|BADCASE|JSON file with cyclic imports (sawtooth, endless)
JPP_1200|PATH_FORMATS|GOODCASE|Relative path to JSON file
JPP_1350|BLOCKED_SLICING|BADCASE|JSON file with blocked slicing notation (-1)
JPP_1351|BLOCKED_SLICING|BADCASE|JSON file with blocked slicing notation (-1)
Expand Down
Loading

0 comments on commit d294a0e

Please sign in to comment.