Skip to content

Commit 30f913f

Browse files
committed
tests: open bounce fixture files in binary mode for Python 3
email.message_from_file() in Python 3 opens files as text with the system encoding (UTF-8). Some bounce fixture files contain Latin-1 bytes, causing UnicodeDecodeError. Use binary mode with email.message_from_binary_file() instead.
1 parent 7735717 commit 30f913f

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

tests/test_bounces.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ def test_bounce(self):
194194
for modname, file, addrs in self.DATA:
195195
module = 'Mailman.Bouncers.' + modname
196196
__import__(module)
197-
fp = open(os.path.join(_TESTDIR, 'bounces', file))
197+
fp = open(os.path.join(_TESTDIR, 'bounces', file), 'rb')
198198
try:
199-
msg = email.message_from_file(fp)
199+
msg = email.message_from_binary_file(fp)
200200
finally:
201201
fp.close()
202202
foundaddrs = sys.modules[module].process(msg)
@@ -214,9 +214,9 @@ def test_bounce(self):
214214
def test_SMTP32_failure(self):
215215
from Mailman.Bouncers import SMTP32
216216
# This file has no X-Mailer: header
217-
fp = open(os.path.join(_TESTDIR, 'bounces', 'postfix_01.txt'))
217+
fp = open(os.path.join(_TESTDIR, 'bounces', 'postfix_01.txt'), 'rb')
218218
try:
219-
msg = email.message_from_file(fp)
219+
msg = email.message_from_binary_file(fp)
220220
finally:
221221
fp.close()
222222
self.failIf(msg['x-mailer'] is not None)

0 commit comments

Comments
 (0)