mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
#20098: add mangle_from_ policy option.
This defaults to True in the compat32 policy for backward compatibility, but to False for all new policies. Patch by Milan Oberkirch, with a few tweaks.
This commit is contained in:
parent
224ef3ec3b
commit
fdb23c2fe5
7 changed files with 76 additions and 5 deletions
|
@ -140,6 +140,28 @@ class TestGeneratorBase:
|
|||
g.flatten(msg, linesep='\n')
|
||||
self.assertEqual(s.getvalue(), self.typ(expected))
|
||||
|
||||
def test_set_mangle_from_via_policy(self):
|
||||
source = textwrap.dedent("""\
|
||||
Subject: test that
|
||||
from is mangeld in the body!
|
||||
|
||||
From time to time I write a rhyme.
|
||||
""")
|
||||
variants = (
|
||||
(None, True),
|
||||
(policy.compat32, True),
|
||||
(policy.default, False),
|
||||
(policy.default.clone(mangle_from_=True), True),
|
||||
)
|
||||
for p, mangle in variants:
|
||||
expected = source.replace('From ', '>From ') if mangle else source
|
||||
with self.subTest(policy=p, mangle_from_=mangle):
|
||||
msg = self.msgmaker(self.typ(source))
|
||||
s = self.ioclass()
|
||||
g = self.genclass(s, policy=p)
|
||||
g.flatten(msg)
|
||||
self.assertEqual(s.getvalue(), self.typ(expected))
|
||||
|
||||
|
||||
class TestGenerator(TestGeneratorBase, TestEmailBase):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue