1 Trying: |
1 test (__main__.DocumentationTestCase) ... Trying: |
2 @memoize_uw |
2 from decorator import getargspec # akin to inspect.getargspec |
3 def f1(x): |
3 Expecting nothing |
4 time.sleep(1) # simulate some long computation |
4 ok |
5 return x |
5 Trying: |
6 Expecting nothing |
6 print(getargspec(f1)) |
7 ok |
7 Expecting: |
8 Trying: |
8 ArgSpec(args=[], varargs='args', varkw='kw', defaults=None) |
9 from inspect import getargspec |
9 ok |
10 Expecting nothing |
10 Trying: |
11 ok |
11 f1(0, 1) # doctest: +IGNORE_EXCEPTION_DETAIL |
12 Trying: |
|
13 print getargspec(f1) # I am using Python 2.6+ here |
|
14 Expecting: |
|
15 ArgSpec(args=[], varargs='args', keywords='kw', defaults=None) |
|
16 ok |
|
17 Trying: |
|
18 f1(0, 1) |
|
19 Expecting: |
12 Expecting: |
20 Traceback (most recent call last): |
13 Traceback (most recent call last): |
21 ... |
14 ... |
22 TypeError: f1() takes exactly 1 argument (2 given) |
15 TypeError: f1() takes exactly 1 positional argument (2 given) |
23 ok |
16 ok |
24 Trying: |
17 Trying: |
25 from decorator import decorator |
18 from decorator import decorate |
26 Expecting nothing |
19 Expecting nothing |
27 ok |
20 ok |
28 Trying: |
21 Trying: |
29 @memoize |
22 @memoize |
30 def heavy_computation(): |
23 def heavy_computation(): |
31 time.sleep(2) |
24 time.sleep(2) |
32 return "done" |
25 return "done" |
33 Expecting nothing |
26 Expecting nothing |
34 ok |
27 ok |
35 Trying: |
28 Trying: |
36 print heavy_computation() # the first time it will take 2 seconds |
29 print(heavy_computation()) # the first time it will take 2 seconds |
37 Expecting: |
30 Expecting: |
38 done |
31 done |
39 ok |
32 ok |
40 Trying: |
33 Trying: |
41 print heavy_computation() # the second time it will be instantaneous |
34 print(heavy_computation()) # the second time it will be instantaneous |
42 Expecting: |
35 Expecting: |
43 done |
36 done |
44 ok |
37 ok |
45 Trying: |
38 Trying: |
46 print getargspec(heavy_computation) |
39 print(getargspec(heavy_computation)) |
47 Expecting: |
40 Expecting: |
48 ArgSpec(args=[], varargs=None, keywords=None, defaults=None) |
41 ArgSpec(args=[], varargs=None, varkw=None, defaults=None) |
49 ok |
42 ok |
50 Trying: |
43 Trying: |
51 @trace |
44 @trace |
52 def f1(x): |
45 def f1(x): |
53 pass |
46 pass |
73 f(0, 3) |
66 f(0, 3) |
74 Expecting: |
67 Expecting: |
75 calling f with args (0, 3, 2), {} |
68 calling f with args (0, 3, 2), {} |
76 ok |
69 ok |
77 Trying: |
70 Trying: |
78 print getargspec(f) |
71 print(getargspec(f)) |
79 Expecting: |
72 Expecting: |
80 ArgSpec(args=['x', 'y', 'z'], varargs='args', keywords='kw', defaults=(1, 2)) |
73 ArgSpec(args=['x', 'y', 'z'], varargs='args', varkw='kw', defaults=(1, 2)) |
81 ok |
74 ok |
82 Trying: |
75 Trying: |
83 @trace |
76 from decorator import decorator |
84 def exotic_signature((x, y)=(1,2)): return x+y |
77 Expecting nothing |
85 Expecting nothing |
78 ok |
86 ok |
79 Trying: |
87 Trying: |
80 print(decorator.__doc__) |
88 print getargspec(exotic_signature) |
81 Expecting: |
89 Expecting: |
82 decorator(caller) converts a caller function into a decorator |
90 ArgSpec(args=[['x', 'y']], varargs=None, keywords=None, defaults=((1, 2),)) |
|
91 ok |
|
92 Trying: |
|
93 exotic_signature() |
|
94 Expecting: |
|
95 calling exotic_signature with args ((1, 2),), {} |
|
96 3 |
|
97 ok |
83 ok |
98 Trying: |
84 Trying: |
99 @decorator |
85 @decorator |
100 def trace(f, *args, **kw): |
86 def trace(f, *args, **kw): |
101 print "calling %s with args %s, %s" % (f.func_name, args, kw) |
87 kwstr = ', '.join('%r: %r' % (k, kw[k]) for k in sorted(kw)) |
|
88 print("calling %s with args %s, {%s}" % (f.__name__, args, kwstr)) |
102 return f(*args, **kw) |
89 return f(*args, **kw) |
103 Expecting nothing |
90 Expecting nothing |
104 ok |
91 ok |
105 Trying: |
92 Trying: |
106 trace # doctest: +ELLIPSIS |
93 trace # doctest: +ELLIPSIS |
123 time.sleep(3) # simulate a blocking resource |
110 time.sleep(3) # simulate a blocking resource |
124 return "some data" |
111 return "some data" |
125 Expecting nothing |
112 Expecting nothing |
126 ok |
113 ok |
127 Trying: |
114 Trying: |
128 print read_data() # data is not available yet |
115 print(read_data()) # data is not available yet |
129 Expecting: |
116 Expecting: |
130 Please wait ... |
117 Please wait ... |
131 ok |
118 ok |
132 Trying: |
119 Trying: |
133 time.sleep(1) |
120 time.sleep(1) |
134 Expecting nothing |
121 Expecting nothing |
135 ok |
122 ok |
136 Trying: |
123 Trying: |
137 print read_data() # data is not available yet |
124 print(read_data()) # data is not available yet |
138 Expecting: |
125 Expecting: |
139 Please wait ... |
126 Please wait ... |
140 ok |
127 ok |
141 Trying: |
128 Trying: |
142 time.sleep(1) |
129 time.sleep(1) |
143 Expecting nothing |
130 Expecting nothing |
144 ok |
131 ok |
145 Trying: |
132 Trying: |
146 print read_data() # data is not available yet |
133 print(read_data()) # data is not available yet |
147 Expecting: |
134 Expecting: |
148 Please wait ... |
135 Please wait ... |
149 ok |
136 ok |
150 Trying: |
137 Trying: |
151 time.sleep(1.1) # after 3.1 seconds, data is available |
138 time.sleep(1.1) # after 3.1 seconds, data is available |
152 Expecting nothing |
139 Expecting nothing |
153 ok |
140 ok |
154 Trying: |
141 Trying: |
155 print read_data() |
142 print(read_data()) |
156 Expecting: |
143 Expecting: |
157 some data |
144 some data |
158 ok |
145 ok |
159 Trying: |
146 Trying: |
160 async = decorator(Async(threading.Thread)) |
147 @decorator(Future) |
161 Expecting nothing |
148 def long_running(x): |
162 ok |
149 time.sleep(.5) |
163 Trying: |
150 return x |
164 datalist = [] # for simplicity the written data are stored into a list. |
151 Expecting nothing |
165 Expecting nothing |
152 ok |
166 ok |
153 Trying: |
167 Trying: |
154 fut1 = long_running(1) |
168 @async |
155 Expecting nothing |
169 def write(data): |
156 ok |
170 # append data to the datalist by locking |
157 Trying: |
171 with threading.Lock(): |
158 fut2 = long_running(2) |
172 time.sleep(1) # emulate some long running operation |
159 Expecting nothing |
173 datalist.append(data) |
160 ok |
174 # other operations not requiring a lock here |
161 Trying: |
175 Expecting nothing |
162 fut1.result() + fut2.result() |
176 ok |
163 Expecting: |
177 Trying: |
164 3 |
178 write("data1") # doctest: +ELLIPSIS |
|
179 Expecting: |
|
180 <Thread(write-1, started...)> |
|
181 ok |
|
182 Trying: |
|
183 time.sleep(.1) # wait a bit, so we are sure data2 is written after data1 |
|
184 Expecting nothing |
|
185 ok |
|
186 Trying: |
|
187 write("data2") # doctest: +ELLIPSIS |
|
188 Expecting: |
|
189 <Thread(write-2, started...)> |
|
190 ok |
|
191 Trying: |
|
192 time.sleep(2) # wait for the writers to complete |
|
193 Expecting nothing |
|
194 ok |
|
195 Trying: |
|
196 print datalist |
|
197 Expecting: |
|
198 ['data1', 'data2'] |
|
199 ok |
165 ok |
200 Trying: |
166 Trying: |
201 from contextlib import contextmanager |
167 from contextlib import contextmanager |
202 Expecting nothing |
168 Expecting nothing |
203 ok |
169 ok |
244 f1 = FunctionMaker.create( |
201 f1 = FunctionMaker.create( |
245 'f1(a, b)', 'f(a, b)', dict(f=f), addsource=True) |
202 'f1(a, b)', 'f(a, b)', dict(f=f), addsource=True) |
246 Expecting nothing |
203 Expecting nothing |
247 ok |
204 ok |
248 Trying: |
205 Trying: |
249 print f1.__source__ |
206 print(f1.__source__) |
250 Expecting: |
207 Expecting: |
251 def f1(a, b): |
208 def f1(a, b): |
252 f(a, b) |
209 f(a, b) |
253 <BLANKLINE> |
210 <BLANKLINE> |
254 ok |
211 ok |
255 Trying: |
212 Trying: |
256 print inspect.getsource(example) |
213 f1 = FunctionMaker.create( |
|
214 'f1(a, b)', 'f(a, b)', dict(f=f), addsource=True, defaults=(None,)) |
|
215 Expecting nothing |
|
216 ok |
|
217 Trying: |
|
218 print(getargspec(f1)) |
|
219 Expecting: |
|
220 ArgSpec(args=['a', 'b'], varargs=None, varkw=None, defaults=(None,)) |
|
221 ok |
|
222 Trying: |
|
223 import inspect |
|
224 Expecting nothing |
|
225 ok |
|
226 Trying: |
|
227 print(inspect.getsource(example)) |
257 Expecting: |
228 Expecting: |
258 def wrapper(*args, **kw): |
229 def wrapper(*args, **kw): |
259 return func(*args, **kw) |
230 return func(*args, **kw) |
260 <BLANKLINE> |
231 <BLANKLINE> |
261 ok |
232 ok |
262 Trying: |
233 Trying: |
263 print inspect.getsource(factorial.__wrapped__) |
234 print(inspect.getsource(factorial.__wrapped__)) |
264 Expecting: |
235 Expecting: |
265 @tail_recursive |
236 @tail_recursive |
266 def factorial(n, acc=1): |
237 def factorial(n, acc=1): |
267 "The good old factorial" |
238 "The good old factorial" |
268 if n == 0: return acc |
239 if n == 0: |
|
240 return acc |
269 return factorial(n-1, n*acc) |
241 return factorial(n-1, n*acc) |
270 <BLANKLINE> |
242 <BLANKLINE> |
271 ok |
243 ok |
272 Trying: |
244 Trying: |
273 print factorial(4) |
245 print(factorial(4)) |
274 Expecting: |
246 Expecting: |
275 24 |
247 24 |
|
248 ok |
|
249 Trying: |
|
250 writer = XMLWriter() |
|
251 Expecting nothing |
|
252 ok |
|
253 Trying: |
|
254 writer.write(2.3) |
|
255 Expecting: |
|
256 '<float>2.3</float>' |
|
257 ok |
|
258 Trying: |
|
259 win(Paper(), Rock()) |
|
260 Expecting: |
|
261 1 |
|
262 ok |
|
263 Trying: |
|
264 win(Scissors(), Paper()) |
|
265 Expecting: |
|
266 1 |
|
267 ok |
|
268 Trying: |
|
269 win(Rock(), Scissors()) |
|
270 Expecting: |
|
271 1 |
|
272 ok |
|
273 Trying: |
|
274 win(Paper(), Paper()) |
|
275 Expecting: |
|
276 0 |
|
277 ok |
|
278 Trying: |
|
279 win(Rock(), Rock()) |
|
280 Expecting: |
|
281 0 |
|
282 ok |
|
283 Trying: |
|
284 win(Scissors(), Scissors()) |
|
285 Expecting: |
|
286 0 |
|
287 ok |
|
288 Trying: |
|
289 win(Rock(), Paper()) |
|
290 Expecting: |
|
291 -1 |
|
292 ok |
|
293 Trying: |
|
294 win(Paper(), Scissors()) |
|
295 Expecting: |
|
296 -1 |
|
297 ok |
|
298 Trying: |
|
299 win(Scissors(), Rock()) |
|
300 Expecting: |
|
301 -1 |
|
302 ok |
|
303 Trying: |
|
304 win(StrongRock(), Scissors()) |
|
305 Expecting: |
|
306 1 |
|
307 ok |
|
308 Trying: |
|
309 win.dispatch_info(StrongRock, Scissors) |
|
310 Expecting: |
|
311 [('StrongRock', 'Scissors'), ('Rock', 'Scissors')] |
|
312 ok |
|
313 Trying: |
|
314 issubclass(WithLength, collections.Sized) |
|
315 Expecting: |
|
316 True |
|
317 ok |
|
318 Trying: |
|
319 get_length(WithLength()) |
|
320 Expecting: |
|
321 0 |
|
322 ok |
|
323 Trying: |
|
324 _ = collections.Set.register(SomeSet) |
|
325 Expecting nothing |
|
326 ok |
|
327 Trying: |
|
328 issubclass(SomeSet, collections.Set) |
|
329 Expecting: |
|
330 True |
|
331 ok |
|
332 Trying: |
|
333 get_length(SomeSet()) # NB: the implementation for Sized would give 0 |
|
334 Expecting: |
|
335 1 |
|
336 ok |
|
337 Trying: |
|
338 g, V = singledispatch_example2() |
|
339 Expecting nothing |
|
340 ok |
|
341 Trying: |
|
342 g.dispatch_info(V) |
|
343 Expecting: |
|
344 [('V',), ('Sized',), ('S',), ('Container',)] |
276 ok |
345 ok |
277 Trying: |
346 Trying: |
278 @trace |
347 @trace |
279 def f(): |
348 def f(): |
280 1/0 |
349 1/0 |
281 Expecting nothing |
350 Expecting nothing |
282 ok |
351 ok |
283 Trying: |
352 Trying: |
284 f() |
353 f() # doctest: +ELLIPSIS |
285 Expecting: |
354 Expecting: |
286 Traceback (most recent call last): |
355 Traceback (most recent call last): |
287 ... |
356 ... |
288 File "<string>", line 2, in f |
357 File "<string>", line 2, in f |
289 File "<doctest __main__[18]>", line 4, in trace |
358 File "<doctest __main__[22]>", line 4, in trace |
290 return f(*args, **kw) |
359 return f(*args, **kw) |
291 File "<doctest __main__[47]>", line 3, in f |
360 File "<doctest __main__[51]>", line 3, in f |
292 1/0 |
361 1/0 |
293 ZeroDivisionError: integer division or modulo by zero |
362 ZeroDivisionError: ... |
294 ok |
363 ok |
295 Trying: |
364 Trying: |
296 class C(object): |
365 @memoize |
297 @trace |
366 def getkeys(**kw): |
298 def meth(self): |
367 return kw.keys() |
299 pass |
368 Expecting nothing |
300 Expecting nothing |
369 ok |
301 ok |
370 Trying: |
302 Trying: |
371 getkeys(func='a') # doctest: +ELLIPSIS |
303 class C(object): |
|
304 def meth(self): |
|
305 pass |
|
306 Expecting nothing |
|
307 ok |
|
308 Trying: |
|
309 trace(C.meth) |
|
310 Expecting: |
372 Expecting: |
311 Traceback (most recent call last): |
373 Traceback (most recent call last): |
312 ... |
374 ... |
313 TypeError: You are decorating a non function: <unbound method C.meth> |
375 TypeError: _memoize() got multiple values for ... 'func' |
314 ok |
|
315 Trying: |
|
316 trace(C.meth.im_func) # doctest: +ELLIPSIS |
|
317 Expecting: |
|
318 <function meth at 0x...> |
|
319 ok |
376 ok |
320 Trying: |
377 Trying: |
321 @trace |
378 @trace |
322 def f(_func_): print f |
379 def f(_func_): print(f) |
323 Expecting: |
380 Expecting: |
324 Traceback (most recent call last): |
381 Traceback (most recent call last): |
325 ... |
382 ... |
326 NameError: _func_ is overridden in |
383 NameError: _func_ is overridden in |
327 def f(_func_): |
384 def f(_func_): |
392 Expecting: |
449 Expecting: |
393 BEFORE |
450 BEFORE |
394 hello michele |
451 hello michele |
395 AFTER |
452 AFTER |
396 ok |
453 ok |
397 31 items had no tests: |
454 52 items had no tests: |
398 __main__.Action.delete |
455 documentation.Action.delete |
399 __main__.Action.insert |
456 documentation.Action.insert |
400 __main__.Action.view |
457 documentation.Action.view |
401 __main__.Admin |
458 documentation.Admin |
402 __main__.Async |
459 documentation.C |
403 __main__.Async.__call__ |
460 documentation.Future |
404 __main__.Async.__init__ |
461 documentation.Future.__init__ |
405 __main__.PermissionError |
462 documentation.Future.result |
406 __main__.PowerUser |
463 documentation.Paper |
407 __main__.TailRecursive |
464 documentation.PermissionError |
408 __main__.TailRecursive.__call__ |
465 documentation.PowerUser |
409 __main__.TailRecursive.__init__ |
466 documentation.Rock |
410 __main__.User |
467 documentation.Scissors |
411 __main__._memoize |
468 documentation.SomeSet |
412 __main__._trace |
469 documentation.SomeSet.__len__ |
413 __main__.before_after |
470 documentation.StrongRock |
414 __main__.blocking |
471 documentation.TailRecursive |
415 __main__.decorator_apply |
472 documentation.TailRecursive.__call__ |
416 __main__.example |
473 documentation.TailRecursive.__init__ |
417 __main__.fact |
474 documentation.User |
418 __main__.factorial |
475 documentation.WithLength |
419 __main__.get_userclass |
476 documentation.WithLength.__len__ |
420 __main__.identity_dec |
477 documentation.XMLWriter |
421 __main__.memoize |
478 documentation.XMLWriter.__init__ |
422 __main__.memoize_uw |
479 documentation.XMLWriter.write |
423 __main__.on_closing |
480 documentation._memoize |
424 __main__.on_failure |
481 documentation._trace |
425 __main__.on_success |
482 documentation.before_after |
426 __main__.restricted |
483 documentation.blocking |
427 __main__.tail_recursive |
484 documentation.decorator_apply |
428 __main__.trace |
485 documentation.example |
|
486 documentation.f1 |
|
487 documentation.fact |
|
488 documentation.factorial |
|
489 documentation.get_length |
|
490 documentation.get_length_set |
|
491 documentation.get_length_sized |
|
492 documentation.get_userclass |
|
493 documentation.identity_dec |
|
494 documentation.memoize |
|
495 documentation.memoize_uw |
|
496 documentation.restricted |
|
497 documentation.singledispatch_example1 |
|
498 documentation.singledispatch_example2 |
|
499 documentation.tail_recursive |
|
500 documentation.trace |
|
501 documentation.win |
|
502 documentation.winPaperScissors |
|
503 documentation.winRockPaper |
|
504 documentation.winRockScissors |
|
505 documentation.winStrongRockPaper |
|
506 documentation.writefloat |
429 4 items passed all tests: |
507 4 items passed all tests: |
430 65 tests in __main__ |
508 78 tests in documentation |
431 3 tests in __main__.Action |
509 3 tests in documentation.Action |
432 2 tests in __main__.a_test_for_pylons |
510 2 tests in documentation.a_test_for_pylons |
433 2 tests in __main__.hello |
511 2 tests in documentation.hello |
434 72 tests in 35 items. |
512 85 teok |
435 72 passed and 0 failed. |
513 test_singledispatch1 (__main__.DocumentationTestCase) ... ok |
|
514 test_singledispatch2 (__main__.DocumentationTestCase) ... ok |
|
515 test_no_first_arg (__main__.ExtraTestCase) ... ok |
|
516 test_qualname (__main__.ExtraTestCase) ... ok |
|
517 test_signature (__main__.ExtraTestCase) ... ok |
|
518 test_unique_filenames (__main__.ExtraTestCase) ... ok |
|
519 test_c_classes (__main__.TestSingleDispatch) ... ok |
|
520 test_mro (__main__.TestSingleDispatch) ... ok |
|
521 test_mro_conflicts (__main__.TestSingleDispatch) ... ok |
|
522 test_register_abc (__main__.TestSingleDispatch) ... ok |
|
523 test_register_decorator (__main__.TestSingleDispatch) ... ok |
|
524 test_register_error (__main__.TestSingleDispatch) ... ok |
|
525 test_simple_overloads (__main__.TestSingleDispatch) ... ok |
|
526 test_wrapping_attributes (__main__.TestSingleDispatch) ... ok |
|
527 |
|
528 ---------------------------------------------------------------------- |
|
529 Ran 15 tests in |
|
530 |
|
531 OK |
|
532 sts in 56 items. |
|
533 85 passed and 0 failed. |
436 Test passed. |
534 Test passed. |