Debian Codegraph @

tests/test-progress.t

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