unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Tomi Ollila <tomi.ollila@iki.fi>
To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org
Subject: Re: [PATCH] test: Fix UTF-8 JSON tests in Python 3
Date: Thu, 06 Dec 2012 23:15:13 +0200	[thread overview]
Message-ID: <m2vcceq3vi.fsf@guru.guru-group.fi> (raw)
In-Reply-To: <1354634654-9564-1-git-send-email-amdragon@mit.edu>

On Tue, Dec 04 2012, Austin Clements <amdragon@MIT.EDU> wrote:

> test_expect_equal_json uses json.tool from the system Python.  While
> Python 2 wasn't picky about the encoding of stdin, Python 3 decodes
> stdin strictly according to the environment.  Since we set LC_ALL=C
> for the tests, Python 3's json.tool was assuming stdin would be in
> ASCII and aborting when it couldn't decode the UTF-8 characters from
> some of the JSON tests.  This patch sets the PYTHONIOENCODING
> environment variable to utf-8 when invoking json.tool to override
> Python's default encoding choice.
> ---

LGTM.

Tomi

>  test/test-lib.sh |    9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/test/test-lib.sh b/test/test-lib.sh
> index f169785..9487526 100644
> --- a/test/test-lib.sh
> +++ b/test/test-lib.sh
> @@ -534,8 +534,13 @@ test_expect_equal_file ()
>  # canonicalized before diff'ing.  If an argument cannot be parsed, it
>  # is used unchanged so that there's something to diff against.
>  test_expect_equal_json () {
> -    output=$(echo "$1" | python -mjson.tool || echo "$1")
> -    expected=$(echo "$2" | python -mjson.tool || echo "$2")
> +    # The test suite forces LC_ALL=C, but this causes Python 3 to
> +    # decode stdin as ASCII.  We need to read JSON in UTF-8, so
> +    # override Python's stdio encoding defaults.
> +    output=$(echo "$1" | PYTHONIOENCODING=utf-8 python -mjson.tool \
> +        || echo "$1")
> +    expected=$(echo "$2" | PYTHONIOENCODING=utf-8 python -mjson.tool \
> +        || echo "$2")
>      shift 2
>      test_expect_equal "$output" "$expected" "$@"
>  }
> -- 
> 1.7.10.4
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch

  reply	other threads:[~2012-12-06 21:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-04 13:46 [PATCH 1/1] Fixing failing JSON tests Peter Feigl
2012-12-04 14:35 ` Austin Clements
2012-12-04 14:43   ` Peter Feigl
2012-12-04 15:24     ` [PATCH] test: Fix UTF-8 JSON tests in Python 3 Austin Clements
2012-12-06 21:15       ` Tomi Ollila [this message]
2012-12-07 13:14       ` David Bremner
2012-12-08 13:37       ` David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2vcceq3vi.fsf@guru.guru-group.fi \
    --to=tomi.ollila@iki.fi \
    --cc=amdragon@MIT.EDU \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).