3 ms·
assert user_data == { 'id': IsPositiveInt, 'avatar_file': IsStr(regex=r'/[a-z0-9\-]{10}/example\.png'), > Without dirty-equals, you'd have to c
by quietbritishjim 5y ago
assert user_data == {
'id': IsPositiveInt,
'avatar_file': IsStr(regex=r'/[a-z0-9\-]{10}/example\.png'),
> Without dirty-equals, you'd have to compare individual fields and/or modify some fields before comparison ...
Hmm, I'm not convinced. Why not
assert dirty_check(user_data, {
'id': IsPositiveInt,
'avatar_file': IsStr(regex=r'/[a-z0-9\-]{10}/example\.png'),
It would work just as well without abusing the == operator. Doing so seems like a bit of a gimmick (although the actual functionality of the library looks useful).
Edit: Ah, I guess the difference is that dict.__eq__ (and list.__eq__ and so on) recursively tests equality of all child elements. So to support arbitrary nesting I think it really does have to be the equals operator.