[PATCH 3/9] test/count: convert library test from python to C

Subject: [PATCH 3/9] test/count: convert library test from python to C

Date: Sat, 15 Feb 2025 16:05:49 -0400

To: notmuch@notmuchmail.org

Cc:

From: David Bremner


The new python bindings do not support modifying query objects, so
convert to C. There is a bit more boilerplate to handle errors but
otherwise it is essentially a line by line translation.
---
 test/T060-count.sh | 57 +++++++++++++++++++++++++++++++++-------------
 1 file changed, 41 insertions(+), 16 deletions(-)

diff --git a/test/T060-count.sh b/test/T060-count.sh
index 6e855b59..d63333b6 100755
--- a/test/T060-count.sh
+++ b/test/T060-count.sh
@@ -132,28 +132,53 @@ restore_database
 
 test_begin_subtest "count library function is non-destructive"
 cat<<EOF > EXPECTED
+== stdout ==
 1: 52 messages
 2: 52 messages
 Exclude 'spam'
 3: 52 messages
 4: 52 messages
+== stderr ==
 EOF
-test_python <<EOF
-import sys
-import notmuch
-
-query_string = 'tag:inbox or tag:spam'
-tag_string = 'spam'
-
-database = notmuch.Database(mode=notmuch.Database.MODE.READ_ONLY)
-query = notmuch.Query(database, query_string)
-
-print("1: {} messages".format(query.count_messages()))
-print("2: {} messages".format(query.count_messages()))
-print("Exclude '{}'".format(tag_string))
-query.exclude_tag(tag_string)
-print("3: {} messages".format(query.count_messages()))
-print("4: {} messages".format(query.count_messages()))
+
+test_C ${MAIL_DIR} <<'EOF' > OUTPUT
+#include <notmuch-test.h>
+
+int main (int argc, char** argv)
+{
+   notmuch_database_t *db;
+   notmuch_status_t stat = NOTMUCH_STATUS_SUCCESS;
+   char *msg = NULL;
+   notmuch_query_t *query;
+   const char *str = "tag:inbox or tag:spam";
+   const char *tag_str = "spam";
+   unsigned int count;
+
+   stat=notmuch_database_open_with_config (argv[1],
+				       NOTMUCH_DATABASE_MODE_READ_ONLY,
+				       NULL, NULL, &db, &msg);
+   if (stat) {
+       fprintf (stderr, "open: %s\n", msg);
+       exit(1);
+   }
+
+   EXPECT0(notmuch_query_create_with_syntax (db, str,
+					     NOTMUCH_QUERY_SYNTAX_XAPIAN, &query));
+   EXPECT0(notmuch_query_count_messages (query, &count));
+   printf("1: %d messages\n", count);
+   EXPECT0(notmuch_query_count_messages (query, &count));
+   printf("2: %d messages\n", count);
+   printf("Exclude '%s'\n",tag_str);
+   stat = notmuch_query_add_tag_exclude (query, tag_str);
+   if (stat && stat != NOTMUCH_STATUS_IGNORED) {
+     fprintf(stderr, "status=%d\n", stat);
+     exit(1);
+   }
+   EXPECT0(notmuch_query_count_messages (query, &count));
+   printf("3: %d messages\n", count);
+   EXPECT0(notmuch_query_count_messages (query, &count));
+   printf("4: %d messages\n", count);
+}
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
-- 
2.47.2

_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org

Thread: