Skip to content

Commit 53cc758

Browse files
committed
assert_equal(): Delegate to assert_dict_equal() if applicable
#14
1 parent c410066 commit 53cc758

3 files changed

Lines changed: 9 additions & 2 deletions

File tree

NEWS.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ API Additions
99
Improvements
1010
------------
1111

12-
* `fail()` is now marked with `NoReturn` in type stub.
12+
* ``assert_equal()``: Use ``assert_dict_equal()`` if applicable.
13+
* ``fail()`` is now marked with ``NoReturn`` in type stub.
1314

1415
Bug Fixes
1516
---------

asserts/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ def assert_equal(first, second, msg_fmt="{msg}"):
165165
* second - the second argument
166166
"""
167167

168-
if not first == second:
168+
if isinstance(first, dict) and isinstance(second, dict):
169+
assert_dict_equal(first, second, msg_fmt)
170+
elif not first == second:
169171
msg = "{!r} != {!r}".format(first, second)
170172
fail(msg_fmt.format(msg=msg, first=first, second=second))
171173

test_asserts.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ def test_assert_equal__not_equal__custom_message(self):
187187
with _assert_raises_assertion("'string' != 55;'string';55"):
188188
assert_equal("string", 55, "{msg};{first!r};{second!r}")
189189

190+
def test_assert_equal__dict(self):
191+
with _assert_raises_assertion("key 'foo' missing from right dict"):
192+
assert_equal({"foo": 5}, {})
193+
190194
# assert_not_equal()
191195

192196
def test_assert_not_equal__not_equal(self):

0 commit comments

Comments
 (0)