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