From fb309bfafe7f24361f9da7fce70062776f45e0ac Mon Sep 17 00:00:00 2001 From: qth2hi Date: Fri, 3 Jan 2025 20:17:21 +0100 Subject: [PATCH] Self test adapted to latest changes of the JsonPreprocessor --- test/JPP_TestUsecases.csv | 3 + test/JPP_TestUsecases.html | 117 ++++++++++++++++-- test/JPP_TestUsecases.rst | 32 ++++- test/JPP_TestUsecases.txt | 14 ++- test/component_test.py | 4 +- .../test_25_PARAMETER_SCOPE_GOODCASE.py | 26 +++- test/testconfig/TestConfig.py | 38 ++++-- test/testfiles/jpp-test_config_2004.jsonp | 1 - test/testfiles/jpp-test_config_2005.jsonp | 3 - test/testfiles/jpp-test_config_2006.jsonp | 3 - test/testtools/GenSnippetsJPP.py | 85 ++++++++++++- 11 files changed, 294 insertions(+), 32 deletions(-) diff --git a/test/JPP_TestUsecases.csv b/test/JPP_TestUsecases.csv index e30040b1..d526aa38 100644 --- a/test/JPP_TestUsecases.csv +++ b/test/JPP_TestUsecases.csv @@ -190,6 +190,9 @@ JPP_2000|PARAMETER_SCOPE|GOODCASE|JSON file with nested dictionary, in which a p JPP_2001|PARAMETER_SCOPE|GOODCASE|JSON file with nested dictionary, in which a parameter is overwritten (2) JPP_2002|PARAMETER_SCOPE|GOODCASE|JSON file with nested dictionary, in which a parameter is overwritten (3) JPP_2003|PARAMETER_SCOPE|GOODCASE|JSON file with nested dictionary, in which a parameter is overwritten (4) +JPP_2004|PARAMETER_SCOPE|GOODCASE|JSON file with nested dictionary, in which a parameter is overwritten (5) +JPP_2005|PARAMETER_SCOPE|GOODCASE|JSON file with nested dictionary, in which a parameter is overwritten (6) +JPP_2006|PARAMETER_SCOPE|GOODCASE|JSON file with nested dictionary, in which a parameter is overwritten (7) JPP_2007|PARAMETER_SCOPE|GOODCASE|JSON file with nested dictionary, in which a parameter is overwritten (8) JPP_2050|PARAMETER_SCOPE|BADCASE|JSON file containing a parameter with missing scope (1) JPP_2051|PARAMETER_SCOPE|BADCASE|JSON file containing a parameter with missing scope (2) diff --git a/test/JPP_TestUsecases.html b/test/JPP_TestUsecases.html index 702f9e26..e9caa37b 100644 --- a/test/JPP_TestUsecases.html +++ b/test/JPP_TestUsecases.html @@ -6349,6 +6349,105 @@ 191 + + + +JPP_2004 + + + + +PARAMETER_SCOPE + + + + +GOODCASE + + + + +JSON file with nested dictionary, in which a parameter is overwritten (5)
+Expected: JsonPreprocessor returns expected value + + +
+ + + + + + + +192 + + + + + +JPP_2005 + + + + +PARAMETER_SCOPE + + + + +GOODCASE + + + + +JSON file with nested dictionary, in which a parameter is overwritten (6)
+Expected: JsonPreprocessor returns expected value + + +
+ + + + + + + +193 + + + + + +JPP_2006 + + + + +PARAMETER_SCOPE + + + + +GOODCASE + + + + +JSON file with nested dictionary, in which a parameter is overwritten (7)
+Expected: JsonPreprocessor returns expected value + + +
+ + + + + + + +194 + + @@ -6379,7 +6478,7 @@ -192 +195 @@ -6412,7 +6511,7 @@ -193 +196 @@ -6445,7 +6544,7 @@ -194 +197 @@ -6478,7 +6577,7 @@ -195 +198 @@ -6511,7 +6610,7 @@ -196 +199 @@ -6544,7 +6643,7 @@ -197 +200 @@ -6577,7 +6676,7 @@ -198 +201 @@ -6610,7 +6709,7 @@ -199 +202 @@ -6643,7 +6742,7 @@
 

-
Generated: 26.11.2024 - 12:36:07
+
Generated: 03.01.2025 - 16:19:20
 
