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