Patchwork Manually encode utf-8 patch in testcase

login
register
mail settings
Submitter Dirk Wallenstein
Date Feb. 10, 2011, 6:45 p.m.
Message ID <20110210184505.GA17251@zap>
Download mbox | patch
Permalink /patch/82651/
State Rejected
Headers show

Comments

Dirk Wallenstein - Feb. 10, 2011, 6:45 p.m.
Otherwise there will be a UnicodeDecodeError.

Signed-off-by: Dirk Wallenstein <halsmit@t-online.de>
---

On Thu, Feb 10, 2011 at 01:55:30PM -0200, Guilherme Salgado wrote:
[...]
> It's actually the other way around -- it works if we remove
> the .decode('utf-8') from parse_patch().  With the decode() there the
> tests that try parsing email addresses with non-ascii stuff (e.g.
> patchwork.tests.patchparser.UTF8InlinePatchTest) fail but if we remove
> the .decode('utf-8') they pass.

That can be fixed by manually encoding the content.  The same might be
possible by just omitting the content_encoding argument but the
documentations appears to be not really clear there
(email.mime.text.MIMEText).

 apps/patchwork/tests/patchparser.py |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
Jeremy Kerr - Feb. 10, 2011, 11:57 p.m.
Dirk,

> Otherwise there will be a UnicodeDecodeError.

Where are you getting this UnicodeDecodeError? With 7fd7d0bbe reverted, I see 
all the testcases pass.

Cheers,


Jeremy
Dirk Wallenstein - Feb. 11, 2011, 9:41 a.m.
On Fri, Feb 11, 2011 at 07:57:26AM +0800, Jeremy Kerr wrote:
> Dirk,
> 
> > Otherwise there will be a UnicodeDecodeError.
> 
> Where are you getting this UnicodeDecodeError? With 7fd7d0bbe reverted, I see 
> all the testcases pass.

Hm, maybe this is a Python bug (Python-2.6.5).  Seemed a bit strange
anyway as the doc explicitly allows to pass in unicode.  I get a couple
of these (all errors attached):

======================================================================
ERROR: testCommentContent (patchwork.tests.patchparser.UTF8InlinePatchTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/srv/patchwork/apps/patchwork/tests/patchparser.py", line 85, in setUp
    (self.patch, self.comment) = find_content(self.project, email)
  File "/srv/patchwork/apps/patchwork/bin/parsemail.py", line 166, in find_content
    payload = unicode(payload, charset)
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 146-148: invalid data

======================================================================
Dirk Wallenstein - Feb. 12, 2011, 10:50 a.m.
On Fri, Feb 11, 2011 at 10:41:54AM +0100, Dirk Wallenstein wrote:
> On Fri, Feb 11, 2011 at 07:57:26AM +0800, Jeremy Kerr wrote:
> > Dirk,
> > 
> > > Otherwise there will be a UnicodeDecodeError.
> > 
> > Where are you getting this UnicodeDecodeError? With 7fd7d0bbe reverted, I see 
> > all the testcases pass.
> 
> Hm, maybe this is a Python bug (Python-2.6.5).  Seemed a bit strange
> anyway as the doc explicitly allows to pass in unicode.  I get a couple
> of these (all errors attached):
> 
> ======================================================================
> ERROR: testCommentContent (patchwork.tests.patchparser.UTF8InlinePatchTest)
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>   File "/srv/patchwork/apps/patchwork/tests/patchparser.py", line 85, in setUp
>     (self.patch, self.comment) = find_content(self.project, email)
>   File "/srv/patchwork/apps/patchwork/bin/parsemail.py", line 166, in find_content
>     payload = unicode(payload, charset)
> UnicodeDecodeError: 'utf8' codec can't decode bytes in position 146-148: invalid data
> 
> ======================================================================

Yap, gone with Python-2.6.6

Patch

diff --git a/apps/patchwork/tests/patchparser.py b/apps/patchwork/tests/patchparser.py
index ff0025a..357ffc1 100644
--- a/apps/patchwork/tests/patchparser.py
+++ b/apps/patchwork/tests/patchparser.py
@@ -80,7 +80,10 @@  class UTF8InlinePatchTest(InlinePatchTest):
 
     def setUp(self):
         self.orig_patch = read_patch(self.patch_filename, self.patch_encoding)
-        email = create_email(self.test_comment + '\n' + self.orig_patch,
+        patch_content = self.test_comment + '\n' + self.orig_patch
+        if isinstance(patch_content, unicode):
+            patch_content = patch_content.encode(self.patch_encoding)
+        email = create_email(patch_content,
                              content_encoding = self.patch_encoding)
         (self.patch, self.comment) = find_content(self.project, email)