https://github.com/python/cpython/commit/522766aa23b110257d5e31128ff5a5575715e880
commit: 522766aa23b110257d5e31128ff5a5575715e880
branch: main
author: Serhiy Storchaka <storch...@gmail.com>
committer: serhiy-storchaka <storch...@gmail.com>
date: 2025-04-14T09:25:58+03:00
summary:

gh-71339: Use new assertion methods in the email tests (GH-129055)

files:
M Lib/test/test_email/test_contentmanager.py
M Lib/test/test_email/test_defect_handling.py
M Lib/test/test_email/test_email.py
M Lib/test/test_mailbox.py
M Lib/test/test_poplib.py

diff --git a/Lib/test/test_email/test_contentmanager.py 
b/Lib/test/test_email/test_contentmanager.py
index 694cef4ba7e413..dceb54f15e48f4 100644
--- a/Lib/test/test_email/test_contentmanager.py
+++ b/Lib/test/test_email/test_contentmanager.py
@@ -288,7 +288,7 @@ def 
test_get_message_non_rfc822_or_external_body_yields_bytes(self):
 
             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):
         m = self._make_message()
diff --git a/Lib/test/test_email/test_defect_handling.py 
b/Lib/test/test_email/test_defect_handling.py
index 781f657418220c..44e76c8ce5e03a 100644
--- a/Lib/test/test_email/test_defect_handling.py
+++ b/Lib/test/test_email/test_defect_handling.py
@@ -57,7 +57,7 @@ def test_same_boundary_inner_outer(self):
             msg = self._str_msg(source)
         if self.raise_expected: return
         inner = msg.get_payload(0)
-        self.assertTrue(hasattr(inner, 'defects'))
+        self.assertHasAttr(inner, 'defects')
         self.assertEqual(len(self.get_defects(inner)), 1)
         self.assertIsInstance(self.get_defects(inner)[0],
                               errors.StartBoundaryNotFoundDefect)
@@ -151,7 +151,7 @@ def test_lying_multipart(self):
         with self._raise_point(errors.NoBoundaryInMultipartDefect):
             msg = self._str_msg(source)
         if self.raise_expected: return
-        self.assertTrue(hasattr(msg, 'defects'))
+        self.assertHasAttr(msg, 'defects')
         self.assertEqual(len(self.get_defects(msg)), 2)
         self.assertIsInstance(self.get_defects(msg)[0],
                               errors.NoBoundaryInMultipartDefect)
diff --git a/Lib/test/test_email/test_email.py 
b/Lib/test/test_email/test_email.py
index 724af3b787d38b..7b14305f997e5d 100644
--- a/Lib/test/test_email/test_email.py
+++ b/Lib/test/test_email/test_email.py
@@ -210,8 +210,8 @@ def test_make_boundary(self):
         self.assertEqual(msg.items()[0][1], 'multipart/form-data')
         # Trigger creation of boundary
         msg.as_string()
-        self.assertEqual(msg.items()[0][1][:33],
-                        'multipart/form-data; boundary="==')
+        self.assertStartsWith(msg.items()[0][1],
+                              'multipart/form-data; boundary="==')
         # XXX: there ought to be tests of the uniqueness of the boundary, too.
 
     def test_message_rfc822_only(self):
@@ -303,7 +303,7 @@ def test_as_string(self):
         self.assertEqual(text, str(msg))
         fullrepr = msg.as_string(unixfrom=True)
         lines = fullrepr.split('\n')
-        self.assertTrue(lines[0].startswith('From '))
+        self.assertStartsWith(lines[0], 'From ')
         self.assertEqual(text, NL.join(lines[1:]))
 
     def test_as_string_policy(self):
@@ -372,7 +372,7 @@ def test_as_bytes(self):
         self.assertEqual(data, bytes(msg))
         fullrepr = msg.as_bytes(unixfrom=True)
         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:]))
 
     def test_as_bytes_policy(self):
@@ -2228,7 +2228,7 @@ def test_same_boundary_inner_outer(self):
         msg = self._msgobj('msg_15.txt')
         # XXX We can probably eventually do better
         inner = msg.get_payload(0)
-        self.assertTrue(hasattr(inner, 'defects'))
+        self.assertHasAttr(inner, 'defects')
         self.assertEqual(len(inner.defects), 1)
         self.assertIsInstance(inner.defects[0],
                               errors.StartBoundaryNotFoundDefect)
@@ -2340,7 +2340,7 @@ def test_no_separating_blank_line(self):
     # test_defect_handling
     def test_lying_multipart(self):
         msg = self._msgobj('msg_41.txt')
-        self.assertTrue(hasattr(msg, 'defects'))
+        self.assertHasAttr(msg, 'defects')
         self.assertEqual(len(msg.defects), 2)
         self.assertIsInstance(msg.defects[0],
                               errors.NoBoundaryInMultipartDefect)
@@ -3684,9 +3684,7 @@ def test_make_msgid_idstring(self):
     def test_make_msgid_default_domain(self):
         with patch('socket.getfqdn') as mock_getfqdn:
             mock_getfqdn.return_value = domain = 'pythontest.example.com'
-            self.assertTrue(
-                email.utils.make_msgid().endswith(
-                    '@' + domain + '>'))
+            self.assertEndsWith(email.utils.make_msgid(), '@' + domain + '>')
 
     def test_Generator_linend(self):
         # Issue 14645.
@@ -4153,7 +4151,7 @@ def test_CRLFLF_at_end_of_part(self):
             "--BOUNDARY--\n"
           )
         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):
diff --git a/Lib/test/test_mailbox.py b/Lib/test/test_mailbox.py
index 3ecb5eab26d4b9..0169948e453438 100644
--- a/Lib/test/test_mailbox.py
+++ b/Lib/test/test_mailbox.py
@@ -1303,12 +1303,12 @@ def test_message_separator(self):
         self._box.add('From: foo\n\n0')  # No newline at the end
         with open(self._path, encoding='utf-8') as f:
             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
         with open(self._path, encoding='utf-8') as f:
             data = f.read()
-            self.assertEqual(data[-3:], '0\n\n')
+            self.assertEndsWith(data, '0\n\n')
 
 
 class TestMMDF(_TestMboxMMDF, unittest.TestCase):
@@ -2357,7 +2357,7 @@ def test_empty_maildir(self):
         # Test for regression on bug #117490:
         # Make sure the boxes attribute actually gets set.
         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.assertIsNone(self.mbox.next())
         self.assertIsNone(self.mbox.next())
diff --git a/Lib/test/test_poplib.py b/Lib/test/test_poplib.py
index f1ebbeafe0cfb4..ef2da97f86734a 100644
--- a/Lib/test/test_poplib.py
+++ b/Lib/test/test_poplib.py
@@ -257,7 +257,7 @@ def handle_error(self):
 
 class TestPOP3Class(TestCase):
     def assertOK(self, resp):
-        self.assertTrue(resp.startswith(b"+OK"))
+        self.assertStartsWith(resp, b"+OK")
 
     def setUp(self):
         self.server = DummyPOP3Server((HOST, PORT))
@@ -324,7 +324,7 @@ def test_list(self):
         self.assertEqual(self.client.list()[1:],
                          ([b'1 1', b'2 2', b'3 3', b'4 4', b'5 5'],
                           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):
         expected = (b'+OK 116 bytes',
@@ -459,7 +459,7 @@ def test_context(self):
                                         context=ctx)
         self.assertIsInstance(self.client.sock, ssl.SSLSocket)
         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):
         self.assertRaises(poplib.error_proto, self.client.stls)

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to