Skip to content

Dictionaries Should Be Equal added support for ignoring keys - #3942

Merged
pekkaklarck merged 4 commits into
robotframework:masterfrom
yuriverweij:master
Jun 2, 2023
Merged

pekkaklarck merged 4 commits into
robotframework:masterfrom
yuriverweij:master

Conversation

@yuriverweij

@yuriverweij yuriverweij commented Apr 21, 2021 •

Copy link
Copy Markdown
Member

Issue #2717
Added additional optional parameter to provide a list of keys to ignore in the comparison

  • updated keyword documentation
  • added acceptance tests

@codecov-commenter

codecov-commenter commented Apr 21, 2021 •

Copy link
Copy Markdown

Codecov Report

Merging #3942 (96582cd) into master (681d359) will decrease coverage by 0.05%.
The diff coverage is n/a.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
src/robot/utils/robotinspect.py 47.62% <0.00%> (-19.04%) ⬇️
src/robot/version.py 55.56% <0.00%> (-11.11%) ⬇️
src/robot/libdocpkg/datatypes.py 94.57% <0.00%> (-1.08%) ⬇️
src/robot/utils/importer.py 83.81% <0.00%> (-0.95%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 681d359...96582cd. Read the comment docs.

@yuriverweij yuriverweij changed the title #2717 dictionary ignore keys Dictionaries Should Be Equal added support for ignoring keys Apr 21, 2021

@pekkaklarck pekkaklarck left a comment

Copy link
Copy Markdown
Member

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.

need to be same.

``ignore_keys`` can be used to provide a list of keys to ignore in the
comparison.

Copy link
Copy Markdown
Member

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}

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Member

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.

@pekkaklarck
pekkaklarck merged commit ae13950 into robotframework:master Jun 2, 2023
@yuriverweij

Copy link
Copy Markdown
Member Author

No problem. Thanks for the feedback!

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.

3 participants