https://github.com/python/cpython/commit/34d3495f32ccacbdcb1084cfeccaa079161cb99e
commit: 34d3495f32ccacbdcb1084cfeccaa079161cb99e
branch: 3.13
author: Miss Islington (bot) <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2025-05-22T09:40:04Z
summary:

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

(cherry picked from commit 522766aa23b110257d5e31128ff5a5575715e880)

Co-authored-by: Serhiy Storchaka <[email protected]>

files:
M Lib/test/test_email/__init__.py
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/__init__.py b/Lib/test/test_email/__init__.py
index 5d708e6e97efe7..455dc48facfd24 100644
--- a/Lib/test/test_email/__init__.py
+++ b/Lib/test/test_email/__init__.py
@@ -5,6 +5,7 @@
 from email.message import Message
 from email._policybase import compat32
 from test.support import load_package_tests
+from test.support.testcase import ExtraAssertions
 from test.test_email import __file__ as landmark
 
 # Load all tests in package
@@ -20,7 +21,7 @@ def openfile(filename, *args, **kws):
 
 
 # Base test class
-class TestEmailBase(unittest.TestCase):
+class TestEmailBase(unittest.TestCase, ExtraAssertions):
 
     maxDiff = None
     # Currently the default policy is compat32.  By setting that as the default
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 925a638572d79c..bbb0102c5018a9 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):
@@ -2203,7 +2203,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)
@@ -2315,7 +2315,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)
@@ -3659,9 +3659,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.
@@ -4128,7 +4126,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 a1d72aed9d8939..940baf3941507f 100644
--- a/Lib/test/test_mailbox.py
+++ b/Lib/test/test_mailbox.py
@@ -13,6 +13,7 @@
 from test.support import os_helper
 from test.support import refleak_helper
 from test.support import socket_helper
+from test.support.testcase import ExtraAssertions
 import unittest
 import textwrap
 import mailbox
@@ -1266,7 +1267,7 @@ def test_relock(self):
         self._box.close()
 
 
-class TestMbox(_TestMboxMMDF, unittest.TestCase):
+class TestMbox(_TestMboxMMDF, unittest.TestCase, ExtraAssertions):
 
     _factory = lambda self, path, factory=None: mailbox.mbox(path, factory)
 
@@ -1304,12 +1305,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):
@@ -2358,7 +2359,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..eb6dab40152a2a 100644
--- a/Lib/test/test_poplib.py
+++ b/Lib/test/test_poplib.py
@@ -17,6 +17,7 @@
 from test.support import threading_helper
 from test.support import asynchat
 from test.support import asyncore
+from test.support.testcase import ExtraAssertions
 
 
 test_support.requires_working_socket(module=True)
@@ -255,9 +256,9 @@ def handle_error(self):
         raise
 
 
-class TestPOP3Class(TestCase):
+class TestPOP3Class(TestCase, ExtraAssertions):
     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 +325,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 +460,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 -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to