annotate test/test_misc.py @ 5542:29346d92d80c

Fix email interfaces with Python 3 (issue 2550974, issue 2551000). This patch fixes various issues handling incoming email with roundup-mailgw with Python 3. Incoming email must always be handled as bytes, not strings, because it may contain 8-bit-encoded MIME parts with different encodings in each part. When handling piped input, that means using sys.stdin.buffer in Python 3 for binary input, along with message_from_binary_file, not sys.stdin which is text input and may be for the wrong encoding and not message_from_file. (In turn, tests that use MailGW.main with text input are affected so an s2b call is inserted in the test code and it is made to use BytesIO not StringIO. Properly all the test messages in test_mailgw.py ought to use b'' explicitly rather than having such an s2b conversion, and there ought to be test messages using 8-bit encodings with non-ASCII characters to verify that that case works.) imaplib and poplib return bytes not strings with Python 3 (from inspection of the code, not tested), as is necessary for the above reasons. Thus, the handling of IMAP and POP messages must expect bytes and handle the data accordingly. For messages from mailboxes, I saw the same problem described in issue 2551000 for a multipart message with a single (non-ASCII) part. The Roundup code requires RoundupMessage not email.message.Message to be used recursively for all MIME parts of a message. Because the mailbox module uses email.message_from_* directly without passing the _class argument to them, fixing this requires temporarily patching the email module to ensure _class=RoundupMessage gets passed to those methods.
author Joseph Myers <jsm@polyomino.org.uk>
date Sun, 16 Sep 2018 13:55:53 +0000
parents 9a09719b0d8e
children 3b945aee0919
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5155
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
1 # misc tests
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
2
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
3 import unittest
5481
9a09719b0d8e helper to allow comparing dicts and None values in Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents: 5155
diff changeset
4 import roundup.anypy.cmp_
5155
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
5 from roundup.cgi.accept_language import parse
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
6
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
7 class AcceptLanguageTest(unittest.TestCase):
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
8 def testParse(self):
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
9 self.assertEqual(parse("da, en-gb;q=0.8, en;q=0.7"),
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
10 ['da', 'en_gb', 'en'])
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
11 self.assertEqual(parse("en;q=0.2, fr;q=1"), ['fr', 'en'])
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
12 self.assertEqual(parse("zn; q = 0.2 ,pt-br;q =1"), ['pt_br', 'zn'])
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
13 self.assertEqual(parse("es-AR"), ['es_AR'])
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
14 self.assertEqual(parse("es-es-cat"), ['es_es_cat'])
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
15 self.assertEqual(parse(""), [])
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
16 self.assertEqual(parse(None),[])
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
17 self.assertEqual(parse(" "), [])
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
18 self.assertEqual(parse("en,"), ['en'])
5481
9a09719b0d8e helper to allow comparing dicts and None values in Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents: 5155
diff changeset
19
9a09719b0d8e helper to allow comparing dicts and None values in Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents: 5155
diff changeset
20 class CmpTest(unittest.TestCase):
9a09719b0d8e helper to allow comparing dicts and None values in Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents: 5155
diff changeset
21 def testCmp(self):
9a09719b0d8e helper to allow comparing dicts and None values in Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents: 5155
diff changeset
22 roundup.anypy.cmp_._test()

Roundup Issue Tracker: http://roundup-tracker.org/