[PATCH 1/2] test: add a function to run Python tests
authorThomas Jost <schnouki@schnouki.net>
Wed, 7 Dec 2011 09:46:17 +0000 (10:46 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:40:38 +0000 (09:40 -0800)
74/6b86750281b5f7685640d4b1f4aa87c5a0e5ef [new file with mode: 0644]

diff --git a/74/6b86750281b5f7685640d4b1f4aa87c5a0e5ef b/74/6b86750281b5f7685640d4b1f4aa87c5a0e5ef
new file mode 100644 (file)
index 0000000..8dbe5c8
--- /dev/null
@@ -0,0 +1,114 @@
+Return-Path: <schnouki@schnouki.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 0FBB4429E44\r
+       for <notmuch@notmuchmail.org>; Wed,  7 Dec 2011 01:46:33 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.1\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.1 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1]\r
+       autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id tSjsAp1sj1gc for <notmuch@notmuchmail.org>;\r
+       Wed,  7 Dec 2011 01:46:32 -0800 (PST)\r
+Received: from ks3536.kimsufi.com (schnouki.net [87.98.217.222])\r
+       by olra.theworths.org (Postfix) with ESMTP id 35D26431FD0\r
+       for <notmuch@notmuchmail.org>; Wed,  7 Dec 2011 01:46:32 -0800 (PST)\r
+Received: from thor.loria.fr (thor.loria.fr [152.81.12.250])\r
+       by ks3536.kimsufi.com (Postfix) with ESMTPSA id E98856A0026;\r
+       Wed,  7 Dec 2011 10:46:29 +0100 (CET)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=schnouki.net;\r
+       s=key-schnouki; t=1323251190;\r
+       bh=lB3SyTPEfYd4szFwQvtNj0zwCEtQvtKfXjDIw2vzff8=;\r
+       h=From:To:Subject:Date:Message-Id;\r
+       b=kcPf/W/ue7bu1ZdooydfCEe7oSRKzRDFrlOEGMtaYqxTnzg0FW9T9Lwh4TncXJoHx\r
+       zLjJgJDV9HXZn3PYxdckpGRSgjyXKOqVuAifZ6PSEYrExQVkGq6+gAMVc3UujumOok\r
+       X5DCked6UhR6Uhyg/0AdRXOHQudpPEar8HSjvQWg=\r
+From: Thomas Jost <schnouki@schnouki.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/2] test: add a function to run Python tests\r
+Date: Wed,  7 Dec 2011 10:46:17 +0100\r
+Message-Id: <1323251178-20409-1-git-send-email-schnouki@schnouki.net>\r
+X-Mailer: git-send-email 1.7.8\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Wed, 07 Dec 2011 09:46:33 -0000\r
+\r
+The new test_python() function makes writing Python tests a little easier:\r
+- it sets the environment variables as needed\r
+- it redirects stdout to the OUTPUT file (like test_emacs()).\r
+\r
+This commit also declares python as an external prereq.\r
+\r
+The stdout redirection is required to avoid trouble when running commands like\r
+"python 'script' | sort > OUTPUT": in such a case, any error due to a missing\r
+external prereq would be "swallowed" by sort, resulting to a failed test instead\r
+of a skipped one.\r
+---\r
+ test/python      |    6 ++----\r
+ test/test-lib.sh |    9 +++++++++\r
+ 2 files changed, 11 insertions(+), 4 deletions(-)\r
+\r
+diff --git a/test/python b/test/python\r
+index f737749..c3aa726 100755\r
+--- a/test/python\r
++++ b/test/python\r
+@@ -5,9 +5,7 @@ test_description="python bindings"\r
+ add_email_corpus\r
\r
+ test_begin_subtest "compare thread ids"\r
+-LD_LIBRARY_PATH=$TEST_DIRECTORY/../lib \\r
+-PYTHONPATH=$TEST_DIRECTORY/../bindings/python \\r
+-python <<EOF | sort > OUTPUT\r
++test_python <<EOF\r
+ import notmuch\r
+ db = notmuch.Database(mode=notmuch.Database.MODE.READ_WRITE)\r
+ q_new = notmuch.Query(db, 'tag:inbox')\r
+@@ -15,5 +13,5 @@ for t in q_new.search_threads():\r
+     print t.get_thread_id()\r
+ EOF\r
+ notmuch search --output=threads tag:inbox | sed s/^thread:// | sort > EXPECTED\r
+-test_expect_equal_file OUTPUT EXPECTED\r
++test_expect_equal_file <(sort OUTPUT) EXPECTED\r
+ test_done\r
+diff --git a/test/test-lib.sh b/test/test-lib.sh\r
+index a975957..519bd84 100644\r
+--- a/test/test-lib.sh\r
++++ b/test/test-lib.sh\r
+@@ -919,6 +919,14 @@ test_emacs () {\r
+       emacsclient --socket-name="$EMACS_SERVER" --eval "(progn $@)"\r
+ }\r
\r
++test_python() {\r
++      export LD_LIBRARY_PATH=$TEST_DIRECTORY/../lib\r
++      export PYTHONPATH=$TEST_DIRECTORY/../bindings/python\r
++\r
++      (echo "import sys; _orig_stdout=sys.stdout; sys.stdout=open('OUTPUT', 'w')"; cat) \\r
++              | python -\r
++}\r
++\r
+ test_reset_state_ () {\r
+       test -z "$test_init_done_" && test_init_\r
\r
+@@ -1148,3 +1156,4 @@ test_declare_external_prereq emacs\r
+ test_declare_external_prereq emacsclient\r
+ test_declare_external_prereq gdb\r
+ test_declare_external_prereq gpg\r
++test_declare_external_prereq python\r
+-- \r
+1.7.8\r
+\r