Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List access with index parameters does not work #184

Closed
HolQue opened this issue Jan 9, 2024 · 19 comments
Closed

List access with index parameters does not work #184

HolQue opened this issue Jan 9, 2024 · 19 comments

Comments

@HolQue
Copy link
Collaborator

HolQue commented Jan 9, 2024

(1)
The JSON code

"intval" : 1,
"testlist" : ["B", 2],
${testlist}[${intval}] : 4

causes a parameter with name ${testlist}[${intval}], type int and value 4.

But expected is that the second element of the testlist is changed from value 2 to value 4.

Update: Retest successful; (1) is solved.

(2)
Now the index parameter is wrapped in single quotes:

"intval" : 1,
"testlist" : ["B", 2],
${testlist}['${intval}'] : 4

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

"intval" : 1,
"testlist" : ["B", 2],
${testlist[${intval}]} : 4

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.

@namsonx
Copy link
Collaborator

namsonx commented Jan 16, 2024

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

@HolQue
Copy link
Collaborator Author

HolQue commented Jan 16, 2024

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.

@namsonx
Copy link
Collaborator

namsonx commented Jan 16, 2024

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

@HolQue
Copy link
Collaborator Author

HolQue commented Jan 16, 2024

"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.

@namsonx
Copy link
Collaborator

namsonx commented Jan 16, 2024

"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

@namsonx
Copy link
Collaborator

namsonx commented Jan 16, 2024

Hello Holger,

After our short discussion, now I understood the context.

Thank you,
Son

@namsonx
Copy link
Collaborator

namsonx commented Jan 17, 2024

Hello Holger,

I pushed the commit 8461eb19a02 to the stabi branch to cover all use cases you mentioned in this ticket.

Thank you,
Son

@namsonx namsonx moved this from In Progress to Done in RobotFramework AIO Jan 17, 2024
@HolQue
Copy link
Collaborator Author

HolQue commented Jan 19, 2024

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

#104 (comment)

@namsonx
Copy link
Collaborator

namsonx commented Jan 24, 2024

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

@HolQue
Copy link
Collaborator Author

HolQue commented Jan 24, 2024

Hi Thomas,

I am confused now. Is slicing a confirmed feature or not?

Because of

#184 (comment)

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?

@HolQue
Copy link
Collaborator Author

HolQue commented Jan 24, 2024

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).

@test-fullautomation
Copy link
Owner

test-fullautomation commented Jan 24, 2024

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

@test-fullautomation
Copy link
Owner

Hi Son,
what is the status of this ticket?
Thank you,
Thomas

@namsonx
Copy link
Collaborator

namsonx commented Jan 31, 2024

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

@HolQue
Copy link
Collaborator Author

HolQue commented Mar 12, 2024

Because of

#205

this part

#184 (comment)

still needs to be fixed.

@namsonx
Copy link
Collaborator

namsonx commented Apr 8, 2024

Hello Holger,

#205 and #184 (comment) are solved.

Thank you,
Son

@HolQue
Copy link
Collaborator Author

HolQue commented Apr 17, 2024

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.

@HolQue
Copy link
Collaborator Author

HolQue commented May 7, 2024

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:

#205 (comment)

Therefore this issue can be closed.

@test-fullautomation
Copy link
Owner

released with RobotFramework AIO 0.12.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

3 participants