Mercurial > hg
annotate tests/test-hgweb.t @ 14007:d764463b433e
atomictempfile: avoid infinite recursion in __del__().
The problem is that a programmer using atomictempfile directly can
make an innocent everyday mistake -- not enough args to the
constructor -- which escalates badly. You would expect a simple
TypeError crash in that case, but you actually get an infinite
recursion that is surprisingly difficult to kill: it happens between
__del__() and __getattr__(), and Python does not handle infinite
recursion from __del__() well.
The fix is to not implement __getattr__(), but instead assign instance
attributes for the methods we wish to delegate to the builtin file
type: write() and fileno(). I've audited mercurial.* and hgext.* and
found no users of atomictempfile using methods other than write() and
rename(). I audited third-party extensions and found one (snap)
passing an atomictempfile to util.fstat(), so I also threw in
fileno().
The last time I submitted a similar patch, Matt proposed that we make
atomictempfile a subclass of file instead of wrapping it. Rejected on
grounds of unnecessary complexity: for one thing, it would make the
Windows implementation of posixfile quite a bit more complex. It would
have to become a subclass of file rather than a simple function -- but
since it's written in C, this is non-obvious and non-trivial.
Furthermore, there's nothing wrong with wrapping objects and
delegating methods: it's a well-established pattern that works just
fine in many cases. Subclassing is not the answer to all of life's
problems.
author | Greg Ward <greg@gerg.ca> |
---|---|
date | Sun, 24 Apr 2011 19:25:10 -0400 |
parents | b602ac02f1ba |
children | b24e5a708fad |
rev | line source |
---|---|
12432 | 1 Some tests for hgweb. Tests static files, plain files and different 404's. |
2 | |
3 $ hg init test | |
4 $ cd test | |
5 $ mkdir da | |
6 $ echo foo > da/foo | |
7 $ echo foo > foo | |
8 $ hg ci -Ambase | |
9 adding da/foo | |
10 adding foo | |
11 $ hg serve -n test -p $HGPORT -d --pid-file=hg.pid -A access.log -E errors.log | |
12 $ cat hg.pid >> $DAEMON_PIDS | |
13 | |
14 manifest | |
3942 | 15 |
12432 | 16 $ ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/?style=raw') |
17 200 Script output follows | |
18 | |
19 | |
20 drwxr-xr-x da | |
21 -rw-r--r-- 4 foo | |
22 | |
23 | |
24 $ ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/da?style=raw') | |
25 200 Script output follows | |
26 | |
27 | |
28 -rw-r--r-- 4 foo | |
29 | |
30 | |
31 | |
32 plain file | |
33 | |
34 $ "$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/foo?style=raw' | |
35 200 Script output follows | |
36 | |
37 foo | |
38 | |
39 should give a 404 - static file that does not exist | |
9842
d3dbdca92458
hgweb: don't choke when an inexistent style is requested (issue1901)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8167
diff
changeset
|
40 |
12432 | 41 $ "$TESTDIR/get-with-headers.py" localhost:$HGPORT '/static/bogus' |
42 404 Not Found | |
43 | |
44 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> | |
45 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US"> | |
46 <head> | |
47 <link rel="icon" href="/static/hgicon.png" type="image/png" /> | |
48 <meta name="robots" content="index, nofollow" /> | |
49 <link rel="stylesheet" href="/static/style-paper.css" type="text/css" /> | |
50 | |
51 <title>test: error</title> | |
52 </head> | |
53 <body> | |
54 | |
55 <div class="container"> | |
56 <div class="menu"> | |
57 <div class="logo"> | |
58 <a href="http://mercurial.selenic.com/"> | |
59 <img src="/static/hglogo.png" width=75 height=90 border=0 alt="mercurial" /></a> | |
60 </div> | |
61 <ul> | |
62 <li><a href="/shortlog">log</a></li> | |
63 <li><a href="/graph">graph</a></li> | |
64 <li><a href="/tags">tags</a></li> | |
13597
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
12846
diff
changeset
|
65 <li><a href="/bookmarks">bookmarks</a></li> |
12432 | 66 <li><a href="/branches">branches</a></li> |
12680
d664547ef540
hgweb: add help link to templates missed in ead4e21f49f1
Augie Fackler <durin42@gmail.com>
parents:
12666
diff
changeset
|
67 <li><a href="/help">help</a></li> |
12432 | 68 </ul> |
69 </div> | |
70 | |
71 <div class="main"> | |
72 | |
73 <h2><a href="/">test</a></h2> | |
74 <h3>error</h3> | |
75 | |
76 <form class="search" action="/log"> | |
77 | |
78 <p><input name="rev" id="search1" type="text" size="30"></p> | |
79 <div id="hint">find changesets by author, revision, | |
80 files, or words in the commit message</div> | |
81 </form> | |
82 | |
83 <div class="description"> | |
84 <p> | |
85 An error occurred while processing your request: | |
86 </p> | |
87 <p> | |
88 Not Found | |
89 </p> | |
90 </div> | |
91 </div> | |
92 </div> | |
93 | |
94 | |
95 | |
96 </body> | |
97 </html> | |
98 | |
99 [1] | |
100 | |
101 should give a 404 - bad revision | |
102 | |
103 $ "$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/spam/foo?style=raw' | |
104 404 Not Found | |
105 | |
106 | |
107 error: revision not found: spam | |
108 [1] | |
109 | |
110 should give a 400 - bad command | |
9842
d3dbdca92458
hgweb: don't choke when an inexistent style is requested (issue1901)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8167
diff
changeset
|
111 |
12432 | 112 $ "$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/foo?cmd=spam&style=raw' |
113 400* (glob) | |
114 | |
115 | |
116 error: no such method: spam | |
117 [1] | |
118 | |
119 should give a 404 - file does not exist | |
5561
22713dce19f6
hgweb: return meaningful HTTP status codes instead of nonsense
Bryan O'Sullivan <bos@serpentine.com>
parents:
5384
diff
changeset
|
120 |
12432 | 121 $ "$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/bork?style=raw' |
122 404 Not Found | |
123 | |
124 | |
125 error: bork@2ef0ac749a14: not found in manifest | |
126 [1] | |
127 $ "$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/bork' | |
128 404 Not Found | |
129 | |
130 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> | |
131 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US"> | |
132 <head> | |
133 <link rel="icon" href="/static/hgicon.png" type="image/png" /> | |
134 <meta name="robots" content="index, nofollow" /> | |
135 <link rel="stylesheet" href="/static/style-paper.css" type="text/css" /> | |
136 | |
137 <title>test: error</title> | |
138 </head> | |
139 <body> | |
140 | |
141 <div class="container"> | |
142 <div class="menu"> | |
143 <div class="logo"> | |
144 <a href="http://mercurial.selenic.com/"> | |
145 <img src="/static/hglogo.png" width=75 height=90 border=0 alt="mercurial" /></a> | |
146 </div> | |
147 <ul> | |
148 <li><a href="/shortlog">log</a></li> | |
149 <li><a href="/graph">graph</a></li> | |
150 <li><a href="/tags">tags</a></li> | |
13597
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
12846
diff
changeset
|
151 <li><a href="/bookmarks">bookmarks</a></li> |
12432 | 152 <li><a href="/branches">branches</a></li> |
12680
d664547ef540
hgweb: add help link to templates missed in ead4e21f49f1
Augie Fackler <durin42@gmail.com>
parents:
12666
diff
changeset
|
153 <li><a href="/help">help</a></li> |
12432 | 154 </ul> |
155 </div> | |
156 | |
157 <div class="main"> | |
158 | |
159 <h2><a href="/">test</a></h2> | |
160 <h3>error</h3> | |
161 | |
162 <form class="search" action="/log"> | |
163 | |
164 <p><input name="rev" id="search1" type="text" size="30"></p> | |
165 <div id="hint">find changesets by author, revision, | |
166 files, or words in the commit message</div> | |
167 </form> | |
168 | |
169 <div class="description"> | |
170 <p> | |
171 An error occurred while processing your request: | |
172 </p> | |
173 <p> | |
174 bork@2ef0ac749a14: not found in manifest | |
175 </p> | |
176 </div> | |
177 </div> | |
178 </div> | |
179 | |
180 | |
181 | |
182 </body> | |
183 </html> | |
184 | |
185 [1] | |
186 $ "$TESTDIR/get-with-headers.py" localhost:$HGPORT '/diff/tip/bork?style=raw' | |
187 404 Not Found | |
188 | |
189 | |
190 error: bork@2ef0ac749a14: not found in manifest | |
191 [1] | |
5561
22713dce19f6
hgweb: return meaningful HTTP status codes instead of nonsense
Bryan O'Sullivan <bos@serpentine.com>
parents:
5384
diff
changeset
|
192 |
12432 | 193 try bad style |
5561
22713dce19f6
hgweb: return meaningful HTTP status codes instead of nonsense
Bryan O'Sullivan <bos@serpentine.com>
parents:
5384
diff
changeset
|
194 |
12432 | 195 $ ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/?style=foobar') |
196 200 Script output follows | |
197 | |
198 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> | |
199 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US"> | |
200 <head> | |
201 <link rel="icon" href="/static/hgicon.png" type="image/png" /> | |
202 <meta name="robots" content="index, nofollow" /> | |
203 <link rel="stylesheet" href="/static/style-paper.css" type="text/css" /> | |
204 | |
205 <title>test: 2ef0ac749a14 /</title> | |
206 </head> | |
207 <body> | |
208 | |
209 <div class="container"> | |
210 <div class="menu"> | |
211 <div class="logo"> | |
212 <a href="http://mercurial.selenic.com/"> | |
213 <img src="/static/hglogo.png" alt="mercurial" /></a> | |
214 </div> | |
215 <ul> | |
216 <li><a href="/shortlog/2ef0ac749a14">log</a></li> | |
217 <li><a href="/graph/2ef0ac749a14">graph</a></li> | |
218 <li><a href="/tags">tags</a></li> | |
13597
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
12846
diff
changeset
|
219 <li><a href="/bookmarks">bookmarks</a></li> |
12432 | 220 <li><a href="/branches">branches</a></li> |
221 </ul> | |
222 <ul> | |
223 <li><a href="/rev/2ef0ac749a14">changeset</a></li> | |
224 <li class="active">browse</li> | |
225 </ul> | |
226 <ul> | |
227 | |
228 </ul> | |
12666
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12432
diff
changeset
|
229 <ul> |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12432
diff
changeset
|
230 <li><a href="/help">help</a></li> |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12432
diff
changeset
|
231 </ul> |
12432 | 232 </div> |
233 | |
234 <div class="main"> | |
235 <h2><a href="/">test</a></h2> | |
236 <h3>directory / @ 0:2ef0ac749a14 <span class="tag">tip</span> </h3> | |
237 | |
238 <form class="search" action="/log"> | |
239 | |
240 <p><input name="rev" id="search1" type="text" size="30" /></p> | |
241 <div id="hint">find changesets by author, revision, | |
242 files, or words in the commit message</div> | |
243 </form> | |
244 | |
245 <table class="bigtable"> | |
246 <tr> | |
247 <th class="name">name</th> | |
248 <th class="size">size</th> | |
249 <th class="permissions">permissions</th> | |
250 </tr> | |
251 <tr class="fileline parity0"> | |
252 <td class="name"><a href="/file/2ef0ac749a14/">[up]</a></td> | |
253 <td class="size"></td> | |
254 <td class="permissions">drwxr-xr-x</td> | |
255 </tr> | |
256 | |
257 <tr class="fileline parity1"> | |
258 <td class="name"> | |
259 <a href="/file/2ef0ac749a14/da"> | |
260 <img src="/static/coal-folder.png" alt="dir."/> da/ | |
261 </a> | |
262 <a href="/file/2ef0ac749a14/da/"> | |
263 | |
264 </a> | |
265 </td> | |
266 <td class="size"></td> | |
267 <td class="permissions">drwxr-xr-x</td> | |
268 </tr> | |
269 | |
270 <tr class="fileline parity0"> | |
271 <td class="filename"> | |
272 <a href="/file/2ef0ac749a14/foo"> | |
273 <img src="/static/coal-file.png" alt="file"/> foo | |
274 </a> | |
275 </td> | |
276 <td class="size">4</td> | |
277 <td class="permissions">-rw-r--r--</td> | |
278 </tr> | |
279 </table> | |
280 </div> | |
281 </div> | |
282 | |
283 | |
284 </body> | |
285 </html> | |
286 | |
5561
22713dce19f6
hgweb: return meaningful HTTP status codes instead of nonsense
Bryan O'Sullivan <bos@serpentine.com>
parents:
5384
diff
changeset
|
287 |
12432 | 288 stop and restart |
289 | |
290 $ "$TESTDIR/killdaemons.py" | |
291 $ hg serve -p $HGPORT -d --pid-file=hg.pid -A access.log | |
292 $ cat hg.pid >> $DAEMON_PIDS | |
5561
22713dce19f6
hgweb: return meaningful HTTP status codes instead of nonsense
Bryan O'Sullivan <bos@serpentine.com>
parents:
5384
diff
changeset
|
293 |
12432 | 294 Test the access/error files are opened in append mode |
295 | |
296 $ python -c "print len(file('access.log').readlines()), 'log lines written'" | |
297 10 log lines written | |
298 | |
299 static file | |
5561
22713dce19f6
hgweb: return meaningful HTTP status codes instead of nonsense
Bryan O'Sullivan <bos@serpentine.com>
parents:
5384
diff
changeset
|
300 |
12432 | 301 $ "$TESTDIR/get-with-headers.py" --twice localhost:$HGPORT '/static/style-gitweb.css' |
302 200 Script output follows | |
303 | |
304 body { font-family: sans-serif; font-size: 12px; margin:0px; border:solid #d9d8d1; border-width:1px; margin:10px; } | |
305 a { color:#0000cc; } | |
306 a:hover, a:visited, a:active { color:#880000; } | |
307 div.page_header { height:25px; padding:8px; font-size:18px; font-weight:bold; background-color:#d9d8d1; } | |
308 div.page_header a:visited { color:#0000cc; } | |
309 div.page_header a:hover { color:#880000; } | |
310 div.page_nav { padding:8px; } | |
311 div.page_nav a:visited { color:#0000cc; } | |
312 div.page_path { padding:8px; border:solid #d9d8d1; border-width:0px 0px 1px} | |
313 div.page_footer { padding:4px 8px; background-color: #d9d8d1; } | |
314 div.page_footer_text { float:left; color:#555555; font-style:italic; } | |
315 div.page_body { padding:8px; } | |
316 div.title, a.title { | |
317 display:block; padding:6px 8px; | |
318 font-weight:bold; background-color:#edece6; text-decoration:none; color:#000000; | |
319 } | |
320 a.title:hover { background-color: #d9d8d1; } | |
321 div.title_text { padding:6px 0px; border: solid #d9d8d1; border-width:0px 0px 1px; } | |
322 div.log_body { padding:8px 8px 8px 150px; } | |
323 .age { white-space:nowrap; } | |
324 span.age { position:relative; float:left; width:142px; font-style:italic; } | |
325 div.log_link { | |
326 padding:0px 8px; | |
327 font-size:10px; font-family:sans-serif; font-style:normal; | |
328 position:relative; float:left; width:136px; | |
329 } | |
330 div.list_head { padding:6px 8px 4px; border:solid #d9d8d1; border-width:1px 0px 0px; font-style:italic; } | |
331 a.list { text-decoration:none; color:#000000; } | |
332 a.list:hover { text-decoration:underline; color:#880000; } | |
333 table { padding:8px 4px; } | |
334 th { padding:2px 5px; font-size:12px; text-align:left; } | |
335 tr.light:hover, .parity0:hover { background-color:#edece6; } | |
336 tr.dark, .parity1 { background-color:#f6f6f0; } | |
337 tr.dark:hover, .parity1:hover { background-color:#edece6; } | |
338 td { padding:2px 5px; font-size:12px; vertical-align:top; } | |
339 td.closed { background-color: #99f; } | |
340 td.link { padding:2px 5px; font-family:sans-serif; font-size:10px; } | |
341 td.indexlinks { white-space: nowrap; } | |
342 td.indexlinks a { | |
343 padding: 2px 5px; line-height: 10px; | |
344 border: 1px solid; | |
345 color: #ffffff; background-color: #7777bb; | |
346 border-color: #aaaadd #333366 #333366 #aaaadd; | |
347 font-weight: bold; text-align: center; text-decoration: none; | |
348 font-size: 10px; | |
349 } | |
350 td.indexlinks a:hover { background-color: #6666aa; } | |
351 div.pre { font-family:monospace; font-size:12px; white-space:pre; } | |
352 div.diff_info { font-family:monospace; color:#000099; background-color:#edece6; font-style:italic; } | |
353 div.index_include { border:solid #d9d8d1; border-width:0px 0px 1px; padding:12px 8px; } | |
354 div.search { margin:4px 8px; position:absolute; top:56px; right:12px } | |
355 .linenr { color:#999999; text-decoration:none } | |
356 div.rss_logo { float: right; white-space: nowrap; } | |
357 div.rss_logo a { | |
358 padding:3px 6px; line-height:10px; | |
359 border:1px solid; border-color:#fcc7a5 #7d3302 #3e1a01 #ff954e; | |
360 color:#ffffff; background-color:#ff6600; | |
361 font-weight:bold; font-family:sans-serif; font-size:10px; | |
362 text-align:center; text-decoration:none; | |
363 } | |
364 div.rss_logo a:hover { background-color:#ee5500; } | |
365 pre { margin: 0; } | |
366 span.logtags span { | |
367 padding: 0px 4px; | |
368 font-size: 10px; | |
369 font-weight: normal; | |
370 border: 1px solid; | |
371 background-color: #ffaaff; | |
372 border-color: #ffccff #ff00ee #ff00ee #ffccff; | |
373 } | |
374 span.logtags span.tagtag { | |
375 background-color: #ffffaa; | |
376 border-color: #ffffcc #ffee00 #ffee00 #ffffcc; | |
377 } | |
378 span.logtags span.branchtag { | |
379 background-color: #aaffaa; | |
380 border-color: #ccffcc #00cc33 #00cc33 #ccffcc; | |
381 } | |
382 span.logtags span.inbranchtag { | |
383 background-color: #d5dde6; | |
384 border-color: #e3ecf4 #9398f4 #9398f4 #e3ecf4; | |
385 } | |
13863
b602ac02f1ba
hgweb: add bookmark labels to gitweb theme (based on 270f57d35525)
Yuya Nishihara <yuya@tcha.org>
parents:
13597
diff
changeset
|
386 span.logtags span.bookmarktag { |
b602ac02f1ba
hgweb: add bookmark labels to gitweb theme (based on 270f57d35525)
Yuya Nishihara <yuya@tcha.org>
parents:
13597
diff
changeset
|
387 background-color: #afdffa; |
b602ac02f1ba
hgweb: add bookmark labels to gitweb theme (based on 270f57d35525)
Yuya Nishihara <yuya@tcha.org>
parents:
13597
diff
changeset
|
388 border-color: #ccecff #46ace6 #46ace6 #ccecff; |
b602ac02f1ba
hgweb: add bookmark labels to gitweb theme (based on 270f57d35525)
Yuya Nishihara <yuya@tcha.org>
parents:
13597
diff
changeset
|
389 } |
12432 | 390 |
391 /* Graph */ | |
392 div#wrapper { | |
393 position: relative; | |
394 margin: 0; | |
395 padding: 0; | |
396 margin-top: 3px; | |
397 } | |
398 | |
399 canvas { | |
400 position: absolute; | |
401 z-index: 5; | |
402 top: -0.9em; | |
403 margin: 0; | |
404 } | |
405 | |
406 ul#nodebgs { | |
407 list-style: none inside none; | |
408 padding: 0; | |
409 margin: 0; | |
410 top: -0.7em; | |
411 } | |
412 | |
413 ul#graphnodes li, ul#nodebgs li { | |
414 height: 39px; | |
415 } | |
416 | |
417 ul#graphnodes { | |
418 position: absolute; | |
419 z-index: 10; | |
420 top: -0.8em; | |
421 list-style: none inside none; | |
422 padding: 0; | |
423 } | |
424 | |
425 ul#graphnodes li .info { | |
426 display: block; | |
427 font-size: 100%; | |
428 position: relative; | |
429 top: -3px; | |
430 font-style: italic; | |
431 } | |
432 304 Not Modified | |
433 | |
9842
d3dbdca92458
hgweb: don't choke when an inexistent style is requested (issue1901)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8167
diff
changeset
|
434 |
12432 | 435 errors |
5690
1b365c5723bc
server: append to logfiles
Mirko Friedenhagen <mirko-lists@friedenhagen.de>
parents:
5580
diff
changeset
|
436 |
12432 | 437 $ cat errors.log |