Re: [PATCH v4 13/16] add indexopts to notmuch python bindings.
[notmuch-archives.git] / 29 / 7d8cc1fe0328d0a54099d141ede33a37a0e056
1 Return-Path: <tomi.ollila@iki.fi>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 1877F431FBD\r
6         for <notmuch@notmuchmail.org>; Wed,  8 Aug 2012 11:47:43 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id RJlYXhFsvrvo for <notmuch@notmuchmail.org>;\r
16         Wed,  8 Aug 2012 11:47:41 -0700 (PDT)\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
18         by olra.theworths.org (Postfix) with ESMTP id 6B127431FAE\r
19         for <notmuch@notmuchmail.org>; Wed,  8 Aug 2012 11:47:41 -0700 (PDT)\r
20 Received: by guru.guru-group.fi (Postfix, from userid 501)\r
21         id E59CD1002A4; Wed,  8 Aug 2012 21:47:49 +0300 (EEST)\r
22 From: Tomi Ollila <tomi.ollila@iki.fi>\r
23 To: Austin Clements <amdragon@MIT.EDU>\r
24 Subject: Re: [PATCH v2] test: Add test for messages with missing headers\r
25 In-Reply-To: <20120808154608.GD11179@mit.edu>\r
26 References: <1344374501-28185-1-git-send-email-amdragon@mit.edu>\r
27         <1344389313-7886-1-git-send-email-amdragon@mit.edu>\r
28         <m2k3x9olfl.fsf@guru.guru-group.fi>\r
29         <20120808154608.GD11179@mit.edu>\r
30 User-Agent: Notmuch/0.13.2+128~g07453d8 (http://notmuchmail.org) Emacs/23.1.1\r
31         (x86_64-redhat-linux-gnu)\r
32 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
33         $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
34         !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
35 Date: Wed, 08 Aug 2012 21:47:49 +0300\r
36 Message-ID: <m2ehnhfcfe.fsf@guru.guru-group.fi>\r
37 MIME-Version: 1.0\r
38 Content-Type: text/plain; charset=us-ascii\r
39 Cc: notmuch@notmuchmail.org\r
40 X-BeenThere: notmuch@notmuchmail.org\r
41 X-Mailman-Version: 2.1.13\r
42 Precedence: list\r
43 List-Id: "Use and development of the notmuch mail system."\r
44         <notmuch.notmuchmail.org>\r
45 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
46         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
47 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
48 List-Post: <mailto:notmuch@notmuchmail.org>\r
49 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
50 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
51         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
52 X-List-Received-Date: Wed, 08 Aug 2012 18:47:43 -0000\r
53 \r
54 On Wed, Aug 08 2012, Austin Clements <amdragon@MIT.EDU> wrote:\r
55 \r
56 > Quoth Tomi Ollila on Aug 08 at 11:08 am:\r
57 >> On Wed, Aug 08 2012, Austin Clements <amdragon@MIT.EDU> wrote:\r
58 >> \r
59 >> > Currently the JSON tests for search and show are broken because\r
60 >> > notmuch attempts to dereference a NULL pointer.\r
61 >> > ---\r
62 >> > This version fixes the "Show: text" test so that it sanitize its\r
63 >> > output and doesn't hard-code my test paths.\r
64 >> \r
65 >> +1\r
66 >> \r
67 >> Tomi\r
68 >> \r
69 >> w/ python json(.tool) the original order cannot be preserved as the parser\r
70 >> stores content into dictionary -- without sorting those came in some\r
71 >> internal python order... the following code could be used to use less\r
72 >\r
73 > To be fair, it can output them in original order, but doing so\r
74 > requires Python 2.7:\r
75 >\r
76 > python -c 'import sys,json,collections; json.dump(json.load(sys.stdin,\r
77 > object_pairs_hook=collections.OrderedDict), sys.stdout, indent=4)'\r
78 \r
79 ack.\r
80 \r
81 >\r
82 >> indentation, though:\r
83 >> \r
84 >> python -c 'import sys,json; j = json.load(sys.stdin);\r
85 >> json.dump(j, sys.stdout, sort_keys=True, indent=2)' < input_file\r
86 >> \r
87 >> The other "problem" with json.tool is that it converts non-ascii chars\r
88 >> to \uNNNN values :/.\r
89 >\r
90 > This one doesn't require 2.7.\r
91 >\r
92 > python -c 'import sys,json,codecs; json.dump(json.load(sys.stdin),\r
93 > codecs.getwriter("utf8")(sys.stdout), indent=4, ensure_ascii=False)'\r
94 \r
95 nice.\r
96 \r
97 >\r
98 > Though I think that, for test canonicalization, \uNNNN is probably\r
99 > less error/locale prone.\r
100 \r
101 true.\r
102 \r
103 >\r
104 >> What we could do is to dig a simple c json formatter -- someday in the\r
105 >> future, maybe -- but for *now* this is the best we can have :D\r
106 >\r
107 > Not another JSON parser/printer!\r
108 \r
109 Why not, one from scratch, without looking any source there is already >;)\r
110 \r
111 Well, you're right; the json.tool version python 2.6 provides is good --\r
112 -- ordering and those \uNNNN:s doesn't really matter.\r
113 Probably thinking (or planning!) anything else at this time is waste of time.\r
114 \r
115 At least these 2 questions remain:\r
116 \r
117 Is the test requirement of python 2.6 suitable/acceptable ?\r
118 \r
119 How do we pretty-print S-expression syntax ;) ?\r
120 \r
121 \r
122 Tomi\r
123 \r
124 \r
125 >\r
126 >> >\r
127 >> >  test/missing-headers |  162 ++++++++++++++++++++++++++++++++++++++++++++++++++\r
128 >> >  test/notmuch-test    |    1 +\r
129 >> >  2 files changed, 163 insertions(+)\r
130 >> >  create mode 100755 test/missing-headers\r
131 >> >\r
132 >> > diff --git a/test/missing-headers b/test/missing-headers\r
133 >> > new file mode 100755\r
134 >> > index 0000000..e79f922\r
135 >> > --- /dev/null\r
136 >> > +++ b/test/missing-headers\r
137 >> > @@ -0,0 +1,162 @@\r
138 >> > +#!/usr/bin/env bash\r
139 >> > +test_description='messages with missing headers'\r
140 >> > +. ./test-lib.sh\r
141 >> > +\r
142 >> > +# Notmuch requires at least one of from, subject, or to or it will\r
143 >> > +# ignore the file.  Generate two messages so that together they cover\r
144 >> > +# all possible missing headers.  We also give one of the messages a\r
145 >> > +# date to ensure stable result ordering.\r
146 >> > +\r
147 >> > +cat <<EOF > "${MAIL_DIR}/msg-2"\r
148 >> > +To: Notmuch Test Suite <test_suite@notmuchmail.org>\r
149 >> > +Date: Fri, 05 Jan 2001 15:43:57 +0000\r
150 >> > +\r
151 >> > +Body\r
152 >> > +EOF\r
153 >> > +\r
154 >> > +cat <<EOF > "${MAIL_DIR}/msg-1"\r
155 >> > +From: Notmuch Test Suite <test_suite@notmuchmail.org>\r
156 >> > +\r
157 >> > +Body\r
158 >> > +EOF\r
159 >> > +\r
160 >> > +NOTMUCH_NEW\r
161 >> > +\r
162 >> > +test_begin_subtest "Search: text"\r
163 >> > +output=$(notmuch search '*' | notmuch_search_sanitize)\r
164 >> > +test_expect_equal "$output" "\\r
165 >> > +thread:XXX   2001-01-05 [1/1] (null);  (inbox unread)\r
166 >> > +thread:XXX   1970-01-01 [1/1] Notmuch Test Suite;  (inbox unread)"\r
167 >> > +\r
168 >> > +test_begin_subtest "Search: json"\r
169 >> > +test_subtest_known_broken\r
170 >> > +output=$(notmuch search --format=json '*' | notmuch_search_sanitize)\r
171 >> > +test_expect_equal_json "$output" '\r
172 >> > +[\r
173 >> > +    {\r
174 >> > +        "authors": "",\r
175 >> > +        "date_relative": "2001-01-05",\r
176 >> > +        "matched": 1,\r
177 >> > +        "subject": "",\r
178 >> > +        "tags": [\r
179 >> > +            "inbox",\r
180 >> > +            "unread"\r
181 >> > +        ],\r
182 >> > +        "thread": "XXX",\r
183 >> > +        "timestamp": 978709437,\r
184 >> > +        "total": 1\r
185 >> > +    },\r
186 >> > +    {\r
187 >> > +        "authors": "Notmuch Test Suite",\r
188 >> > +        "date_relative": "1970-01-01",\r
189 >> > +        "matched": 1,\r
190 >> > +        "subject": "",\r
191 >> > +        "tags": [\r
192 >> > +            "inbox",\r
193 >> > +            "unread"\r
194 >> > +        ],\r
195 >> > +        "thread": "XXX",\r
196 >> > +        "timestamp": 0,\r
197 >> > +        "total": 1\r
198 >> > +    }\r
199 >> > +]'\r
200 >> > +\r
201 >> > +test_begin_subtest "Show: text"\r
202 >> > +output=$(notmuch show '*' | notmuch_show_sanitize)\r
203 >> > +test_expect_equal "$output" "\\r
204 >> > +\f\r
205 message{ id:notmuch-sha1-7a6e4eac383ef958fcd3ebf2143db71b8ff01161 depth:0 match:1 excluded:0 filename:/XXX/mail/msg-2\r
206 >> > +\f\r
207 header{\r
208 >> > + (2001-01-05) (inbox unread)\r
209 >> > +Subject: (null)\r
210 >> > +From: (null)\r
211 >> > +To: Notmuch Test Suite <test_suite@notmuchmail.org>\r
212 >> > +Date: Fri, 05 Jan 2001 15:43:57 +0000\r
213 >> > +\f\r
214 header}\r
215 >> > +\f\r
216 body{\r
217 >> > +\f\r
218 part{ ID: 1, Content-type: text/plain\r
219 >> > +Body\r
220 >> > +\f\r
221 part}\r
222 >> > +\f\r
223 body}\r
224 >> > +\f\r
225 message}\r
226 >> > +\f\r
227 message{ id:notmuch-sha1-ca55943aff7a72baf2ab21fa74fab3d632401334 depth:0 match:1 excluded:0 filename:/XXX/mail/msg-1\r
228 >> > +\f\r
229 header{\r
230 >> > +Notmuch Test Suite <test_suite@notmuchmail.org> (1970-01-01) (inbox unread)\r
231 >> > +Subject: (null)\r
232 >> > +From: Notmuch Test Suite <test_suite@notmuchmail.org>\r
233 >> > +Date: Thu, 01 Jan 1970 00:00:00 +0000\r
234 >> > +\f\r
235 header}\r
236 >> > +\f\r
237 body{\r
238 >> > +\f\r
239 part{ ID: 1, Content-type: text/plain\r
240 >> > +Body\r
241 >> > +\f\r
242 part}\r
243 >> > +\f\r
244 body}\r
245 >> > +\f\r
246 message}"\r
247 >> > +\r
248 >> > +test_begin_subtest "Show: json"\r
249 >> > +test_subtest_known_broken\r
250 >> > +output=$(notmuch show --format=json '*' | notmuch_json_show_sanitize)\r
251 >> > +test_expect_equal_json "$output" '\r
252 >> > +[\r
253 >> > +    [\r
254 >> > +        [\r
255 >> > +            {\r
256 >> > +                "body": [\r
257 >> > +                    {\r
258 >> > +                        "content": "Body\n",\r
259 >> > +                        "content-type": "text/plain",\r
260 >> > +                        "id": 1\r
261 >> > +                    }\r
262 >> > +                ],\r
263 >> > +                "date_relative": "2001-01-05",\r
264 >> > +                "excluded": false,\r
265 >> > +                "filename": "YYYYY",\r
266 >> > +                "headers": {\r
267 >> > +                    "Date": "Fri, 05 Jan 2001 15:43:57 +0000",\r
268 >> > +                    "From": "",\r
269 >> > +                    "Subject": "",\r
270 >> > +                    "To": "Notmuch Test Suite <test_suite@notmuchmail.org>"\r
271 >> > +                },\r
272 >> > +                "id": "XXXXX",\r
273 >> > +                "match": true,\r
274 >> > +                "tags": [\r
275 >> > +                    "inbox",\r
276 >> > +                    "unread"\r
277 >> > +                ],\r
278 >> > +                "timestamp": 978709437\r
279 >> > +            },\r
280 >> > +            []\r
281 >> > +        ]\r
282 >> > +    ],\r
283 >> > +    [\r
284 >> > +        [\r
285 >> > +            {\r
286 >> > +                "body": [\r
287 >> > +                    {\r
288 >> > +                        "content": "Body\n",\r
289 >> > +                        "content-type": "text/plain",\r
290 >> > +                        "id": 1\r
291 >> > +                    }\r
292 >> > +                ],\r
293 >> > +                "date_relative": "1970-01-01",\r
294 >> > +                "excluded": false,\r
295 >> > +                "filename": "YYYYY",\r
296 >> > +                "headers": {\r
297 >> > +                    "Date": "Thu, 01 Jan 1970 00:00:00 +0000",\r
298 >> > +                    "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",\r
299 >> > +                    "Subject": ""\r
300 >> > +                },\r
301 >> > +                "id": "XXXXX",\r
302 >> > +                "match": true,\r
303 >> > +                "tags": [\r
304 >> > +                    "inbox",\r
305 >> > +                    "unread"\r
306 >> > +                ],\r
307 >> > +                "timestamp": 0\r
308 >> > +            },\r
309 >> > +            []\r
310 >> > +        ]\r
311 >> > +    ]\r
312 >> > +]'\r
313 >> > +\r
314 >> > +\r
315 >> > +test_done\r
316 >> > diff --git a/test/notmuch-test b/test/notmuch-test\r
317 >> > index ea39dfc..cc732c3 100755\r
318 >> > --- a/test/notmuch-test\r
319 >> > +++ b/test/notmuch-test\r
320 >> > @@ -59,6 +59,7 @@ TESTS="\r
321 >> >    emacs-address-cleaning\r
322 >> >    emacs-hello\r
323 >> >    emacs-show\r
324 >> > +  missing-headers\r
325 >> >  "\r
326 >> >  TESTS=${NOTMUCH_TESTS:=$TESTS}\r
327 >> >  \r
328 >> >\r
329 >> > _______________________________________________\r
330 >> > notmuch mailing list\r
331 >> > notmuch@notmuchmail.org\r
332 >> > http://notmuchmail.org/mailman/listinfo/notmuch\r
333 > _______________________________________________\r
334 > notmuch mailing list\r
335 > notmuch@notmuchmail.org\r
336 > http://notmuchmail.org/mailman/listinfo/notmuch\r