diff options
author | R David Murray <rdmurray@bitdance.com> | 2013-02-04 20:22:53 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2013-02-04 20:22:53 (GMT) |
commit | 844b0e69717bf97bd7fbd055368ac398b99ec7e1 (patch) | |
tree | 6d74607155730a01582342be94394b8275c053bd /Lib/test/test_email | |
parent | 36b365ccff21cdc563a3f4209b0bbaa079572487 (diff) | |
download | cpython-844b0e69717bf97bd7fbd055368ac398b99ec7e1.zip cpython-844b0e69717bf97bd7fbd055368ac398b99ec7e1.tar.gz cpython-844b0e69717bf97bd7fbd055368ac398b99ec7e1.tar.bz2 |
#16811: Fix folding of headers with no value in provisional policies.
Diffstat (limited to 'Lib/test/test_email')
-rw-r--r-- | Lib/test/test_email/test_inversion.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/Lib/test/test_email/test_inversion.py b/Lib/test/test_email/test_inversion.py new file mode 100644 index 0000000..6f5c534 --- /dev/null +++ b/Lib/test/test_email/test_inversion.py @@ -0,0 +1,45 @@ +"""Test the parser and generator are inverses. + +Note that this is only strictly true if we are parsing RFC valid messages and +producing RFC valid messages. +""" + +import io +import unittest +from email import policy, message_from_bytes +from email.generator import BytesGenerator +from test.test_email import TestEmailBase, parameterize + +# This is like textwrap.dedent for bytes, except that it uses \r\n for the line +# separators on the rebuilt string. +def dedent(bstr): + lines = bstr.splitlines() + if not lines[0].strip(): + raise ValueError("First line must contain text") + stripamt = len(lines[0]) - len(lines[0].lstrip()) + return b'\r\n'.join( + [x[stripamt:] if len(x)>=stripamt else b'' + for x in lines]) + + +@parameterize +class TestInversion(TestEmailBase, unittest.TestCase): + + def msg_as_input(self, msg): + m = message_from_bytes(msg, policy=policy.SMTP) + b = io.BytesIO() + g = BytesGenerator(b) + g.flatten(m) + self.assertEqual(b.getvalue(), msg) + + # XXX: spaces are not preserved correctly here yet in the general case. + msg_params = { + 'header_with_one_space_body': (dedent(b"""\ + From: abc@xyz.com + X-Status:\x20 + Subject: test + + foo + """),), + + } |