diff options
author | R David Murray <rdmurray@bitdance.com> | 2016-09-09 19:00:09 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2016-09-09 19:00:09 (GMT) |
commit | 94a7927cc6ad7c2fa986cc207f1f655eb017fa18 (patch) | |
tree | 83f61a38801af0735f31454c04190c1b5a451e14 /Lib/test | |
parent | de02b084e6e5c57be32414da87111679a89049f7 (diff) | |
download | cpython-94a7927cc6ad7c2fa986cc207f1f655eb017fa18.zip cpython-94a7927cc6ad7c2fa986cc207f1f655eb017fa18.tar.gz cpython-94a7927cc6ad7c2fa986cc207f1f655eb017fa18.tar.bz2 |
#28047: Fix calculation of base64 line length.
This is buggy in the old email code as well, but it doesn't affect anything
there because only the default line length is ever used there.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_email/__init__.py | 12 | ||||
-rw-r--r-- | Lib/test/test_email/test_inversion.py | 23 |
2 files changed, 32 insertions, 3 deletions
diff --git a/Lib/test/test_email/__init__.py b/Lib/test/test_email/__init__.py index d2f7d31..d4a03ee 100644 --- a/Lib/test/test_email/__init__.py +++ b/Lib/test/test_email/__init__.py @@ -121,6 +121,10 @@ def parameterize(cls): Note: if and only if the generated test name is a valid identifier can it be used to select the test individually from the unittest command line. + The values in the params dict can be a single value, a tuple, or a + dict. If a single value of a tuple, it is passed to the test function + as positional arguments. If a dict, it is a passed via **kw. + """ paramdicts = {} testers = collections.defaultdict(list) @@ -149,8 +153,12 @@ def parameterize(cls): if name.startswith(paramsname): testnameroot = 'test_' + name[len(paramsname):] for paramname, params in paramsdict.items(): - test = (lambda self, name=name, params=params: - getattr(self, name)(*params)) + if hasattr(params, 'keys'): + test = (lambda self, name=name, params=params: + getattr(self, name)(**params)) + else: + test = (lambda self, name=name, params=params: + getattr(self, name)(*params)) testname = testnameroot + '_' + paramname test.__name__ = testname testfuncs[testname] = test diff --git a/Lib/test/test_email/test_inversion.py b/Lib/test/test_email/test_inversion.py index f36e33d..8e8d676 100644 --- a/Lib/test/test_email/test_inversion.py +++ b/Lib/test/test_email/test_inversion.py @@ -7,6 +7,7 @@ producing RFC valid messages. import io import unittest from email import policy, message_from_bytes +from email.message import EmailMessage from email.generator import BytesGenerator from test.test_email import TestEmailBase, parameterize @@ -23,7 +24,10 @@ def dedent(bstr): @parameterize -class TestInversion(TestEmailBase, unittest.TestCase): +class TestInversion(TestEmailBase): + + policy = policy.default + message = EmailMessage def msg_as_input(self, msg): m = message_from_bytes(msg, policy=policy.SMTP) @@ -44,6 +48,23 @@ class TestInversion(TestEmailBase, unittest.TestCase): } + payload_params = { + 'plain_text': dict(payload='This is a test\n'*20), + 'base64_text': dict(payload=(('xy a'*40+'\n')*5), cte='base64'), + 'qp_text': dict(payload=(('xy a'*40+'\n')*5), cte='quoted-printable'), + } + + def payload_as_body(self, payload, **kw): + msg = self._make_message() + msg['From'] = 'foo' + msg['To'] = 'bar' + msg['Subject'] = 'payload round trip test' + msg.set_content(payload, **kw) + b = bytes(msg) + msg2 = message_from_bytes(b, policy=self.policy) + self.assertEqual(bytes(msg2), b) + self.assertEqual(msg2.get_content(), payload) + if __name__ == '__main__': unittest.main() |