Rev 6593: Fix minor incompatible change in email python 2.7.6 module. in file:///home/vila/src/bzr/bugs/1303879-py27-issues/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Wed Apr 9 08:00:39 UTC 2014
At file:///home/vila/src/bzr/bugs/1303879-py27-issues/
------------------------------------------------------------
revno: 6593
revision-id: v.ladeuil+lp at free.fr-20140409080039-zq5y8wu59qc8bgnz
parent: pqm at pqm.ubuntu.com-20140403074532-0sdwrky6ie4y20l4
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 1303879-py27-issues
timestamp: Wed 2014-04-09 10:00:39 +0200
message:
Fix minor incompatible change in email python 2.7.6 module.
-------------- next part --------------
=== modified file 'bzrlib/email_message.py'
--- a/bzrlib/email_message.py 2011-12-19 13:23:58 +0000
+++ b/bzrlib/email_message.py 2014-04-09 08:00:39 +0000
@@ -149,7 +149,7 @@
@staticmethod
def send(config, from_address, to_address, subject, body, attachment=None,
- attachment_filename=None, attachment_mime_subtype='plain'):
+ attachment_filename=None, attachment_mime_subtype='plain'):
"""Create an email message and send it with SMTPConnection.
:param config: config object to pass to SMTPConnection constructor.
=== modified file 'bzrlib/tests/test_email_message.py'
--- a/bzrlib/tests/test_email_message.py 2011-12-16 19:18:39 +0000
+++ b/bzrlib/tests/test_email_message.py 2014-04-09 08:00:39 +0000
@@ -14,13 +14,14 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+import sys
from email.Header import decode_header
from bzrlib import __version__ as _bzrlib_version
from bzrlib.email_message import EmailMessage
from bzrlib.errors import BzrBadParameterNotUnicode
from bzrlib.smtp_connection import SMTPConnection
-from bzrlib.tests import TestCase
+from bzrlib import tests
EMPTY_MESSAGE = '''\
From: from at from.com
@@ -65,9 +66,22 @@
body
''' % { 'version': _bzrlib_version, 'boundary': BOUNDARY }
-SIMPLE_MULTIPART_MESSAGE = _MULTIPART_HEAD + '--%s--' % BOUNDARY
-
-COMPLEX_MULTIPART_MESSAGE = _MULTIPART_HEAD + '''\
+
+def final_newline_or_not(msg):
+ if sys.version_info >= (2, 7, 6):
+ # Some internals of python's email module changed in an (minor)
+ # incompatible way: a final newline is appended in 2.7.6...
+ msg += '\n'
+ return msg
+
+
+def simple_multipart_message():
+ msg = _MULTIPART_HEAD + '--%s--' % BOUNDARY
+ return final_newline_or_not(msg)
+
+
+def complex_multipart_message(typ):
+ msg = _MULTIPART_HEAD + '''\
--%(boundary)s
MIME-Version: 1.0
Content-Type: text/%%s; charset="us-ascii"; name="lines.txt"
@@ -81,9 +95,11 @@
e
--%(boundary)s--''' % { 'boundary': BOUNDARY }
-
-
-class TestEmailMessage(TestCase):
+ msg = final_newline_or_not(msg)
+ return msg % (typ,)
+
+
+class TestEmailMessage(tests.TestCase):
def test_empty_message(self):
msg = EmailMessage('from at from.com', 'to at to.com', 'subject')
@@ -100,15 +116,18 @@
msg = EmailMessage('from at from.com', 'to at to.com', 'subject', body)
self.assertEqualDiff(expected, msg.as_string())
- def test_multipart_message(self):
+ def test_multipart_message_simple(self):
msg = EmailMessage('from at from.com', 'to at to.com', 'subject')
msg.add_inline_attachment('body')
- self.assertEqualDiff(SIMPLE_MULTIPART_MESSAGE, msg.as_string(BOUNDARY))
-
+ self.assertEqualDiff(simple_multipart_message(),
+ msg.as_string(BOUNDARY))
+
+
+ def test_multipart_message_complex(self):
msg = EmailMessage('from at from.com', 'to at to.com', 'subject', 'body')
msg.add_inline_attachment(u'a\nb\nc\nd\ne\n', 'lines.txt', 'x-subtype')
- self.assertEqualDiff(COMPLEX_MULTIPART_MESSAGE % 'x-subtype',
- msg.as_string(BOUNDARY))
+ self.assertEqualDiff(complex_multipart_message('x-subtype'),
+ msg.as_string(BOUNDARY))
def test_headers_accept_unicode_and_utf8(self):
for user in [ u'Pepe P\xe9rez <pperez at ejemplo.com>',
@@ -148,40 +167,6 @@
self.assertEqual('to2 at to.com', msg['To'])
self.assertEqual('cc at cc.com', msg['Cc'])
- def test_send(self):
- class FakeConfig:
- def get(self, option):
- return None
-
- messages = []
-
- def send_as_append(_self, msg):
- messages.append(msg.as_string(BOUNDARY))
-
- old_send_email = SMTPConnection.send_email
- try:
- SMTPConnection.send_email = send_as_append
-
- EmailMessage.send(FakeConfig(), 'from at from.com', 'to at to.com',
- 'subject', 'body', u'a\nb\nc\nd\ne\n', 'lines.txt')
- self.assertEqualDiff(COMPLEX_MULTIPART_MESSAGE % 'plain',
- messages[0])
- messages[:] = []
-
- EmailMessage.send(FakeConfig(), 'from at from.com', 'to at to.com',
- 'subject', 'body', u'a\nb\nc\nd\ne\n', 'lines.txt',
- 'x-patch')
- self.assertEqualDiff(COMPLEX_MULTIPART_MESSAGE % 'x-patch',
- messages[0])
- messages[:] = []
-
- EmailMessage.send(FakeConfig(), 'from at from.com', 'to at to.com',
- 'subject', 'body')
- self.assertEqualDiff(SIMPLE_MESSAGE_ASCII , messages[0])
- messages[:] = []
- finally:
- SMTPConnection.send_email = old_send_email
-
def test_address_to_encoded_header(self):
def decode(s):
"""Convert a RFC2047-encoded string to a unicode string."""
@@ -224,3 +209,46 @@
}
for string_, pair in pairs.items():
self.assertEqual(pair, EmailMessage.string_with_encoding(string_))
+
+
+class TestSend(tests.TestCase):
+
+ def setUp(self):
+ super(TestSend, self).setUp()
+ self.messages = []
+
+ def send_as_append(_self, msg):
+ self.messages.append(msg.as_string(BOUNDARY))
+
+ self.overrideAttr(SMTPConnection, 'send_email', send_as_append)
+
+
+
+ def send_email(self, attachment=None, attachment_filename=None,
+ attachment_mime_subtype='plain'):
+ class FakeConfig:
+ def get(self, option):
+ return None
+
+ EmailMessage.send(FakeConfig(), 'from at from.com', 'to at to.com',
+ 'subject', 'body',
+ attachment=attachment,
+ attachment_filename=attachment_filename,
+ attachment_mime_subtype=attachment_mime_subtype)
+
+ def assertMessage(self, expected):
+ self.assertLength(1, self.messages)
+ self.assertEqualDiff(expected, self.messages[0])
+
+ def test_send_plain(self):
+ self.send_email(u'a\nb\nc\nd\ne\n', 'lines.txt')
+ self.assertMessage(complex_multipart_message('plain'))
+
+ def test_send_patch(self):
+ self.send_email(u'a\nb\nc\nd\ne\n', 'lines.txt', 'x-patch')
+ self.assertMessage(complex_multipart_message('x-patch'))
+
+ def test_send_simple(self):
+ self.send_email()
+ self.assertMessage(SIMPLE_MESSAGE_ASCII)
+
=== modified file 'doc/en/release-notes/bzr-2.7.txt'
--- a/doc/en/release-notes/bzr-2.7.txt 2014-04-02 16:15:32 +0000
+++ b/doc/en/release-notes/bzr-2.7.txt 2014-04-09 08:00:39 +0000
@@ -63,6 +63,9 @@
suite. This can include new facilities for writing tests, fixes to
spurious test failures and changes to the way things should be tested.
+* Handle (minor) incompatible change in python 2.7.6 leading to test
+ failures. Only tests are affected. (Vincent Ladeuil, #1303879)
+
* Remove wrong assumption about how TCP server and client interact when run
inside the same process. (Vincent Ladeuil, #1269886).
More information about the bazaar-commits
mailing list