Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

deep dict compare #75

Copy link
Copy link
@saturnboy

Description

@saturnboy
Issue body actions

Using is_equal_to() with dicts works fine, but error messages under assertion failure are not as clear as they could be. Plus this would be super helpful when combined with #74.

Old:

assert_that({'a':1,'b':2,'c':3}).is_equal_to({'a':1,'b':2,'c':4})

Just says:

Expected <{'b': 2, 'c': 3, 'a': 1}> to be equal to <{'b': 2, 'c': 4, 'a': 1}>, but was not.

Step 1 - hide the equal bits

Should say something actually useful, like:

Expected <{.., 'c': 3}> to be equal to <{.., 'c': 4}>, but was not.

Where all the equal entries are simply hidden.

Step 2 - support deep dicts

Also, needs to support arbitrary dict depth. For example:

assert_that({'a':1,'b':{'x':2,y:3}}).is_equal_to({'a':1,'b':{'x':2,y:4}})

Should say something like:

Expected <{.., 'b': {.., 'y': 3}}> to be equal to <{.., 'b': {.., 'y': 4}}>, but was not.

Step 3 - ignore keys

Lastly, it would be cool to allow dict equality to ignore certain keys. For example:

assert_that({'a':1,'b':2,'c':3}).is_equal_to({'a':1,'b':2}, ignore='c')

Or ignore multiple keys:

assert_that({'a':1,'b':2,'c':3}).is_equal_to({'a':1}, ignore=['b','c'])

And it would be double amazing to ignore deep branches of keys. For example:

assert_that({'a':1,'b':{'x':2,y:3}}).is_equal_to({'a':1,'b':{'x':2}}, ignore='b.y')
Reactions are currently unavailable

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.