Mercurial > hg
comparison tests/test-import.t @ 37467:9bf65d1b43a6
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
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 08 Apr 2018 14:59:12 +0900 |
parents | abd9f5ec1d82 |
children | 49b82cdb5983 |
comparison
equal
deleted
inserted
replaced
37466:abd9f5ec1d82 | 37467:9bf65d1b43a6 |
---|---|
286 | 286 |
287 $ cat > mkmsg.py <<EOF | 287 $ cat > mkmsg.py <<EOF |
288 > import email.message, sys | 288 > import email.message, sys |
289 > msg = email.message.Message() | 289 > msg = email.message.Message() |
290 > patch = open(sys.argv[1], 'rb').read() | 290 > patch = open(sys.argv[1], 'rb').read() |
291 > msg.set_payload('email commit message\n' + patch) | 291 > msg.set_payload(b'email commit message\n' + patch) |
292 > msg['Subject'] = 'email patch' | 292 > msg['Subject'] = 'email patch' |
293 > msg['From'] = 'email patcher' | 293 > msg['From'] = 'email patcher' |
294 > open(sys.argv[2], 'wb').write(msg.as_string()) | 294 > open(sys.argv[2], 'wb').write(bytes(msg)) |
295 > EOF | 295 > EOF |
296 | 296 |
297 | 297 |
298 plain diff in email, subject, message body | 298 plain diff in email, subject, message body |
299 | 299 |
384 | 384 |
385 $ cat > mkmsg2.py <<EOF | 385 $ cat > mkmsg2.py <<EOF |
386 > import email.message, sys | 386 > import email.message, sys |
387 > msg = email.message.Message() | 387 > msg = email.message.Message() |
388 > patch = open(sys.argv[1], 'rb').read() | 388 > patch = open(sys.argv[1], 'rb').read() |
389 > msg.set_payload('email patch\n\nnext line\n---\n' + patch) | 389 > msg.set_payload(b'email patch\n\nnext line\n---\n' + patch) |
390 > msg['Subject'] = '[PATCH] email patch' | 390 > msg['Subject'] = '[PATCH] email patch' |
391 > msg['From'] = 'email patcher' | 391 > msg['From'] = 'email patcher' |
392 > open(sys.argv[2], 'wb').write(msg.as_string()) | 392 > open(sys.argv[2], 'wb').write(bytes(msg)) |
393 > EOF | 393 > EOF |
394 | 394 |
395 | 395 |
396 plain diff in email, [PATCH] subject, message body with subject | 396 plain diff in email, [PATCH] subject, message body with subject |
397 | 397 |