-
Notifications
You must be signed in to change notification settings - Fork 2.4k
List ignore #3469
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 ignore #3469
Conversation
I am working on fixing the tests, |
@finally all tests passed. Today I learn new thing on test expected value!!! |
@tysonite @pekkaklarck can you please review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just one missing space. Thanks!
is this RF 3.2 Candidate ? |
src/robot/libraries/Collections.py
Outdated
else: | ||
sorted_list1 = sorted(list1) | ||
sorted_list2 = sorted(list2) | ||
diffs = list(self._yield_list_diffs(sorted_list1, sorted_list2, names)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks a bit more complicated than needed. AFAIK this would be enough:
if ignore_order:
list1 = sorted(list1)
list2 = sorted(list2)
@@ -346,7 +346,7 @@ def list_should_not_contain_duplicates(self, list_, msg=None): | |||
'%s found multiple times.' % seq2str(dupes)) | |||
|
|||
def lists_should_be_equal(self, list1, list2, msg=None, values=True, | |||
names=None): | |||
names=None, ignore_order=False): | |||
"""Fails if given lists are unequal. | |||
|
|||
The keyword first verifies that the lists have equal lengths, and then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new option needs to be explained in the documentation, possibly with an example. A note about the option being new in Robot Framework 3.2 is needed as well.
@@ -331,6 +331,11 @@ Lists Should Be Equal With Named Indices As Dictionary With Too Few Values | |||
${names} = Create Dictionary 0=a 2=c | |||
Lists Should Be Equal ${L3} ${L3B} names=${names} | |||
|
|||
Lists Should Be Equal Ignore Order | |||
${names1} = Create List A B C D | |||
${names2} = Create List D B C A |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks a bit strange that the separator between arguments is different. Using four spaces consistently would be better. These values aren't names either so probably variables should be just ${list1}
and ${list2}
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somehow formatting of this shown differently but I just checked checked in file here and it
shows correct.
https://user-images.githubusercontent.com/33742811/74623859-3ffbb600-516c-11ea-86ac-902a73a13862.png
Yeah, this can easily be included to RF 3.2. Please take a look at the review comments. I hope you can fix them all so that I can simply merge this online without any further changes. |
@@ -331,6 +331,11 @@ Lists Should Be Equal With Named Indices As Dictionary With Too Few Values | |||
${names} = Create Dictionary 0=a 2=c | |||
Lists Should Be Equal ${L3} ${L3B} names=${names} | |||
|
|||
Lists Should Be Equal Ignore Order | |||
${list1} = Create List A B C D | |||
${list2} = Create List D B C A |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's probably a tab between C
and A
. I can fix that myself.
Changes done @pekkaklarck |
Looks good to me. Documentation could perhaps be enhanced a bit but I can do that after merging. Thanks! |
well... is that work all time? test in python3.6.8 >>> sorted([{1,2}, {3,4}]) == sorted([{4,3}, {2,1}])
False but since set is orderless, i expect the above can pass the compare |
That seems to be some Python oddity: >>> sorted([{1, 2}, {3,4}])
[{1, 2}, {3, 4}]
>>> sorted([{3, 4}, {1, 2}])
[{3, 4}, {1, 2}] My guess is that sets cannot compared. Anyway, nothing we really can do anything. |
As list is mutable and if we use sort, it will alter original list. Original list should not be altered so used sorted function instead of sort method.
Instead of modify more lines in the _yield_list_diffs method to handle
name
option given by user, just passed sorted list to get the diff as we should support name argument/parameter as well.