Closed HolQue closed 4 weeks ago
Hello Holger,
Regarding to the use case (2)
"intval" : 1,
"testlist" : ["B", 2],
${testlist}['${intval}'] : 4
Sorry but I'm not agree with you that it's a context of lists because user use the syntax ['<something>']
(a context of list is without the single quote).
Thank you, Son
Hi Son,
this is a BADCASE test and I clearly pointed out my expectation:
Expected is an error message telling that list indices are expected to be of type int.
Hi Son,
this is a BADCASE test and I clearly pointed out my expectation:
Expected is an error message telling that list indices are expected to be of type int.
Hello Holger,
The syntax with square brackets [ ... ]
is used for list indices and for dictionary as well, when we place a string inside square brackets it means we want to access the sub-element of a dictionary. So, it's not only expected int
datatype.
Thank you, Son
"we want to access the sub-element of a dictionary"
NO!
This depends on the data type of the parameter the square bracket expression belongs to. If it's a list and the index is a string, then this is an error! Therefore I told that it's a BADCASE test.
Some days ago I updated the documentation of the JsonPreprocessor and explained these expectations in detail. Please take a look at this.
"we want to access the sub-element of a dictionary"
NO!
This depends on the data type of the parameter the square bracket expression belongs to. If it's a list and the index is a string, then this is an error! Therefore I told that it's a BADCASE test.
Some days ago I updated the documentation of the JsonPreprocessor and explained these expectations in detail. Please take a look at this.
Hello Holger,
I understood you define a BADCASE test, how about user define a json file like below:
{
${testlist}['1'] : "ABC"
}
Now, we consider this scenario is valid or invalid?
if valid (current behavior of JP is valid), the result is: testlist : {'1': 'ABC'}
if invalid, JP will raise an error message as you mentioned.
Thank you, Son
Hello Holger,
After our short discussion, now I understood the context.
Thank you, Son
Hello Holger,
I pushed the commit 8461eb19a02 to the stabi branch to cover all use cases you mentioned in this ticket.
Thank you, Son
Only one tiny aspect left:
"intval" : 1,
"testlist" : ["B", 2],
${testlist}['${intval}'] : 4
now causes:
Error: 'Could not set variable '${testlist}['${intval}']' with value '4'! Reason: list indices must be integers or slices, not str'!
"or slices"? As per my understanding we do not support slicing. Therefore we must not tell the opposite in error messages.
Maybe this is the original error message from Python interpreter. In this case we have to provide an own error message.
A small code example about how to do this I already communicated in
https://github.com/test-fullautomation/python-jsonpreprocessor/issues/104#issuecomment-1740777467
Hello Holger,
Actually, we support slicing as Python interpreter does. For example, I create a json file like below:
{
"param1" : [1, 2, 3, 4, 5],
"param2" : ${param1}[1:4]
}
Then I get the result below:
param1 : [1, 2, 3, 4, 5] - <class 'list'>
param2 : [2, 3, 4] - <class 'list'>
So, I think we don't need to update the error message.
Thank you, Son
Hi Thomas,
I am confused now. Is slicing a confirmed feature or not?
Because of
https://github.com/test-fullautomation/python-jsonpreprocessor/issues/184#issuecomment-1907842396
my understanding was, that slicing is not supported (= not a supported feature).
Because if slicing is supported officially, we have to explain this feature in documentation. And also in TestsuitesManagement Tutorial. And the feature has to be mentioned in history of JsonPreprocessor. And self tests are needed for both the TestsuitesManagement and the JsonPreprocessor. All these things are not yet done.
How to continue?
Small check with
"testlist" : ["A", "B", "C", "D", "E"],
"index1" : 1,
"index2" : 3,
"param1" : ${testlist}[1:3]
"param2" : ${testlist}[${index1}:${index2}]
param1
works.
param2
causes:
Error: 'Invalid nested parameter format: ${testlist}[${index1} - The double quotes are missing!!!'!
Outcome: slicing feature needs to be specified in more detail before we can release it.
Update: Also param2 works now (slicing detected).
Hi both, If slicing is working, then it's O.K. for me. But we document and create tests with 0.11.0. Shifted to 0.11.0 Thank you, Thomas
Hi Son, what is the status of this ticket? Thank you, Thomas
Hi Thomas,
The list slicing is currently working if slicing indexes are a number, and the slicing doesn't work while slicing indexes are nested parameter. This is a different issue of list slicing index feature which we planned to shift to next release. So, I think we should closed this ticket and create a different ticket.
Thank you, Son
Because of
https://github.com/test-fullautomation/python-jsonpreprocessor/issues/205
this part
https://github.com/test-fullautomation/python-jsonpreprocessor/issues/184#issuecomment-1900923788
still needs to be fixed.
Hello Holger,
Thank you, Son
Hi Son,
the error message
"list indices must be integers or slices, not str'"
still proposes slices. Because of the decision to block slicing, this part of the error message is not correct.
The list access code examples from above work now.
Error message:
"list indices must be integers or slices, not str'"
is still wrong. But this is already tracked by:
https://github.com/test-fullautomation/python-jsonpreprocessor/issues/205#issuecomment-2097754541
Therefore this issue can be closed.
released with RobotFramework AIO 0.12.0
(1) The JSON code
causes a parameter with name
${testlist}[${intval}]
, typeint
and value4
.But expected is that the second element of the
testlist
is changed from value2
to value4
.Update: Retest successful; (1) is solved.
(2) Now the index parameter is wrapped in single quotes:
Result:
The implicit creation of data structures based on nested parameter does not enable yet.
That's wrong, because in context of lists the 'implicit creation' has no meaning.
Expected is an error message telling that list indices are expected to be of type int.
Reference: JPP_0551
Update: Retest successful; (2) is solved.
(3) The JSON code
causes a parameter with name
${testlist[${intval}]}
But expected is an error message telling that indices must be placed outside the curly brackets.
Reference: JPP_0552
Update: Retest successful; (3) is solved.