diff --git a/test/JPP_TestUsecases.rst b/test/JPP_TestUsecases.rst index 2de6fc89..49f7a098 100644 --- a/test/JPP_TestUsecases.rst +++ b/test/JPP_TestUsecases.rst @@ -2005,6 +2005,36 @@ Test Use Cases ---- +* **Test JPP_2004** + + [PARAMETER_SCOPE / GOODCASE] + + **JSON file with nested dictionary, in which a parameter is overwritten (5)** + + Expected: JsonPreprocessor returns expected value + +---- + +* **Test JPP_2005** + + [PARAMETER_SCOPE / GOODCASE] + + **JSON file with nested dictionary, in which a parameter is overwritten (6)** + + Expected: JsonPreprocessor returns expected value + +---- + +* **Test JPP_2006** + + [PARAMETER_SCOPE / GOODCASE] + + **JSON file with nested dictionary, in which a parameter is overwritten (7)** + + Expected: JsonPreprocessor returns expected value + +---- + * **Test JPP_2007** [PARAMETER_SCOPE / GOODCASE] @@ -2095,5 +2125,5 @@ Test Use Cases ---- -Generated: 26.11.2024 - 12:36:07 +Generated: 03.01.2025 - 16:19:20 diff --git a/test/JPP_TestUsecases.txt b/test/JPP_TestUsecases.txt index e168fcf5..e61f7f57 100644 --- a/test/JPP_TestUsecases.txt +++ b/test/JPP_TestUsecases.txt @@ -820,6 +820,18 @@ Test JPP_2003 / PARAMETER_SCOPE / GOODCASE Description: JSON file with nested dictionary, in which a parameter is overwritten (4) Expectation: JsonPreprocessor returns expected value ------------------------------------------------------------------------------------------------------------------------ +Test JPP_2004 / PARAMETER_SCOPE / GOODCASE +Description: JSON file with nested dictionary, in which a parameter is overwritten (5) +Expectation: JsonPreprocessor returns expected value +------------------------------------------------------------------------------------------------------------------------ +Test JPP_2005 / PARAMETER_SCOPE / GOODCASE +Description: JSON file with nested dictionary, in which a parameter is overwritten (6) +Expectation: JsonPreprocessor returns expected value +------------------------------------------------------------------------------------------------------------------------ +Test JPP_2006 / PARAMETER_SCOPE / GOODCASE +Description: JSON file with nested dictionary, in which a parameter is overwritten (7) +Expectation: JsonPreprocessor returns expected value +------------------------------------------------------------------------------------------------------------------------ Test JPP_2007 / PARAMETER_SCOPE / GOODCASE Description: JSON file with nested dictionary, in which a parameter is overwritten (8) Expectation: JsonPreprocessor returns expected value @@ -856,5 +868,5 @@ 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: 26.11.2024 - 12:36:07 +Generated: 03.01.2025 - 16:19:20 diff --git a/test/component_test.py b/test/component_test.py index 83b74563..92d1b7b2 100644 --- a/test/component_test.py +++ b/test/component_test.py @@ -22,8 +22,8 @@ # # -------------------------------------------------------------------------------------------------------------- # -VERSION = "0.55.0" -VERSION_DATE = "26.11.2024" +VERSION = "0.56.0" +VERSION_DATE = "03.01.2025" # # -------------------------------------------------------------------------------------------------------------- #TM*** diff --git a/test/pytest/pytestfiles/test_25_PARAMETER_SCOPE_GOODCASE.py b/test/pytest/pytestfiles/test_25_PARAMETER_SCOPE_GOODCASE.py index 7b7f0660..fd18e409 100644 --- a/test/pytest/pytestfiles/test_25_PARAMETER_SCOPE_GOODCASE.py +++ b/test/pytest/pytestfiles/test_25_PARAMETER_SCOPE_GOODCASE.py @@ -18,7 +18,7 @@ # # XC-HWP/ESW3-Queckenstedt # -# 06.11.2024 - 18:29:18 +# 03.01.2025 - 16:19:20 # # -------------------------------------------------------------------------------------------------------------- @@ -61,6 +61,30 @@ def test_JPP_2002(self, Description): def test_JPP_2003(self, Description): nReturn = CExecute.Execute("JPP_2003") assert nReturn == 0 +# -------------------------------------------------------------------------------------------------------------- + # Expected: JsonPreprocessor returns expected value + @pytest.mark.parametrize( + "Description", ["JSON file with nested dictionary, in which a parameter is overwritten (5)",] + ) + def test_JPP_2004(self, Description): + nReturn = CExecute.Execute("JPP_2004") + assert nReturn == 0 +# -------------------------------------------------------------------------------------------------------------- + # Expected: JsonPreprocessor returns expected value + @pytest.mark.parametrize( + "Description", ["JSON file with nested dictionary, in which a parameter is overwritten (6)",] + ) + def test_JPP_2005(self, Description): + nReturn = CExecute.Execute("JPP_2005") + assert nReturn == 0 +# -------------------------------------------------------------------------------------------------------------- + # Expected: JsonPreprocessor returns expected value + @pytest.mark.parametrize( + "Description", ["JSON file with nested dictionary, in which a parameter is overwritten (7)",] + ) + def test_JPP_2006(self, Description): + nReturn = CExecute.Execute("JPP_2006") + assert nReturn == 0 # -------------------------------------------------------------------------------------------------------------- # Expected: JsonPreprocessor returns expected value @pytest.mark.parametrize( diff --git a/test/testconfig/TestConfig.py b/test/testconfig/TestConfig.py index d0cb234b..5555c8f2 100644 --- a/test/testconfig/TestConfig.py +++ b/test/testconfig/TestConfig.py @@ -22,7 +22,7 @@ # # -------------------------------------------------------------------------------------------------------------- # -# 26.11.2024 +# 03.01.2025 # # !!! Temporarily tests are deactivated by the following line commented out: # # # listofdictUsecases.append(dictUsecase) @@ -4149,8 +4149,16 @@ dictUsecase['COMMENT'] = None dictUsecase['JSONFILE'] = r"..\testfiles\jpp-test_config_2004.jsonp" dictUsecase['EXPECTEDEXCEPTION'] = None -dictUsecase['EXPECTEDRETURN'] = None -# # # listofdictUsecases.append(dictUsecase) # https://github.com/test-fullautomation/python-jsonpreprocessor/issues/349 +dictUsecase['EXPECTEDRETURN'] = """ +[DOTDICT] (2/1) > {C} [INT] : 1 +[DOTDICT] (2/2) > {params} [LIST] (3/1) > [INT] : 2 +[DOTDICT] (2/2) > {params} [LIST] (3/2) > [DOTDICT] (2/1) > {A} [INT] : 3 +[DOTDICT] (2/2) > {params} [LIST] (3/2) > [DOTDICT] (2/2) > {B} [LIST] (2/1) > [DOTDICT] (2/1) > {C} [INT] : 10 +[DOTDICT] (2/2) > {params} [LIST] (3/2) > [DOTDICT] (2/2) > {B} [LIST] (2/1) > [DOTDICT] (2/2) > {D} [INT] : 5 +[DOTDICT] (2/2) > {params} [LIST] (3/2) > [DOTDICT] (2/2) > {B} [LIST] (2/2) > [INT] : 6 +[DOTDICT] (2/2) > {params} [LIST] (3/3) > [INT] : 7 +""" +listofdictUsecases.append(dictUsecase) del dictUsecase # -------------------------------------------------------------------------------------------------------------- dictUsecase = {} @@ -4163,8 +4171,16 @@ dictUsecase['COMMENT'] = None dictUsecase['JSONFILE'] = r"..\testfiles\jpp-test_config_2005.jsonp" dictUsecase['EXPECTEDEXCEPTION'] = None -dictUsecase['EXPECTEDRETURN'] = None -# # # listofdictUsecases.append(dictUsecase) # https://github.com/test-fullautomation/python-jsonpreprocessor/issues/349 +dictUsecase['EXPECTEDRETURN'] = """ +[DOTDICT] (2/1) > {C} [INT] : 1 +[DOTDICT] (2/2) > {params} [LIST] (3/1) > [INT] : 2 +[DOTDICT] (2/2) > {params} [LIST] (3/2) > [DOTDICT] (2/1) > {A} [INT] : 3 +[DOTDICT] (2/2) > {params} [LIST] (3/2) > [DOTDICT] (2/2) > {B} [LIST] (2/1) > [DOTDICT] (2/1) > {C} [INT] : 10 +[DOTDICT] (2/2) > {params} [LIST] (3/2) > [DOTDICT] (2/2) > {B} [LIST] (2/1) > [DOTDICT] (2/2) > {D} [INT] : 5 +[DOTDICT] (2/2) > {params} [LIST] (3/2) > [DOTDICT] (2/2) > {B} [LIST] (2/2) > [INT] : 6 +[DOTDICT] (2/2) > {params} [LIST] (3/3) > [INT] : 7 +""" +listofdictUsecases.append(dictUsecase) del dictUsecase # -------------------------------------------------------------------------------------------------------------- dictUsecase = {} @@ -4177,8 +4193,16 @@ dictUsecase['COMMENT'] = None dictUsecase['JSONFILE'] = r"..\testfiles\jpp-test_config_2006.jsonp" dictUsecase['EXPECTEDEXCEPTION'] = None -dictUsecase['EXPECTEDRETURN'] = None -# # # listofdictUsecases.append(dictUsecase) # https://github.com/test-fullautomation/python-jsonpreprocessor/issues/349 +dictUsecase['EXPECTEDRETURN'] = """ +[DOTDICT] (2/1) > {C} [INT] : 1 +[DOTDICT] (2/2) > {params} [LIST] (3/1) > [INT] : 2 +[DOTDICT] (2/2) > {params} [LIST] (3/2) > [DOTDICT] (2/1) > {A} [INT] : 3 +[DOTDICT] (2/2) > {params} [LIST] (3/2) > [DOTDICT] (2/2) > {B} [LIST] (2/1) > [DOTDICT] (2/1) > {C} [INT] : 10 +[DOTDICT] (2/2) > {params} [LIST] (3/2) > [DOTDICT] (2/2) > {B} [LIST] (2/1) > [DOTDICT] (2/2) > {D} [INT] : 5 +[DOTDICT] (2/2) > {params} [LIST] (3/2) > [DOTDICT] (2/2) > {B} [LIST] (2/2) > [INT] : 6 +[DOTDICT] (2/2) > {params} [LIST] (3/3) > [INT] : 7 +""" +listofdictUsecases.append(dictUsecase) del dictUsecase # -------------------------------------------------------------------------------------------------------------- dictUsecase = {} diff --git a/test/testfiles/jpp-test_config_2004.jsonp b/test/testfiles/jpp-test_config_2004.jsonp index 2f271da2..b929fb84 100644 --- a/test/testfiles/jpp-test_config_2004.jsonp +++ b/test/testfiles/jpp-test_config_2004.jsonp @@ -13,7 +13,6 @@ // limitations under the License. //************************************************************************** { - // https://github.com/test-fullautomation/python-jsonpreprocessor/issues/349 "C" : 1, "params" : [ 2, diff --git a/test/testfiles/jpp-test_config_2005.jsonp b/test/testfiles/jpp-test_config_2005.jsonp index 14bcbe6e..ad980c1d 100644 --- a/test/testfiles/jpp-test_config_2005.jsonp +++ b/test/testfiles/jpp-test_config_2005.jsonp @@ -13,9 +13,6 @@ // limitations under the License. //************************************************************************** { - // https://github.com/test-fullautomation/python-jsonpreprocessor/issues/349 - // 'A key with name '${params.1.B.0.C}' does not exist at this position. Use the ' : ' syntax to create a new key.'! - "C" : 1, "params" : [ 2, diff --git a/test/testfiles/jpp-test_config_2006.jsonp b/test/testfiles/jpp-test_config_2006.jsonp index fb04f305..65b42962 100644 --- a/test/testfiles/jpp-test_config_2006.jsonp +++ b/test/testfiles/jpp-test_config_2006.jsonp @@ -13,9 +13,6 @@ // limitations under the License. //************************************************************************** { - // https://github.com/test-fullautomation/python-jsonpreprocessor/issues/349 - // {C} [INT] : 10 - "C" : 1, "params" : [ 2, diff --git a/test/testtools/GenSnippetsJPP.py b/test/testtools/GenSnippetsJPP.py index b8469eb6..5121332a 100644 --- a/test/testtools/GenSnippetsJPP.py +++ b/test/testtools/GenSnippetsJPP.py @@ -22,8 +22,8 @@ # # ************************************************************************************************************** # -VERSION = "0.34.0" -VERSION_DATE = "18.11.2024" +VERSION = "0.35.0" +VERSION_DATE = "03.01.2025" # # ************************************************************************************************************** @@ -2497,8 +2497,6 @@ def GetSeveralParticularSnippets(self): listCodeSnippets.append("""{ "A" : 1, "check01" : ${A}, - // Bug: https://github.com/test-fullautomation/python-jsonpreprocessor/issues/357#issuecomment-2435677836 - // 'The parameter '${0}' is not available!'! "0" : 2, "check02" : ${0}, "_" : 3, @@ -4018,6 +4016,82 @@ def GetMissingBrackets(self): # -------------------------------------------------------------------------------------------------------------- + def GetAdditionalBrackets(self): + """Additional brackets at several positions within a complex data structure + """ + + sHeadline = "Additional brackets at several positions within a complex data structure" + + # data structure + sDataStructure1 = """ "C" : *01*1, + "params" : *02*[ + *03*2, + *04*{"A" : 3, + *05*"B" : *06*[ + *07*{ + *08*"C" : 4, + *09*${params.1.B.0.C*10*} : 10, + *11*"D" : 5, + *12*${params*13*}*14*[1]*15*['B']*16*[0]*17*['D'*18*] : 11, + "E" : *19*["020", *20*{"021" : "022"*21*}*22*], + "F" : *23*{"023" : *24*["024", "025"*25*]*26*} + *27*}, + 6 + *28*] + *29*}, + 7 + *30*] +""" + + sCodeSnippetPattern = """{ +####DATASTRUCTURE#### +} +""" + + # We have a list of expressions and we have a list of placeholders like used in sDataStructure1. + # The followig code runs in a nested loop: Every expression is placed at every placeholder position. Only one single + # expression and placeholder per iteration. All remaining placeholders in current iteration are replaced by elements + # from a list of filler expressions (simple letters) that are only used to complete the code snippet, but are not in focus. + + listExpressions = ["{", "}", "[", "]", "$"] + + listPlaceholders = ["*01*", "*02*", "*03*", "*04*", "*05*", "*06*", "*07*", "*08*", "*09*", "*10*", + "*11*", "*12*", "*13*", "*14*", "*15*", "*16*", "*17*", "*18*", "*19*", "*20*", + "*21*", "*22*", "*23*", "*24*", "*25*", "*26*", "*27*", "*28*", "*29*", "*30*"] + + listPositions = listPlaceholders[:] # to support a nested iteration of the same list; better readibility of code because of different names + + listFiller = ["","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""] # as much elements as in listPlaceholders + + # put all things together + + listCodeSnippets = [] + + # sDataStructure1 + + for sExpression in listExpressions: + for sPosition in listPositions: + sDataStructure = sDataStructure1 # init a new data structure from pattern sDataStructure1 + sCodeSnippet = sCodeSnippetPattern # init a new code snippet from code snippet pattern + oFiller = CListElements(listFiller) # init a new filler object (= content for remaining placeholders) + for sPlaceholder in listPlaceholders: + sFiller = oFiller.GetElement() + if sPosition == sPlaceholder: + sDataStructure = sDataStructure.replace(sPlaceholder, sExpression) + else: + sDataStructure = sDataStructure.replace(sPlaceholder, f"{sFiller}") + # eof for sPlaceholder in listPlaceholders: + sCodeSnippet = sCodeSnippet.replace("####DATASTRUCTURE####", sDataStructure) + listCodeSnippets.append(sCodeSnippet) + # eof for sPosition in listPositions: + # eof for sExpression in listExpressions: + + return sHeadline, listCodeSnippets + + # eof def GetAdditionalBrackets(self): + + # -------------------------------------------------------------------------------------------------------------- + def GetSpecialCharacters(self): """Special characters at several positions within a complex data structure """ @@ -4588,6 +4662,9 @@ def GetInternalTokenStrings(self): sHeadline, listCodeSnippets = oSnippets.GetMissingBrackets() bSuccess, sResult = oExecutor.Execute(sHeadline, listCodeSnippets, "JPP") +sHeadline, listCodeSnippets = oSnippets.GetAdditionalBrackets() +bSuccess, sResult = oExecutor.Execute(sHeadline, listCodeSnippets, "JPP") + sHeadline, listCodeSnippets = oSnippets.GetSpecialCharacters() bSuccess, sResult = oExecutor.Execute(sHeadline, listCodeSnippets, "JPP")