mirror of
https://github.com/python/cpython.git
synced 2025-12-09 10:37:17 +00:00
gh-71339: Use new assertion methods in the email tests (GH-129055)
This commit is contained in:
parent
7076d076c2
commit
522766aa23
5 changed files with 17 additions and 19 deletions
|
|
@ -288,7 +288,7 @@ class TestRawDataManager(TestEmailBase):
|
||||||
|
|
||||||
The real body is in another message.
|
The real body is in another message.
|
||||||
"""))
|
"""))
|
||||||
self.assertEqual(raw_data_manager.get_content(m)[:10], b'To: foo@ex')
|
self.assertStartsWith(raw_data_manager.get_content(m), b'To: foo@ex')
|
||||||
|
|
||||||
def test_set_text_plain(self):
|
def test_set_text_plain(self):
|
||||||
m = self._make_message()
|
m = self._make_message()
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ class TestDefectsBase:
|
||||||
msg = self._str_msg(source)
|
msg = self._str_msg(source)
|
||||||
if self.raise_expected: return
|
if self.raise_expected: return
|
||||||
inner = msg.get_payload(0)
|
inner = msg.get_payload(0)
|
||||||
self.assertTrue(hasattr(inner, 'defects'))
|
self.assertHasAttr(inner, 'defects')
|
||||||
self.assertEqual(len(self.get_defects(inner)), 1)
|
self.assertEqual(len(self.get_defects(inner)), 1)
|
||||||
self.assertIsInstance(self.get_defects(inner)[0],
|
self.assertIsInstance(self.get_defects(inner)[0],
|
||||||
errors.StartBoundaryNotFoundDefect)
|
errors.StartBoundaryNotFoundDefect)
|
||||||
|
|
@ -151,7 +151,7 @@ class TestDefectsBase:
|
||||||
with self._raise_point(errors.NoBoundaryInMultipartDefect):
|
with self._raise_point(errors.NoBoundaryInMultipartDefect):
|
||||||
msg = self._str_msg(source)
|
msg = self._str_msg(source)
|
||||||
if self.raise_expected: return
|
if self.raise_expected: return
|
||||||
self.assertTrue(hasattr(msg, 'defects'))
|
self.assertHasAttr(msg, 'defects')
|
||||||
self.assertEqual(len(self.get_defects(msg)), 2)
|
self.assertEqual(len(self.get_defects(msg)), 2)
|
||||||
self.assertIsInstance(self.get_defects(msg)[0],
|
self.assertIsInstance(self.get_defects(msg)[0],
|
||||||
errors.NoBoundaryInMultipartDefect)
|
errors.NoBoundaryInMultipartDefect)
|
||||||
|
|
|
||||||
|
|
@ -210,7 +210,7 @@ class TestMessageAPI(TestEmailBase):
|
||||||
self.assertEqual(msg.items()[0][1], 'multipart/form-data')
|
self.assertEqual(msg.items()[0][1], 'multipart/form-data')
|
||||||
# Trigger creation of boundary
|
# Trigger creation of boundary
|
||||||
msg.as_string()
|
msg.as_string()
|
||||||
self.assertEqual(msg.items()[0][1][:33],
|
self.assertStartsWith(msg.items()[0][1],
|
||||||
'multipart/form-data; boundary="==')
|
'multipart/form-data; boundary="==')
|
||||||
# XXX: there ought to be tests of the uniqueness of the boundary, too.
|
# XXX: there ought to be tests of the uniqueness of the boundary, too.
|
||||||
|
|
||||||
|
|
@ -303,7 +303,7 @@ class TestMessageAPI(TestEmailBase):
|
||||||
self.assertEqual(text, str(msg))
|
self.assertEqual(text, str(msg))
|
||||||
fullrepr = msg.as_string(unixfrom=True)
|
fullrepr = msg.as_string(unixfrom=True)
|
||||||
lines = fullrepr.split('\n')
|
lines = fullrepr.split('\n')
|
||||||
self.assertTrue(lines[0].startswith('From '))
|
self.assertStartsWith(lines[0], 'From ')
|
||||||
self.assertEqual(text, NL.join(lines[1:]))
|
self.assertEqual(text, NL.join(lines[1:]))
|
||||||
|
|
||||||
def test_as_string_policy(self):
|
def test_as_string_policy(self):
|
||||||
|
|
@ -372,7 +372,7 @@ class TestMessageAPI(TestEmailBase):
|
||||||
self.assertEqual(data, bytes(msg))
|
self.assertEqual(data, bytes(msg))
|
||||||
fullrepr = msg.as_bytes(unixfrom=True)
|
fullrepr = msg.as_bytes(unixfrom=True)
|
||||||
lines = fullrepr.split(b'\n')
|
lines = fullrepr.split(b'\n')
|
||||||
self.assertTrue(lines[0].startswith(b'From '))
|
self.assertStartsWith(lines[0], b'From ')
|
||||||
self.assertEqual(data, b'\n'.join(lines[1:]))
|
self.assertEqual(data, b'\n'.join(lines[1:]))
|
||||||
|
|
||||||
def test_as_bytes_policy(self):
|
def test_as_bytes_policy(self):
|
||||||
|
|
@ -2228,7 +2228,7 @@ class TestNonConformant(TestEmailBase):
|
||||||
msg = self._msgobj('msg_15.txt')
|
msg = self._msgobj('msg_15.txt')
|
||||||
# XXX We can probably eventually do better
|
# XXX We can probably eventually do better
|
||||||
inner = msg.get_payload(0)
|
inner = msg.get_payload(0)
|
||||||
self.assertTrue(hasattr(inner, 'defects'))
|
self.assertHasAttr(inner, 'defects')
|
||||||
self.assertEqual(len(inner.defects), 1)
|
self.assertEqual(len(inner.defects), 1)
|
||||||
self.assertIsInstance(inner.defects[0],
|
self.assertIsInstance(inner.defects[0],
|
||||||
errors.StartBoundaryNotFoundDefect)
|
errors.StartBoundaryNotFoundDefect)
|
||||||
|
|
@ -2340,7 +2340,7 @@ counter to RFC 2822, there's no separating newline here
|
||||||
# test_defect_handling
|
# test_defect_handling
|
||||||
def test_lying_multipart(self):
|
def test_lying_multipart(self):
|
||||||
msg = self._msgobj('msg_41.txt')
|
msg = self._msgobj('msg_41.txt')
|
||||||
self.assertTrue(hasattr(msg, 'defects'))
|
self.assertHasAttr(msg, 'defects')
|
||||||
self.assertEqual(len(msg.defects), 2)
|
self.assertEqual(len(msg.defects), 2)
|
||||||
self.assertIsInstance(msg.defects[0],
|
self.assertIsInstance(msg.defects[0],
|
||||||
errors.NoBoundaryInMultipartDefect)
|
errors.NoBoundaryInMultipartDefect)
|
||||||
|
|
@ -3684,9 +3684,7 @@ multipart/report
|
||||||
def test_make_msgid_default_domain(self):
|
def test_make_msgid_default_domain(self):
|
||||||
with patch('socket.getfqdn') as mock_getfqdn:
|
with patch('socket.getfqdn') as mock_getfqdn:
|
||||||
mock_getfqdn.return_value = domain = 'pythontest.example.com'
|
mock_getfqdn.return_value = domain = 'pythontest.example.com'
|
||||||
self.assertTrue(
|
self.assertEndsWith(email.utils.make_msgid(), '@' + domain + '>')
|
||||||
email.utils.make_msgid().endswith(
|
|
||||||
'@' + domain + '>'))
|
|
||||||
|
|
||||||
def test_Generator_linend(self):
|
def test_Generator_linend(self):
|
||||||
# Issue 14645.
|
# Issue 14645.
|
||||||
|
|
@ -4153,7 +4151,7 @@ Here's the message body
|
||||||
"--BOUNDARY--\n"
|
"--BOUNDARY--\n"
|
||||||
)
|
)
|
||||||
msg = email.message_from_string(m)
|
msg = email.message_from_string(m)
|
||||||
self.assertTrue(msg.get_payload(0).get_payload().endswith('\r\n'))
|
self.assertEndsWith(msg.get_payload(0).get_payload(), '\r\n')
|
||||||
|
|
||||||
|
|
||||||
class Test8BitBytesHandling(TestEmailBase):
|
class Test8BitBytesHandling(TestEmailBase):
|
||||||
|
|
|
||||||
|
|
@ -1303,12 +1303,12 @@ class TestMbox(_TestMboxMMDF, unittest.TestCase):
|
||||||
self._box.add('From: foo\n\n0') # No newline at the end
|
self._box.add('From: foo\n\n0') # No newline at the end
|
||||||
with open(self._path, encoding='utf-8') as f:
|
with open(self._path, encoding='utf-8') as f:
|
||||||
data = f.read()
|
data = f.read()
|
||||||
self.assertEqual(data[-3:], '0\n\n')
|
self.assertEndsWith(data, '0\n\n')
|
||||||
|
|
||||||
self._box.add('From: foo\n\n0\n') # Newline at the end
|
self._box.add('From: foo\n\n0\n') # Newline at the end
|
||||||
with open(self._path, encoding='utf-8') as f:
|
with open(self._path, encoding='utf-8') as f:
|
||||||
data = f.read()
|
data = f.read()
|
||||||
self.assertEqual(data[-3:], '0\n\n')
|
self.assertEndsWith(data, '0\n\n')
|
||||||
|
|
||||||
|
|
||||||
class TestMMDF(_TestMboxMMDF, unittest.TestCase):
|
class TestMMDF(_TestMboxMMDF, unittest.TestCase):
|
||||||
|
|
@ -2357,7 +2357,7 @@ class MaildirTestCase(unittest.TestCase):
|
||||||
# Test for regression on bug #117490:
|
# Test for regression on bug #117490:
|
||||||
# Make sure the boxes attribute actually gets set.
|
# Make sure the boxes attribute actually gets set.
|
||||||
self.mbox = mailbox.Maildir(os_helper.TESTFN)
|
self.mbox = mailbox.Maildir(os_helper.TESTFN)
|
||||||
#self.assertTrue(hasattr(self.mbox, "boxes"))
|
#self.assertHasAttr(self.mbox, "boxes")
|
||||||
#self.assertEqual(len(self.mbox.boxes), 0)
|
#self.assertEqual(len(self.mbox.boxes), 0)
|
||||||
self.assertIsNone(self.mbox.next())
|
self.assertIsNone(self.mbox.next())
|
||||||
self.assertIsNone(self.mbox.next())
|
self.assertIsNone(self.mbox.next())
|
||||||
|
|
|
||||||
|
|
@ -257,7 +257,7 @@ class DummyPOP3Server(asyncore.dispatcher, threading.Thread):
|
||||||
|
|
||||||
class TestPOP3Class(TestCase):
|
class TestPOP3Class(TestCase):
|
||||||
def assertOK(self, resp):
|
def assertOK(self, resp):
|
||||||
self.assertTrue(resp.startswith(b"+OK"))
|
self.assertStartsWith(resp, b"+OK")
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.server = DummyPOP3Server((HOST, PORT))
|
self.server = DummyPOP3Server((HOST, PORT))
|
||||||
|
|
@ -324,7 +324,7 @@ class TestPOP3Class(TestCase):
|
||||||
self.assertEqual(self.client.list()[1:],
|
self.assertEqual(self.client.list()[1:],
|
||||||
([b'1 1', b'2 2', b'3 3', b'4 4', b'5 5'],
|
([b'1 1', b'2 2', b'3 3', b'4 4', b'5 5'],
|
||||||
25))
|
25))
|
||||||
self.assertTrue(self.client.list('1').endswith(b"OK 1 1"))
|
self.assertEndsWith(self.client.list('1'), b"OK 1 1")
|
||||||
|
|
||||||
def test_retr(self):
|
def test_retr(self):
|
||||||
expected = (b'+OK 116 bytes',
|
expected = (b'+OK 116 bytes',
|
||||||
|
|
@ -459,7 +459,7 @@ class TestPOP3_SSLClass(TestPOP3Class):
|
||||||
context=ctx)
|
context=ctx)
|
||||||
self.assertIsInstance(self.client.sock, ssl.SSLSocket)
|
self.assertIsInstance(self.client.sock, ssl.SSLSocket)
|
||||||
self.assertIs(self.client.sock.context, ctx)
|
self.assertIs(self.client.sock.context, ctx)
|
||||||
self.assertTrue(self.client.noop().startswith(b'+OK'))
|
self.assertStartsWith(self.client.noop(), b'+OK')
|
||||||
|
|
||||||
def test_stls(self):
|
def test_stls(self):
|
||||||
self.assertRaises(poplib.error_proto, self.client.stls)
|
self.assertRaises(poplib.error_proto, self.client.stls)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue