Patchwork [10,of,10,STABLE] py3: fix generated non-ascii message in test-notify.t

login
register
mail settings
Submitter Denis Laxalde
Date Oct. 24, 2019, 3:30 p.m.
Message ID <818013898b850073a6c2.1571931041@steppe.local>
Download mbox | patch
Permalink /patch/42573/
State Accepted
Headers show

Comments

Denis Laxalde - Oct. 24, 2019, 3:30 p.m.
# HG changeset patch
# User Denis Laxalde <denis.laxalde@logilab.fr>
# Date 1571930937 -7200
#      Thu Oct 24 17:28:57 2019 +0200
# Branch stable
# Node ID 818013898b850073a6c221e7dcb965aa4daba1e6
# Parent  b3070247092e461d15f0921618b94a2b1646fdf1
py3: fix generated non-ascii message in test-notify.t

The resulting "Subject:" header contains an encoded word in Python 3 so
we have to add distinct outputs for Python 3 but underlying values are
the same:

    >>> from email.header import decode_header
    >>> decode_header('=?utf-8?b?w6AuLi4=?=')
    [(b'\xc3\xa0...', 'utf-8')]
Yuya Nishihara - Oct. 25, 2019, 12:24 p.m.
On Thu, 24 Oct 2019 17:30:41 +0200, Denis Laxalde wrote:
> # HG changeset patch
> # User Denis Laxalde <denis.laxalde@logilab.fr>
> # Date 1571930937 -7200
> #      Thu Oct 24 17:28:57 2019 +0200
> # Branch stable
> # Node ID 818013898b850073a6c221e7dcb965aa4daba1e6
> # Parent  b3070247092e461d15f0921618b94a2b1646fdf1
> py3: fix generated non-ascii message in test-notify.t
> 
> The resulting "Subject:" header contains an encoded word in Python 3 so
> we have to add distinct outputs for Python 3 but underlying values are
> the same:
> 
>     >>> from email.header import decode_header
>     >>> decode_header('=?utf-8?b?w6AuLi4=?=')
>     [(b'\xc3\xa0...', 'utf-8')]
> 
> diff --git a/tests/test-notify.t b/tests/test-notify.t
> --- a/tests/test-notify.t
> +++ b/tests/test-notify.t
> @@ -418,8 +418,13 @@ non-ascii content and truncation of mult
>    > maxsubject = 4
>    > EOF
>    $ echo a >> a/a
> +#if py3
> +  $ hg --cwd a --encoding utf-8 commit -A -d '0 0' \
> +  >   -m `"$PYTHON" -c 'print(b"\xc3\xa0\xc3\xa1\xc3\xa2\xc3\xa3\xc3\xa4".decode("utf-8"))'`
> +#else
>    $ hg --cwd a --encoding utf-8 commit -A -d '0 0' \
>    >   -m `"$PYTHON" -c 'print("\xc3\xa0\xc3\xa1\xc3\xa2\xc3\xa3\xc3\xa4")'`

Can't we just do getattr(sys.stdout, 'buffer', sys.stdout).write(b'...')?

Patch

diff --git a/tests/test-notify.t b/tests/test-notify.t
--- a/tests/test-notify.t
+++ b/tests/test-notify.t
@@ -418,8 +418,13 @@  non-ascii content and truncation of mult
   > maxsubject = 4
   > EOF
   $ echo a >> a/a
+#if py3
+  $ hg --cwd a --encoding utf-8 commit -A -d '0 0' \
+  >   -m `"$PYTHON" -c 'print(b"\xc3\xa0\xc3\xa1\xc3\xa2\xc3\xa3\xc3\xa4".decode("utf-8"))'`
+#else
   $ hg --cwd a --encoding utf-8 commit -A -d '0 0' \
   >   -m `"$PYTHON" -c 'print("\xc3\xa0\xc3\xa1\xc3\xa2\xc3\xa3\xc3\xa4")'`
+#endif
   $ hg --traceback --cwd b --encoding utf-8 pull ../a | \
   >   "$PYTHON" $TESTTMP/filter.py
   pulling from ../a
@@ -434,7 +439,8 @@  non-ascii content and truncation of mult
   Content-Transfer-Encoding: 8bit
   X-Test: foo
   Date: * (glob)
-  Subject: \xc3\xa0... (esc)
+  Subject: \xc3\xa0... (esc) (no-py3 !)
+  Subject: =?utf-8?b?w6AuLi4=?= (py3 !)
   From: test@test.com
   X-Hg-Notification: changeset 0f25f9c22b4c
   Message-Id: <*> (glob)