-
Notifications
You must be signed in to change notification settings - Fork 76
Closed
Description
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')