[Python-checkins] bpo-43651: PEP 597: Fix test_email (GH-25158)
methane
webhook-mailer at python.org
Sun Apr 4 23:30:21 EDT 2021
https://github.com/python/cpython/commit/de522a89e42a35da9275169b113460c3581e32d7
commit: de522a89e42a35da9275169b113460c3581e32d7
branch: master
author: Inada Naoki <songofacandy at gmail.com>
committer: methane <songofacandy at gmail.com>
date: 2021年04月05日T12:30:12+09:00
summary:
bpo-43651: PEP 597: Fix test_email (GH-25158)
files:
M Lib/test/test_email/__init__.py
M Lib/test/test_email/test_email.py
diff --git a/Lib/test/test_email/__init__.py b/Lib/test/test_email/__init__.py
index 888751e9e617f..5d708e6e97efe 100644
--- a/Lib/test/test_email/__init__.py
+++ b/Lib/test/test_email/__init__.py
@@ -38,7 +38,7 @@ def __init__(self, *args, **kw):
ndiffAssertEqual = unittest.TestCase.assertEqual
def _msgobj(self, filename):
- with openfile(filename) as fp:
+ with openfile(filename, encoding="utf-8") as fp:
return email.message_from_file(fp, policy=self.policy)
def _str_msg(self, string, message=None, policy=None):
diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py
index 720a63b4e48ff..eed60142b19e3 100644
--- a/Lib/test/test_email/test_email.py
+++ b/Lib/test/test_email/test_email.py
@@ -214,7 +214,7 @@ def test_make_boundary(self):
def test_message_rfc822_only(self):
# Issue 7970: message/rfc822 not in multipart parsed by
# HeaderParser caused an exception when flattened.
- with openfile('msg_46.txt') as fp:
+ with openfile('msg_46.txt', encoding="utf-8") as fp:
msgdata = fp.read()
parser = HeaderParser()
msg = parser.parsestr(msgdata)
@@ -225,7 +225,7 @@ def test_message_rfc822_only(self):
def test_byte_message_rfc822_only(self):
# Make sure new bytes header parser also passes this.
- with openfile('msg_46.txt') as fp:
+ with openfile('msg_46.txt', encoding="utf-8") as fp:
msgdata = fp.read().encode('ascii')
parser = email.parser.BytesHeaderParser()
msg = parser.parsebytes(msgdata)
@@ -274,7 +274,7 @@ def test_get_payload_n_raises_on_non_multipart(self):
def test_decoded_generator(self):
eq = self.assertEqual
msg = self._msgobj('msg_07.txt')
- with openfile('msg_17.txt') as fp:
+ with openfile('msg_17.txt', encoding="utf-8") as fp:
text = fp.read()
s = StringIO()
g = DecodedGenerator(s)
@@ -295,7 +295,7 @@ def test__contains__(self):
def test_as_string(self):
msg = self._msgobj('msg_01.txt')
- with openfile('msg_01.txt') as fp:
+ with openfile('msg_01.txt', encoding="utf-8") as fp:
text = fp.read()
self.assertEqual(text, str(msg))
fullrepr = msg.as_string(unixfrom=True)
@@ -349,7 +349,7 @@ def test_nonascii_as_string_without_content_type_and_cte(self):
def test_as_bytes(self):
msg = self._msgobj('msg_01.txt')
- with openfile('msg_01.txt') as fp:
+ with openfile('msg_01.txt', encoding="utf-8") as fp:
data = fp.read().encode('ascii')
self.assertEqual(data, bytes(msg))
fullrepr = msg.as_bytes(unixfrom=True)
@@ -2436,7 +2436,7 @@ def test_multiline_header(self):
# Test the MIMEMessage class
class TestMIMEMessage(TestEmailBase):
def setUp(self):
- with openfile('msg_11.txt') as fp:
+ with openfile('msg_11.txt', encoding="utf-8") as fp:
self._text = fp.read()
def test_type_error(self):
@@ -2555,7 +2555,7 @@ def test_dsn(self):
def test_epilogue(self):
eq = self.ndiffAssertEqual
- with openfile('msg_21.txt') as fp:
+ with openfile('msg_21.txt', encoding="utf-8") as fp:
text = fp.read()
msg = Message()
msg['From'] = 'aperson at dom.ain'
@@ -2610,7 +2610,7 @@ def test_no_nl_preamble(self):
def test_default_type(self):
eq = self.assertEqual
- with openfile('msg_30.txt') as fp:
+ with openfile('msg_30.txt', encoding="utf-8") as fp:
msg = email.message_from_file(fp)
container1 = msg.get_payload(0)
eq(container1.get_default_type(), 'message/rfc822')
@@ -2627,7 +2627,7 @@ def test_default_type(self):
def test_default_type_with_explicit_container_type(self):
eq = self.assertEqual
- with openfile('msg_28.txt') as fp:
+ with openfile('msg_28.txt', encoding="utf-8") as fp:
msg = email.message_from_file(fp)
container1 = msg.get_payload(0)
eq(container1.get_default_type(), 'message/rfc822')
@@ -2753,7 +2753,7 @@ class TestIdempotent(TestEmailBase):
linesep = '\n'
def _msgobj(self, filename):
- with openfile(filename) as fp:
+ with openfile(filename, encoding="utf-8") as fp:
data = fp.read()
msg = email.message_from_string(data)
return msg, data
@@ -2909,7 +2909,7 @@ def test_parser(self):
# Test various other bits of the package's functionality
class TestMiscellaneous(TestEmailBase):
def test_message_from_string(self):
- with openfile('msg_01.txt') as fp:
+ with openfile('msg_01.txt', encoding="utf-8") as fp:
text = fp.read()
msg = email.message_from_string(text)
s = StringIO()
@@ -2920,7 +2920,7 @@ def test_message_from_string(self):
self.assertEqual(text, s.getvalue())
def test_message_from_file(self):
- with openfile('msg_01.txt') as fp:
+ with openfile('msg_01.txt', encoding="utf-8") as fp:
text = fp.read()
fp.seek(0)
msg = email.message_from_file(fp)
@@ -2932,7 +2932,7 @@ def test_message_from_file(self):
self.assertEqual(text, s.getvalue())
def test_message_from_string_with_class(self):
- with openfile('msg_01.txt') as fp:
+ with openfile('msg_01.txt', encoding="utf-8") as fp:
text = fp.read()
# Create a subclass
@@ -2942,7 +2942,7 @@ class MyMessage(Message):
msg = email.message_from_string(text, MyMessage)
self.assertIsInstance(msg, MyMessage)
# Try something more complicated
- with openfile('msg_02.txt') as fp:
+ with openfile('msg_02.txt', encoding="utf-8") as fp:
text = fp.read()
msg = email.message_from_string(text, MyMessage)
for subpart in msg.walk():
@@ -2953,11 +2953,11 @@ def test_message_from_file_with_class(self):
class MyMessage(Message):
pass
- with openfile('msg_01.txt') as fp:
+ with openfile('msg_01.txt', encoding="utf-8") as fp:
msg = email.message_from_file(fp, MyMessage)
self.assertIsInstance(msg, MyMessage)
# Try something more complicated
- with openfile('msg_02.txt') as fp:
+ with openfile('msg_02.txt', encoding="utf-8") as fp:
msg = email.message_from_file(fp, MyMessage)
for subpart in msg.walk():
self.assertIsInstance(subpart, MyMessage)
@@ -3386,7 +3386,7 @@ def test_make_msgid_default_domain(self):
def test_Generator_linend(self):
# Issue 14645.
- with openfile('msg_26.txt', newline='\n') as f:
+ with openfile('msg_26.txt', encoding="utf-8", newline='\n') as f:
msgtxt = f.read()
msgtxt_nl = msgtxt.replace('\r\n', '\n')
msg = email.message_from_string(msgtxt)
@@ -3397,7 +3397,7 @@ def test_Generator_linend(self):
def test_BytesGenerator_linend(self):
# Issue 14645.
- with openfile('msg_26.txt', newline='\n') as f:
+ with openfile('msg_26.txt', encoding="utf-8", newline='\n') as f:
msgtxt = f.read()
msgtxt_nl = msgtxt.replace('\r\n', '\n')
msg = email.message_from_string(msgtxt_nl)
@@ -3456,7 +3456,7 @@ def test_body_line_iterator(self):
it = iterators.body_line_iterator(msg)
lines = list(it)
eq(len(lines), 43)
- with openfile('msg_19.txt') as fp:
+ with openfile('msg_19.txt', encoding="utf-8") as fp:
neq(EMPTYSTRING.join(lines), fp.read())
def test_typed_subpart_iterator(self):
@@ -3597,7 +3597,7 @@ class TestParsers(TestEmailBase):
def test_header_parser(self):
eq = self.assertEqual
# Parse only the headers of a complex multipart MIME document
- with openfile('msg_02.txt') as fp:
+ with openfile('msg_02.txt', encoding="utf-8") as fp:
msg = HeaderParser().parse(fp)
eq(msg['from'], 'ppp-request at zzz.org')
eq(msg['to'], 'ppp at zzz.org')
@@ -3631,12 +3631,12 @@ def test_bytes_parser_on_exception_does_not_close_file(self):
self.assertFalse(fp.closed)
def test_parser_does_not_close_file(self):
- with openfile('msg_02.txt', 'r') as fp:
+ with openfile('msg_02.txt', encoding="utf-8") as fp:
email.parser.Parser().parse(fp)
self.assertFalse(fp.closed)
def test_parser_on_exception_does_not_close_file(self):
- with openfile('msg_15.txt', 'r') as fp:
+ with openfile('msg_15.txt', encoding="utf-8") as fp:
parser = email.parser.Parser
self.assertRaises(email.errors.StartBoundaryNotFoundDefect,
parser(policy=email.policy.strict).parse, fp)
@@ -3680,7 +3680,7 @@ def test_whitespace_continuation_last_header(self):
def test_crlf_separation(self):
eq = self.assertEqual
- with openfile('msg_26.txt', newline='\n') as fp:
+ with openfile('msg_26.txt', encoding="utf-8", newline='\n') as fp:
msg = Parser().parse(fp)
eq(len(msg.get_payload()), 2)
part1 = msg.get_payload(0)
@@ -3691,7 +3691,7 @@ def test_crlf_separation(self):
def test_crlf_flatten(self):
# Using newline='\n' preserves the crlfs in this input file.
- with openfile('msg_26.txt', newline='\n') as fp:
+ with openfile('msg_26.txt', encoding="utf-8", newline='\n') as fp:
text = fp.read()
msg = email.message_from_string(text)
s = StringIO()
@@ -3704,7 +3704,7 @@ def test_crlf_flatten(self):
def test_multipart_digest_with_extra_mime_headers(self):
eq = self.assertEqual
neq = self.ndiffAssertEqual
- with openfile('msg_28.txt') as fp:
+ with openfile('msg_28.txt', encoding="utf-8") as fp:
msg = email.message_from_file(fp)
# Structure is:
# multipart/digest
@@ -5447,7 +5447,7 @@ def test_should_not_hang_on_invalid_ew_messages(self):
class TestSigned(TestEmailBase):
def _msg_and_obj(self, filename):
- with openfile(filename) as fp:
+ with openfile(filename, encoding="utf-8") as fp:
original = fp.read()
msg = email.message_from_string(original)
return original, msg
More information about the Python-checkins
mailing list