From 77a896f6f24921c0d00cb40333a3d7be7aac5b66 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Wed, 5 Dec 2012 10:24:14 +1900 Subject: [PATCH] [PATCH] test: Fix UTF-8 JSON tests in Python 3 --- c7/b2b7c8403e7ba56feda75fb9eeb7c742adba0b | 107 ++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 c7/b2b7c8403e7ba56feda75fb9eeb7c742adba0b diff --git a/c7/b2b7c8403e7ba56feda75fb9eeb7c742adba0b b/c7/b2b7c8403e7ba56feda75fb9eeb7c742adba0b new file mode 100644 index 000000000..3750da4f1 --- /dev/null +++ b/c7/b2b7c8403e7ba56feda75fb9eeb7c742adba0b @@ -0,0 +1,107 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 6C48D431FB6 + for ; Tue, 4 Dec 2012 07:24:25 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id tUpnjUcjgZ0e for ; + Tue, 4 Dec 2012 07:24:21 -0800 (PST) +Received: from dmz-mailsec-scanner-3.mit.edu (DMZ-MAILSEC-SCANNER-3.MIT.EDU + [18.9.25.14]) + by olra.theworths.org (Postfix) with ESMTP id 76DE1431FAE + for ; Tue, 4 Dec 2012 07:24:21 -0800 (PST) +X-AuditID: 1209190e-b7f516d0000008e4-f5-50be15a43521 +Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) + by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP + id 23.95.02276.4A51EB05; Tue, 4 Dec 2012 10:24:20 -0500 (EST) +Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) + by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id qB4FOJN5009216; + Tue, 4 Dec 2012 10:24:19 -0500 +Received: from drake.dyndns.org + (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com + [209.6.116.242]) (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id qB4FOG6A012417 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Tue, 4 Dec 2012 10:24:18 -0500 (EST) +Received: from amthrax by drake.dyndns.org with local (Exim 4.77) + (envelope-from ) + id 1TfuM4-0002Ux-Iv; Tue, 04 Dec 2012 10:24:16 -0500 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH] test: Fix UTF-8 JSON tests in Python 3 +Date: Tue, 4 Dec 2012 10:24:14 -0500 +Message-Id: <1354634654-9564-1-git-send-email-amdragon@mit.edu> +X-Mailer: git-send-email 1.7.10.4 +In-Reply-To: <87d2yp27zu.fsf@nexoid.at> +References: <87d2yp27zu.fsf@nexoid.at> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFtrDIsWRmVeSWpSXmKPExsUixCmqrLtEdF+AwZ5fNhZ7G9oZLa7fnMns + wOSxeNN+No9nq24xBzBFcdmkpOZklqUW6dslcGVMf/iUseAvd8WV3weZGhiPcnYxcnJICJhI + 7Duzkg3CFpO4cG89kM3FISSwj1Fi+rezrBDOekaJ/mV/mCCch0wSy1pvgbUICcxllHjzWA/E + ZhPQkNi2fzkjiC0iIC2x8+5sVhCbWcBMYu7PiWD1wgLmEnM7J4HVsAioSrxZf5ili5GDg1fA + XuLCLluIKxQlup9NACvnFFCXWPhjHiPEKjWJaSces05g5F/AyLCKUTYlt0o3NzEzpzg1Wbc4 + OTEvL7VI11gvN7NELzWldBMjOJAk+XYwfj2odIhRgINRiYd3wq09AUKsiWXFlbmHGCU5mJRE + eY2F9wUI8SXlp1RmJBZnxBeV5qQWH2KU4GBWEuFV+LA3QIg3JbGyKrUoHyYlzcGiJM57JeWm + v5BAemJJanZqakFqEUxWhoNDSYJ3kQjQUMGi1PTUirTMnBKENBMHJ8hwHqDhWSA1vMUFibnF + mekQ+VOMilLivKwgCQGQREZpHlwvLNJfMYoDvSLMew3kbh5gkoDrfgU0mAlo8Auh3SCDSxIR + UlINjB3bLylOPxMoMt94/czWZ9LcLNpdJ67/tAwwkE26tvW+3KfEvoLYTTu+iR2YbvP+A+O2 + jheBB4U4/81QdO5et+Zd4A/5P3pBVzJ+lcRk2+hxTXQ0ZLwlFt4sND/hg63Mx23fdzmw3/lq + EW/4dlJp1d3TLpa7XU6sPfgg8VTpl8AVqszqwe8bYpRYijMSDbWYi4oTAXKN1AnPAgAA +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Tue, 04 Dec 2012 15:24:25 -0000 + +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. +--- + 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 + -- 2.26.2