コード例 #1
0
class TestPickleCopyMessage(TestEmailBase):

    # Message objects are a sequence, so we have to make them a one-tuple in
    # msg_params so they get passed to the parameterized test method as a
    # single argument instead of as a list of headers.
    msg_params = {}

    # Note: there will be no custom header objects in the parsed message.
    msg_params['parsed'] = (email.message_from_string(textwrap.dedent("""\
        Date: Tue, 29 May 2012 09:24:26 +1000
        From: [email protected]
        To: [email protected]
        Subject: help

        I think I forgot the ring.
        """),
                                                      policy=policy.default), )

    msg_params['created'] = (email_message.Message(policy=policy.default), )
    msg_params['created'][0]['Date'] = 'Tue, 29 May 2012 09:24:26 +1000'
    msg_params['created'][0]['From'] = '*****@*****.**'
    msg_params['created'][0]['To'] = '*****@*****.**'
    msg_params['created'][0]['Subject'] = 'help'
    msg_params['created'][0].set_payload('I think I forgot the ring.')

    def msg_as_deepcopy(self, msg):
        msg2 = copy.deepcopy(msg)
        self.assertEqual(msg2.as_string(), msg.as_string())

    def msg_as_pickle(self, msg):
        p = pickle.dumps(msg)
        msg2 = pickle.loads(p)
        self.assertEqual(msg2.as_string(), msg.as_string())
コード例 #2
0
 def _make_msg(self, source='Subject: test\n\n', policy=None):
     self.policy = email_policy.default.clone() if policy is None else policy
     return email.message_from_string(source, policy=self.policy)
コード例 #3
0
 def test_message_from_string(self):
     with self.assertRaisesRegex(Exception, "^test$"):
         email.message_from_string("Subject: test\n\n",
                                   policy=self.MyPolicy)
コード例 #4
0
 def test_custom_message_gets_policy_if_possible_from_string(self):
     msg = email.message_from_string("Subject: bogus\n\nmsg\n",
                                     self.MyMessage,
                                     policy=self.MyPolicy)
     self.assertTrue(isinstance(msg, self.MyMessage))
     self.assertIs(msg.check_policy, self.MyPolicy)
コード例 #5
0
 def _make_msg(self, source='Subject: test\n\n', policy=None):
     self.policy = email_policy.default.clone(
     ) if policy is None else policy
     return email.message_from_string(source, policy=self.policy)
コード例 #6
0
 def test_message_from_string(self):
     with self.assertRaisesRegex(Exception, "^test$"):
         email.message_from_string("Subject: test\n\n",
                                   policy=self.MyPolicy)
コード例 #7
0
ファイル: __init__.py プロジェクト: 9seconds/python-future
 def _str_msg(self, string, message=Message, policy=None):
     if policy is None:
         policy = self.policy
     return email.message_from_string(string, message, policy=policy)
コード例 #8
0
ファイル: __init__.py プロジェクト: krischer/python-future
 def _str_msg(self, string, message=Message, policy=None):
     if policy is None:
         policy = self.policy
     return email.message_from_string(string, message, policy=policy)
コード例 #9
0
 def test_custom_message_gets_policy_if_possible_from_string(self):
     msg = email.message_from_string("Subject: bogus\n\nmsg\n",
                                     self.MyMessage,
                                     policy=self.MyPolicy)
     self.assertTrue(isinstance(msg, self.MyMessage))
     self.assertIs(msg.check_policy, self.MyPolicy)