summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_mailbox.py
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2012-04-09 02:36:07 (GMT)
committerR David Murray <rdmurray@bitdance.com>2012-04-09 02:36:07 (GMT)
commitb019ee752a6be0bcd4f640f09bce0c5f5215e880 (patch)
treef133252dfbd0da52f86a59a2c489c595c911ebad /Lib/test/test_mailbox.py
parentc988e242408ea793052320fc2174fd124f193a77 (diff)
downloadcpython-b019ee752a6be0bcd4f640f09bce0c5f5215e880.zip
cpython-b019ee752a6be0bcd4f640f09bce0c5f5215e880.tar.gz
cpython-b019ee752a6be0bcd4f640f09bce0c5f5215e880.tar.bz2
#12537: in mailbox avoid depending on knowledge of email package internals
Previously mailbox was copying a list of attributes from one message object to another in order to "copy the message data". This means that any time new attributes were added to email.message.Message, mailbox broke. Now instead it copies all attributes from the source object to the target object, skipping any mailbox-object-specific attributes to produce the same clean initial state it was previously getting by copying only the "known" attributes. David Lam assisted in the development of this patch.
Diffstat (limited to 'Lib/test/test_mailbox.py')
-rw-r--r--Lib/test/test_mailbox.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/test_mailbox.py b/Lib/test/test_mailbox.py
index 95f8e0d..0fe4bd9 100644
--- a/Lib/test/test_mailbox.py
+++ b/Lib/test/test_mailbox.py
@@ -1330,6 +1330,14 @@ class TestMessage(TestBase, unittest.TestCase):
# Initialize with invalid argument
self.assertRaises(TypeError, lambda: self._factory(object()))
+ def test_all_eMM_attribues_exist(self):
+ # Issue 12537
+ eMM = email.message_from_string(_sample_message)
+ msg = self._factory(_sample_message)
+ for attr in eMM.__dict__:
+ self.assertTrue(attr in msg.__dict__,
+ '{} attribute does not exist'.format(attr))
+
def test_become_message(self):
# Take on the state of another message
eMM = email.message_from_string(_sample_message)
@@ -1596,6 +1604,21 @@ class TestMessageConversion(TestBase, unittest.TestCase):
for class_ in self.all_mailbox_types:
self.assertRaises(TypeError, lambda: class_(False))
+ def test_type_specific_attributes_removed_on_conversion(self):
+ reference = {class_: class_(_sample_message).__dict__
+ for class_ in self.all_mailbox_types}
+ for class1 in self.all_mailbox_types:
+ for class2 in self.all_mailbox_types:
+ if class1 is class2:
+ continue
+ source = class1(_sample_message)
+ target = class2(source)
+ type_specific = [a for a in reference[class1]
+ if a not in reference[class2]]
+ for attr in type_specific:
+ self.assertNotIn(attr, target.__dict__,
+ "while converting {} to {}".format(class1, class2))
+
def test_maildir_to_maildir(self):
# Convert MaildirMessage to MaildirMessage
msg_maildir = mailbox.MaildirMessage(_sample_message)