Skip to content

Commit b42a4db

Browse files
committed
pythongh-92613: Silence uuencode deprecation warnings in email tests
1 parent 87b9035 commit b42a4db

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

Lib/test/test_email/test_email.py

+17-10
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from email import utils
4040

4141
from test.support import threading_helper
42+
from test.support.warnings_helper import check_warnings
4243
from test.support.os_helper import unlink
4344
from test.test_email import openfile, TestEmailBase
4445

@@ -50,6 +51,8 @@
5051
EMPTYSTRING = ''
5152
SPACE = ' '
5253

54+
UU_WARNING_FILTER = ('.*uu.*', DeprecationWarning)
55+
5356

5457
# Test various aspects of the Message class's API
5558
class TestMessageAPI(TestEmailBase):
@@ -263,10 +266,12 @@ def test_get_decoded_uu_payload(self):
263266
msg.set_payload('begin 666 -\n+:&5L;&\\@=V]R;&0 \n \nend\n')
264267
for cte in ('x-uuencode', 'uuencode', 'uue', 'x-uue'):
265268
msg['content-transfer-encoding'] = cte
266-
eq(msg.get_payload(decode=True), b'hello world')
269+
with check_warnings(UU_WARNING_FILTER):
270+
eq(msg.get_payload(decode=True), b'hello world')
267271
# Now try some bogus data
268272
msg.set_payload('foo')
269-
eq(msg.get_payload(decode=True), b'foo')
273+
with check_warnings(UU_WARNING_FILTER):
274+
eq(msg.get_payload(decode=True), b'foo')
270275

271276
def test_get_payload_n_raises_on_non_multipart(self):
272277
msg = Message()
@@ -740,12 +745,13 @@ def test_binary_uuencode_payload(self):
740745
msg['content-type'] = 'text/plain; charset=%s' % charset
741746
msg['content-transfer-encoding'] = encoding
742747
msg.set_payload(b"begin 666 -\n)9F]OYI:'8F%R\n \nend\n")
743-
self.assertEqual(
744-
msg.get_payload(decode=True),
745-
b'foo\xe6\x96\x87bar',
746-
str(('get_payload returns wrong result ',
747-
'with charset {0} and encoding {1}.')).\
748-
format(charset, encoding))
748+
with check_warnings(UU_WARNING_FILTER):
749+
self.assertEqual(
750+
msg.get_payload(decode=True),
751+
b'foo\xe6\x96\x87bar',
752+
str(('get_payload returns wrong result ',
753+
'with charset {0} and encoding {1}.')).\
754+
format(charset, encoding))
749755

750756
def test_add_header_with_name_only_param(self):
751757
msg = Message()
@@ -3963,8 +3969,9 @@ def test_8bit_in_uuencode_body(self):
39633969
cte='uuencode',
39643970
bodyline='<,.V<W1A; á ').encode('utf-8')
39653971
msg = email.message_from_bytes(m)
3966-
self.assertEqual(msg.get_payload(decode=True),
3967-
'<,.V<W1A; á \n'.encode('utf-8'))
3972+
with check_warnings(UU_WARNING_FILTER):
3973+
self.assertEqual(msg.get_payload(decode=True),
3974+
'<,.V<W1A; á \n'.encode('utf-8'))
39683975

39693976

39703977
headertest_headers = (

0 commit comments

Comments
 (0)