mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Move assertBytesEqual to base test class, improve it, and hook into assertEqual
This commit is contained in:
parent
eb50e51a0f
commit
a46ed1186f
2 changed files with 12 additions and 6 deletions
|
@ -25,6 +25,10 @@ def openfile(filename, *args, **kws):
|
|||
# Base test class
|
||||
class TestEmailBase(unittest.TestCase):
|
||||
|
||||
def __init__(self, *args, **kw):
|
||||
super().__init__(*args, **kw)
|
||||
self.addTypeEqualityFunc(bytes, self.assertBytesEqual)
|
||||
|
||||
def ndiffAssertEqual(self, first, second):
|
||||
"""Like assertEqual except use ndiff for readable output."""
|
||||
if first != second:
|
||||
|
@ -38,3 +42,10 @@ class TestEmailBase(unittest.TestCase):
|
|||
def _msgobj(self, filename):
|
||||
with openfile(filename) as fp:
|
||||
return email.message_from_file(fp)
|
||||
|
||||
def _bytes_repr(self, b):
|
||||
return [repr(x) for x in b.splitlines(True)]
|
||||
|
||||
def assertBytesEqual(self, first, second, msg):
|
||||
"""Our byte strings are really encoded strings; improve diff output"""
|
||||
self.assertEqual(self._bytes_repr(first), self._bytes_repr(second))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue