# HG changeset patch
# User Yuya Nishihara <y...@tcha.org>
# Date 1523167152 -32400
#      Sun Apr 08 14:59:12 2018 +0900
# Node ID 9e3b46147b952770b7b10d626a745df8f3c1eeb1
# Parent  017138c795b7bea75181b759807dcd077e0a29f6
py3: fix string issues of email message in test-import.t

- payload can be bytes
- headers must be unicode on Python 3
- need to call msg.as_bytes() on Python 3, but msg.as_string() on Python 2,
  where bytes(msg) magic works

diff --git a/tests/test-import.t b/tests/test-import.t
--- a/tests/test-import.t
+++ b/tests/test-import.t
@@ -288,10 +288,10 @@ override commit message
   > import email.message, sys
   > msg = email.message.Message()
   > patch = open(sys.argv[1], 'rb').read()
-  > msg.set_payload('email commit message\n' + patch)
+  > msg.set_payload(b'email commit message\n' + patch)
   > msg['Subject'] = 'email patch'
   > msg['From'] = 'email patcher'
-  > open(sys.argv[2], 'wb').write(msg.as_string())
+  > open(sys.argv[2], 'wb').write(bytes(msg))
   > EOF
 
 
@@ -386,10 +386,10 @@ The '---' tests the gitsendmail handling
   > import email.message, sys
   > msg = email.message.Message()
   > patch = open(sys.argv[1], 'rb').read()
-  > msg.set_payload('email patch\n\nnext line\n---\n' + patch)
+  > msg.set_payload(b'email patch\n\nnext line\n---\n' + patch)
   > msg['Subject'] = '[PATCH] email patch'
   > msg['From'] = 'email patcher'
-  > open(sys.argv[2], 'wb').write(msg.as_string())
+  > open(sys.argv[2], 'wb').write(bytes(msg))
   > EOF
 
 
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to