##// END OF EJS Templates
tests: conditionalize the progress timestamp for Windows...
Matt Harbison -
r46691:31ecf715 default
parent child Browse files
Show More
@@ -1,403 +1,409 b''
1 1
2 2 $ cat > loop.py <<EOF
3 3 > from __future__ import absolute_import
4 4 > import time
5 5 > from mercurial import commands, registrar
6 6 >
7 7 > cmdtable = {}
8 8 > command = registrar.command(cmdtable)
9 9 >
10 10 > class incrementingtime(object):
11 11 > def __init__(self):
12 12 > self._time = 0.0
13 13 > def __call__(self):
14 14 > self._time += 0.25
15 15 > return self._time
16 16 > time.time = incrementingtime()
17 17 >
18 18 > @command(b'loop',
19 19 > [(b'', b'total', b'', b'override for total'),
20 20 > (b'', b'nested', False, b'show nested results'),
21 21 > (b'', b'parallel', False, b'show parallel sets of results'),
22 22 > (b'', b'warn', False, b'show warning if step divisible by 3')],
23 23 > b'hg loop LOOPS',
24 24 > norepo=True)
25 25 > def loop(ui, loops, **opts):
26 26 > loops = int(loops)
27 27 > total = None
28 28 > if loops >= 0:
29 29 > total = loops
30 30 > if opts.get('total', None):
31 31 > total = int(opts.get('total'))
32 32 > nested = False
33 33 > if opts.get('nested', None):
34 34 > nested = True
35 35 > loops = abs(loops)
36 36 > showwarn = opts.get('warn', False)
37 37 >
38 38 > progress = ui.makeprogress(topiclabel, unit=b'loopnum', total=total)
39 39 > other = ui.makeprogress(b'other', unit=b'othernum', total=total)
40 40 > for i in range(loops):
41 41 > progress.update(i, item=getloopitem(i))
42 42 > if opts.get('parallel'):
43 43 > other.update(i, item=b'other.%d' % i)
44 44 > if nested:
45 45 > nested_steps = 2
46 46 > if i and i % 4 == 0:
47 47 > nested_steps = 5
48 48 > nested = ui.makeprogress(b'nested', unit=b'nestnum',
49 49 > total=nested_steps)
50 50 > for j in range(nested_steps):
51 51 > nested.update(j, item=b'nested.%d' % j)
52 52 > nested.complete()
53 53 > if showwarn and i % 3 == 0:
54 54 > ui.warn(b'reached step %d\n' %i)
55 55 > progress.complete()
56 56 >
57 57 > topiclabel = b'loop'
58 58 > def getloopitem(i):
59 59 > return b'loop.%d' % i
60 60 >
61 61 > EOF
62 62
63 63 $ cp $HGRCPATH $HGRCPATH.orig
64 64 $ echo "[extensions]" >> $HGRCPATH
65 65 $ echo "progress=" >> $HGRCPATH
66 66 $ echo "loop=`pwd`/loop.py" >> $HGRCPATH
67 67 $ echo "[progress]" >> $HGRCPATH
68 68 $ echo "format = topic bar number" >> $HGRCPATH
69 69 $ echo "assume-tty=1" >> $HGRCPATH
70 70 $ echo "width=60" >> $HGRCPATH
71 71
72 72 test default params, display nothing because of delay
73 73
74 74 $ hg -y loop 3
75 75 $ echo "delay=0" >> $HGRCPATH
76 76 $ echo "refresh=0" >> $HGRCPATH
77 77
78 78 test with delay=0, refresh=0
79 79
80 80 $ hg -y loop 3
81 81 \r (no-eol) (esc)
82 82 loop [ ] 0/3\r (no-eol) (esc)
83 83 loop [===============> ] 1/3\r (no-eol) (esc)
84 84 loop [===============================> ] 2/3\r (no-eol) (esc)
85 85 \r (no-eol) (esc)
86 86 no progress with --quiet
87 87 $ hg -y loop 3 --quiet
88 88
89 89 test plain mode exception
90 90 $ HGPLAINEXCEPT=progress hg -y loop 1
91 91 \r (no-eol) (esc)
92 92 loop [ ] 0/1\r (no-eol) (esc)
93 93 \r (no-eol) (esc)
94 94
95 95 test nested short-lived topics (which shouldn't display with nestdelay):
96 96
97 97 $ hg -y loop 3 --nested
98 98 \r (no-eol) (esc)
99 99 loop [ ] 0/3\r (no-eol) (esc)
100 100 loop [===============> ] 1/3\r (no-eol) (esc)
101 101 loop [===============================> ] 2/3\r (no-eol) (esc)
102 102 \r (no-eol) (esc)
103 103
104 104 Test nested long-lived topic which has the same name as a short-lived
105 105 peer. We shouldn't get stuck showing the short-lived inner steps, and
106 106 should go back to skipping the inner steps when the slow nested step
107 107 finishes.
108 108
109 109 $ hg -y loop 7 --nested
110 110 \r (no-eol) (esc)
111 111 loop [ ] 0/7\r (no-eol) (esc)
112 112 loop [=====> ] 1/7\r (no-eol) (esc)
113 113 loop [============> ] 2/7\r (no-eol) (esc)
114 114 loop [===================> ] 3/7\r (no-eol) (esc)
115 115 loop [==========================> ] 4/7\r (no-eol) (esc)
116 116 nested [==========================> ] 3/5\r (no-eol) (esc)
117 117 nested [===================================> ] 4/5\r (no-eol) (esc)
118 118 loop [=================================> ] 5/7\r (no-eol) (esc)
119 119 loop [========================================> ] 6/7\r (no-eol) (esc)
120 120 \r (no-eol) (esc)
121 121
122 122
123 123 $ hg --config progress.changedelay=0 -y loop 3 --nested
124 124 \r (no-eol) (esc)
125 125 loop [ ] 0/3\r (no-eol) (esc)
126 126 nested [ ] 0/2\r (no-eol) (esc)
127 127 nested [======================> ] 1/2\r (no-eol) (esc)
128 128 loop [===============> ] 1/3\r (no-eol) (esc)
129 129 nested [ ] 0/2\r (no-eol) (esc)
130 130 nested [======================> ] 1/2\r (no-eol) (esc)
131 131 loop [===============================> ] 2/3\r (no-eol) (esc)
132 132 nested [ ] 0/2\r (no-eol) (esc)
133 133 nested [======================> ] 1/2\r (no-eol) (esc)
134 134 \r (no-eol) (esc)
135 135
136 136
137 137 test two topics being printed in parallel (as when we're doing a local
138 138 --pull clone, where you get the unbundle and bundle progress at the
139 139 same time):
140 140 $ hg loop 3 --parallel
141 141 \r (no-eol) (esc)
142 142 loop [ ] 0/3\r (no-eol) (esc)
143 143 loop [===============> ] 1/3\r (no-eol) (esc)
144 144 loop [===============================> ] 2/3\r (no-eol) (esc)
145 145 \r (no-eol) (esc)
146 146 test refresh is taken in account
147 147
148 148 $ hg -y --config progress.refresh=100 loop 3
149 149
150 150 test format options 1
151 151
152 152 $ hg -y --config 'progress.format=number topic item+2' loop 2
153 153 \r (no-eol) (esc)
154 154 0/2 loop lo\r (no-eol) (esc)
155 155 1/2 loop lo\r (no-eol) (esc)
156 156 \r (no-eol) (esc)
157 157
158 158 test format options 2
159 159
160 160 $ hg -y --config 'progress.format=number item-3 bar' loop 2
161 161 \r (no-eol) (esc)
162 162 0/2 p.0 [ ]\r (no-eol) (esc)
163 163 1/2 p.1 [=======================> ]\r (no-eol) (esc)
164 164 \r (no-eol) (esc)
165 165
166 166 test format options and indeterminate progress
167 167
168 168 $ hg -y --config 'progress.format=number item bar' loop -- -2
169 169 \r (no-eol) (esc)
170 170 0 loop.0 [ <=> ]\r (no-eol) (esc)
171 171 1 loop.1 [ <=> ]\r (no-eol) (esc)
172 172 \r (no-eol) (esc)
173 173
174 174 make sure things don't fall over if count > total
175 175
176 176 $ hg -y loop --total 4 6
177 177 \r (no-eol) (esc)
178 178 loop [ ] 0/4\r (no-eol) (esc)
179 179 loop [===========> ] 1/4\r (no-eol) (esc)
180 180 loop [=======================> ] 2/4\r (no-eol) (esc)
181 181 loop [===================================> ] 3/4\r (no-eol) (esc)
182 182 loop [===============================================>] 4/4\r (no-eol) (esc)
183 183 loop [ <=> ] 5/4\r (no-eol) (esc)
184 184 \r (no-eol) (esc)
185 185
186 186 test interaction with ui.warn
187 187
188 188 $ hg loop --warn 6
189 189 \r (no-eol) (esc)
190 190 loop [ ] 0/6\r (no-eol) (esc)
191 191 \r (no-eol) (esc)
192 192 reached step 0
193 193 \r (no-eol) (esc)
194 194 loop [=======> ] 1/6\r (no-eol) (esc)
195 195 loop [===============> ] 2/6\r (no-eol) (esc)
196 196 loop [=======================> ] 3/6\r (no-eol) (esc)
197 197 \r (no-eol) (esc)
198 198 reached step 3
199 199 \r (no-eol) (esc)
200 200 loop [===============================> ] 4/6\r (no-eol) (esc)
201 201 loop [=======================================> ] 5/6\r (no-eol) (esc)
202 202 \r (no-eol) (esc)
203 203
204 204 test interaction with ui.timestamp-output
205 205
206 XXX: The timestamp on Windows with py2 hg is in 1970, and py3 hg is now. But
207 the py2/py3 checks here test the test runner, not the binary. The Windows lines
208 can be dropped when switching to py3-only.
209
206 210 $ hg loop --warn --config ui.timestamp-output=true 6
207 211 \r (no-eol) (esc)
208 212 loop [ ] 0/6\r (no-eol) (esc)
209 213 \r (no-eol) (esc)
210 \[20[2-9][0-9]-[01][0-9]-[0-3][0-9]T[0-5][0-9]:[0-5][0-9]:[0-5][0-9]\.[0-9][0-9][0-9][0-9][0-9][0-9]\] reached step 0 (re)
214 [*T*] reached step 0 (glob) (windows !)
215 \[20[2-9][0-9]-[01][0-9]-[0-3][0-9]T[0-5][0-9]:[0-5][0-9]:[0-5][0-9]\.[0-9][0-9][0-9][0-9][0-9][0-9]\] reached step 0 (re) (no-windows !)
211 216 \r (no-eol) (esc)
212 217 loop [=======> ] 1/6\r (no-eol) (esc)
213 218 loop [===============> ] 2/6\r (no-eol) (esc)
214 219 loop [=======================> ] 3/6\r (no-eol) (esc)
215 220 \r (no-eol) (esc)
216 \[20[2-9][0-9]-[01][0-9]-[0-3][0-9]T[0-5][0-9]:[0-5][0-9]:[0-5][0-9]\.[0-9][0-9][0-9][0-9][0-9][0-9]\] reached step 3 (re)
221 [*T*] reached step 3 (glob) (windows !)
222 \[20[2-9][0-9]-[01][0-9]-[0-3][0-9]T[0-5][0-9]:[0-5][0-9]:[0-5][0-9]\.[0-9][0-9][0-9][0-9][0-9][0-9]\] reached step 3 (re) (no-windows !)
217 223 \r (no-eol) (esc)
218 224 loop [===============================> ] 4/6\r (no-eol) (esc)
219 225 loop [=======================================> ] 5/6\r (no-eol) (esc)
220 226 \r (no-eol) (esc)
221 227
222 228 test immediate progress completion
223 229
224 230 $ hg -y loop 0
225 231
226 232 test delay time estimates
227 233
228 234 #if no-chg
229 235
230 236 $ cp $HGRCPATH.orig $HGRCPATH
231 237 $ echo "[extensions]" >> $HGRCPATH
232 238 $ echo "mocktime=$TESTDIR/mocktime.py" >> $HGRCPATH
233 239 $ echo "progress=" >> $HGRCPATH
234 240 $ echo "loop=`pwd`/loop.py" >> $HGRCPATH
235 241 $ echo "[progress]" >> $HGRCPATH
236 242 $ echo "assume-tty=1" >> $HGRCPATH
237 243 $ echo "delay=25" >> $HGRCPATH
238 244 $ echo "width=60" >> $HGRCPATH
239 245
240 246 $ MOCKTIME=11 hg -y loop 8
241 247 \r (no-eol) (esc)
242 248 loop [=========> ] 2/8 1m07s\r (no-eol) (esc)
243 249 loop [===============> ] 3/8 56s\r (no-eol) (esc)
244 250 loop [=====================> ] 4/8 45s\r (no-eol) (esc)
245 251 loop [==========================> ] 5/8 34s\r (no-eol) (esc)
246 252 loop [================================> ] 6/8 23s\r (no-eol) (esc)
247 253 loop [=====================================> ] 7/8 12s\r (no-eol) (esc)
248 254 \r (no-eol) (esc)
249 255
250 256 $ MOCKTIME=10000 hg -y loop 4
251 257 \r (no-eol) (esc)
252 258 loop [ ] 0/4\r (no-eol) (esc)
253 259 loop [=========> ] 1/4 8h21m\r (no-eol) (esc)
254 260 loop [====================> ] 2/4 5h34m\r (no-eol) (esc)
255 261 loop [==============================> ] 3/4 2h47m\r (no-eol) (esc)
256 262 \r (no-eol) (esc)
257 263
258 264 $ MOCKTIME=1000000 hg -y loop 4
259 265 \r (no-eol) (esc)
260 266 loop [ ] 0/4\r (no-eol) (esc)
261 267 loop [=========> ] 1/4 5w00d\r (no-eol) (esc)
262 268 loop [====================> ] 2/4 3w03d\r (no-eol) (esc)
263 269 loop [=============================> ] 3/4 11d14h\r (no-eol) (esc)
264 270 \r (no-eol) (esc)
265 271
266 272
267 273 $ MOCKTIME=14000000 hg -y loop 4
268 274 \r (no-eol) (esc)
269 275 loop [ ] 0/4\r (no-eol) (esc)
270 276 loop [=========> ] 1/4 1y18w\r (no-eol) (esc)
271 277 loop [===================> ] 2/4 46w03d\r (no-eol) (esc)
272 278 loop [=============================> ] 3/4 23w02d\r (no-eol) (esc)
273 279 \r (no-eol) (esc)
274 280
275 281 Non-linear progress:
276 282
277 283 $ MOCKTIME='20 20 20 20 20 20 20 20 20 20 500 500 500 500 500 20 20 20 20 20' hg -y loop 20
278 284 \r (no-eol) (esc)
279 285 loop [=> ] 1/20 6m21s\r (no-eol) (esc)
280 286 loop [===> ] 2/20 6m01s\r (no-eol) (esc)
281 287 loop [=====> ] 3/20 5m41s\r (no-eol) (esc)
282 288 loop [=======> ] 4/20 5m21s\r (no-eol) (esc)
283 289 loop [=========> ] 5/20 5m01s\r (no-eol) (esc)
284 290 loop [===========> ] 6/20 4m41s\r (no-eol) (esc)
285 291 loop [=============> ] 7/20 4m21s\r (no-eol) (esc)
286 292 loop [===============> ] 8/20 4m01s\r (no-eol) (esc)
287 293 loop [================> ] 9/20 25m40s\r (no-eol) (esc)
288 294 loop [===================> ] 10/20 1h06m\r (no-eol) (esc)
289 295 loop [=====================> ] 11/20 1h13m\r (no-eol) (esc)
290 296 loop [=======================> ] 12/20 1h07m\r (no-eol) (esc)
291 297 loop [========================> ] 13/20 58m19s\r (no-eol) (esc)
292 298 loop [===========================> ] 14/20 7m09s\r (no-eol) (esc)
293 299 loop [=============================> ] 15/20 3m38s\r (no-eol) (esc)
294 300 loop [===============================> ] 16/20 2m15s\r (no-eol) (esc)
295 301 loop [=================================> ] 17/20 1m27s\r (no-eol) (esc)
296 302 loop [====================================> ] 18/20 52s\r (no-eol) (esc)
297 303 loop [======================================> ] 19/20 25s\r (no-eol) (esc)
298 304 \r (no-eol) (esc)
299 305
300 306 Time estimates should not fail when there's no end point:
301 307 $ MOCKTIME=11 hg -y loop -- -4
302 308 \r (no-eol) (esc)
303 309 loop [ <=> ] 2\r (no-eol) (esc)
304 310 loop [ <=> ] 3\r (no-eol) (esc)
305 311 \r (no-eol) (esc)
306 312
307 313 #endif
308 314
309 315 test line trimming by '[progress] width', when progress topic contains
310 316 multi-byte characters, of which length of byte sequence and columns in
311 317 display are different from each other.
312 318
313 319 $ cp $HGRCPATH.orig $HGRCPATH
314 320 $ cat >> $HGRCPATH <<EOF
315 321 > [extensions]
316 322 > progress=
317 323 > loop=`pwd`/loop.py
318 324 > [progress]
319 325 > assume-tty = 1
320 326 > delay = 0
321 327 > refresh = 0
322 328 > EOF
323 329
324 330 $ rm -f loop.pyc
325 331 $ cat >> loop.py <<EOF
326 332 > # use non-ascii characters as topic label of progress
327 333 > # 2 x 4 = 8 columns, but 3 x 4 = 12 bytes
328 334 > topiclabel = u'\u3042\u3044\u3046\u3048'.encode('utf-8')
329 335 > EOF
330 336
331 337 $ cat >> $HGRCPATH <<EOF
332 338 > [progress]
333 339 > format = topic number
334 340 > width= 12
335 341 > EOF
336 342
337 343 $ hg --encoding utf-8 -y loop --total 3 3
338 344 \r (no-eol) (esc)
339 345 \xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\xe3\x81\x88 0/3\r (no-eol) (esc)
340 346 \xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\xe3\x81\x88 1/3\r (no-eol) (esc)
341 347 \xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\xe3\x81\x88 2/3\r (no-eol) (esc)
342 348 \r (no-eol) (esc)
343 349
344 350 test calculation of bar width, when progress topic contains multi-byte
345 351 characters, of which length of byte sequence and columns in display
346 352 are different from each other.
347 353
348 354 $ cat >> $HGRCPATH <<EOF
349 355 > [progress]
350 356 > format = topic bar
351 357 > width= 21
352 358 > # progwidth should be 9 (= 21 - (8+1) - 3)
353 359 > EOF
354 360
355 361 $ hg --encoding utf-8 -y loop --total 3 3
356 362 \r (no-eol) (esc)
357 363 \xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\xe3\x81\x88 [ ]\r (no-eol) (esc)
358 364 \xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\xe3\x81\x88 [==> ]\r (no-eol) (esc)
359 365 \xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\xe3\x81\x88 [=====> ]\r (no-eol) (esc)
360 366 \r (no-eol) (esc)
361 367
362 368 test trimming progress items, when they contain multi-byte characters,
363 369 of which length of byte sequence and columns in display are different
364 370 from each other.
365 371
366 372 $ rm -f loop.pyc
367 373 $ rm -Rf __pycache__
368 374 $ cat >> loop.py <<EOF
369 375 > # use non-ascii characters as loop items of progress
370 376 > loopitems = [
371 377 > u'\u3042\u3044'.encode('utf-8'), # 2 x 2 = 4 columns
372 378 > u'\u3042\u3044\u3046'.encode('utf-8'), # 2 x 3 = 6 columns
373 379 > u'\u3042\u3044\u3046\u3048'.encode('utf-8'), # 2 x 4 = 8 columns
374 380 > ]
375 381 > def getloopitem(i):
376 382 > return loopitems[i % len(loopitems)]
377 383 > EOF
378 384
379 385 $ cat >> $HGRCPATH <<EOF
380 386 > [progress]
381 387 > # trim at tail side
382 388 > format = item+6
383 389 > EOF
384 390
385 391 $ hg --encoding utf-8 -y loop --total 3 3
386 392 \r (no-eol) (esc)
387 393 \xe3\x81\x82\xe3\x81\x84 \r (no-eol) (esc)
388 394 \xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\r (no-eol) (esc)
389 395 \xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\r (no-eol) (esc)
390 396 \r (no-eol) (esc)
391 397
392 398 $ cat >> $HGRCPATH <<EOF
393 399 > [progress]
394 400 > # trim at left side
395 401 > format = item-6
396 402 > EOF
397 403
398 404 $ hg --encoding utf-8 -y loop --total 3 3
399 405 \r (no-eol) (esc)
400 406 \xe3\x81\x82\xe3\x81\x84 \r (no-eol) (esc)
401 407 \xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\r (no-eol) (esc)
402 408 \xe3\x81\x84\xe3\x81\x86\xe3\x81\x88\r (no-eol) (esc)
403 409 \r (no-eol) (esc)
General Comments 0
You need to be logged in to leave comments. Login now