Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 8 commits into from
Feb 28, 2020
Merged

List ignore #3469

merged 8 commits into from
Feb 28, 2020

Conversation

bbpatel2001
Copy link
Contributor

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

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

@bbpatel2001
Copy link
Contributor Author

I am working on fixing the tests,

@bbpatel2001
Copy link
Contributor Author

@finally all tests passed. Today I learn new thing on test expected value!!!

@bbpatel2001
Copy link
Contributor Author

@tysonite @pekkaklarck can you please review.

Copy link
Contributor

@laurentbristiel laurentbristiel left a 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!

@bbpatel2001
Copy link
Contributor Author

is this RF 3.2 Candidate ?

else:
sorted_list1 = sorted(list1)
sorted_list2 = sorted(list2)
diffs = list(self._yield_list_diffs(sorted_list1, sorted_list2, names))
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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

Copy link
Contributor Author

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

@pekkaklarck
Copy link
Member

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
Copy link
Contributor Author

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.

image

Copy link
Member

@pekkaklarck pekkaklarck Feb 28, 2020

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.

@bbpatel2001
Copy link
Contributor Author

Changes done @pekkaklarck

@pekkaklarck
Copy link
Member

Looks good to me. Documentation could perhaps be enhanced a bit but I can do that after merging. Thanks!

@pekkaklarck pekkaklarck merged commit 0032b78 into robotframework:master Feb 28, 2020
@rainydew
Copy link

rainydew commented Feb 28, 2020

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

@pekkaklarck
Copy link
Member

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.

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

Successfully merging this pull request may close these issues.

5 participants