-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Dictionaries Should Be Equal
added support for ignoring keys
#3942
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
Conversation
…ld Be Equal" added acceptance tests
Codecov Report
@@ Coverage Diff @@
## master #3942 +/- ##
==========================================
- Coverage 75.15% 75.11% -0.04%
==========================================
Files 222 222
Lines 18816 18816
Branches 3076 3076
==========================================
- Hits 14140 14131 -9
- Misses 4147 4153 +6
- Partials 529 532 +3
Continue to review full report at Codecov.
|
Dictionaries Should Be Equal
added support for ignoring keys
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.
First of all, sorry for a very late review. I had missed this PR earlier and now noticed it when finalizing RF 6.1. This looks so good that I'll merge it and fix the small issues mentioned in separate comments.
I also plan to change this so that the list of ignored keys can be given as a Python list literal. That would be easiest to implement by having list
as a type hint for ignore_keys
, but because this library doesn't use type hints otherwise (it should!) I'll probably implement it using ast.literal_eval
separately.
"""Fails if the given dictionaries are not equal. | ||
|
||
First the equality of dictionaries' keys is checked and after that all | ||
the key value pairs. If there are differences between the values, those | ||
are listed in the error message. The types of the dictionaries do not | ||
need to be same. | ||
|
||
``ignore_keys`` can be used to provide a list of keys to ignore in the | ||
comparison. |
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.
Need a note when this option has been added.
self._validate_dictionary(dict1) | ||
self._validate_dictionary(dict2, 2) | ||
dict1 = {k: v for k, v in dict1.items() if k not in ignore_keys} | ||
dict2 = {k: v for k, v in dict2.items() if k not in ignore_keys} |
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 should be done only when ignore_keys
is set. Now dictionaries are always recreated which wastes resources and in with custom dict subsclasses can also change semantics.
See `Lists Should Be Equal` for more information about configuring | ||
the error message with ``msg`` and ``values`` arguments. | ||
""" | ||
|
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.
We don't generally use empty lines inside functions or methods.
No problem. Thanks for the feedback! |
Issue #2717
Added additional optional parameter to provide a list of keys to ignore in the comparison