1 Traceback (most recent call last): |
1 test (__main__.DocumentationTestCase) ... ok |
2 File "documentation3.py", line 1155, in <module> |
2 test_singledispatch1 (__main__.DocumentationTestCase) ... ok |
3 ba = before_after('BEFORE', 'AFTER') # ContextManager instance |
3 test_singledispatch2 (__main__.DocumentationTestCase) ... ok |
4 File "<string>", line 2, in before_after |
4 test_no_first_arg (__main__.ExtraTestCase) ... ok |
5 File "/usr/lib/python3.5/contextlib.py", line 38, in __init__ |
5 test_qualname (__main__.ExtraTestCase) ... ok |
6 self.gen = func(*args, **kwds) |
6 test_signature (__main__.ExtraTestCase) ... ok |
7 TypeError: before_after() argument after ** must be a mapping, not str |
7 test_unique_filenames (__main__.ExtraTestCase) ... ok |
|
8 test_c_classes (__main__.TestSingleDispatch) ... ok |
|
9 test_mro (__main__.TestSingleDispatch) ... ok |
|
10 test_mro_conflicts (__main__.TestSingleDispatch) ... ok |
|
11 test_register_abc (__main__.TestSingleDispatch) ... ok |
|
12 test_register_decorator (__main__.TestSingleDispatch) ... ok |
|
13 test_register_error (__main__.TestSingleDispatch) ... ok |
|
14 test_simple_overloads (__main__.TestSingleDispatch) ... ok |
|
15 test_wrapping_attributes (__main__.TestSingleDispatch) ... ok |
|
16 |
|
17 ---------------------------------------------------------------------- |
|
18 Ran 15 tests in |
|
19 |
|
20 OK |
|
21 Trying: |
|
22 from decorator import getargspec # akin to inspect.getargspec |
|
23 Expecting nothing |
|
24 ok |
|
25 Trying: |
|
26 print(getargspec(f1)) |
|
27 Expecting: |
|
28 ArgSpec(args=[], varargs='args', varkw='kw', defaults=None) |
|
29 ok |
|
30 Trying: |
|
31 f1(0, 1) # doctest: +IGNORE_EXCEPTION_DETAIL |
|
32 Expecting: |
|
33 Traceback (most recent call last): |
|
34 ... |
|
35 TypeError: f1() takes exactly 1 positional argument (2 given) |
|
36 ok |
|
37 Trying: |
|
38 from decorator import decorate |
|
39 Expecting nothing |
|
40 ok |
|
41 Trying: |
|
42 @memoize |
|
43 def heavy_computation(): |
|
44 time.sleep(2) |
|
45 return "done" |
|
46 Expecting nothing |
|
47 ok |
|
48 Trying: |
|
49 print(heavy_computation()) # the first time it will take 2 seconds |
|
50 Expecting: |
|
51 done |
|
52 ok |
|
53 Trying: |
|
54 print(heavy_computation()) # the second time it will be instantaneous |
|
55 Expecting: |
|
56 done |
|
57 ok |
|
58 Trying: |
|
59 print(getargspec(heavy_computation)) |
|
60 Expecting: |
|
61 ArgSpec(args=[], varargs=None, varkw=None, defaults=None) |
|
62 ok |
|
63 Trying: |
|
64 @trace |
|
65 def f1(x): |
|
66 pass |
|
67 Expecting nothing |
|
68 ok |
|
69 Trying: |
|
70 f1(0) |
|
71 Expecting: |
|
72 calling f1 with args (0,), {} |
|
73 ok |
|
74 Trying: |
|
75 print(getargspec(f1)) |
|
76 Expecting: |
|
77 ArgSpec(args=['x'], varargs=None, varkw=None, defaults=None) |
|
78 ok |
|
79 Trying: |
|
80 @trace |
|
81 def f(x, y=1, z=2, *args, **kw): |
|
82 pass |
|
83 Expecting nothing |
|
84 ok |
|
85 Trying: |
|
86 f(0, 3) |
|
87 Expecting: |
|
88 calling f with args (0, 3, 2), {} |
|
89 ok |
|
90 Trying: |
|
91 print(getargspec(f)) |
|
92 Expecting: |
|
93 ArgSpec(args=['x', 'y', 'z'], varargs='args', varkw='kw', defaults=(1, 2)) |
|
94 ok |
|
95 Trying: |
|
96 @trace |
|
97 def f(x: 'the first argument', y: 'default argument'=1, z=2, |
|
98 *args: 'varargs', **kw: 'kwargs'): |
|
99 pass |
|
100 Expecting nothing |
|
101 ok |
|
102 Trying: |
|
103 from inspect import getfullargspec |
|
104 Expecting nothing |
|
105 ok |
|
106 Trying: |
|
107 argspec = getfullargspec(f) |
|
108 Expecting nothing |
|
109 ok |
|
110 Trying: |
|
111 argspec.args |
|
112 Expecting: |
|
113 ['x', 'y', 'z'] |
|
114 ok |
|
115 Trying: |
|
116 argspec.varargs |
|
117 Expecting: |
|
118 'args' |
|
119 ok |
|
120 Trying: |
|
121 argspec.varkw |
|
122 Expecting: |
|
123 'kw' |
|
124 ok |
|
125 Trying: |
|
126 argspec.defaults |
|
127 Expecting: |
|
128 (1, 2) |
|
129 ok |
|
130 Trying: |
|
131 argspec.kwonlyargs |
|
132 Expecting: |
|
133 [] |
|
134 ok |
|
135 Trying: |
|
136 argspec.kwonlydefaults |
|
137 Expecting nothing |
|
138 ok |
|
139 Trying: |
|
140 f.__annotations__ is f.__wrapped__.__annotations__ |
|
141 Expecting: |
|
142 True |
|
143 ok |
|
144 Trying: |
|
145 from decorator import decorator |
|
146 Expecting nothing |
|
147 ok |
|
148 Trying: |
|
149 print(decorator.__doc__) |
|
150 Expecting: |
|
151 decorator(caller) converts a caller function into a decorator |
|
152 ok |
|
153 Trying: |
|
154 @decorator |
|
155 def trace(f, *args, **kw): |
|
156 kwstr = ', '.join('%r: %r' % (k, kw[k]) for k in sorted(kw)) |
|
157 print("calling %s with args %s, {%s}" % (f.__name__, args, kwstr)) |
|
158 return f(*args, **kw) |
|
159 Expecting nothing |
|
160 ok |
|
161 Trying: |
|
162 trace # doctest: +ELLIPSIS |
|
163 Expecting: |
|
164 <function trace at 0x...> |
|
165 ok |
|
166 Trying: |
|
167 @trace |
|
168 def func(): pass |
|
169 Expecting nothing |
|
170 ok |
|
171 Trying: |
|
172 func() |
|
173 Expecting: |
|
174 calling func with args (), {} |
|
175 ok |
|
176 Trying: |
|
177 @blocking("Please wait ...") |
|
178 def read_data(): |
|
179 time.sleep(3) # simulate a blocking resource |
|
180 return "some data" |
|
181 Expecting nothing |
|
182 ok |
|
183 Trying: |
|
184 print(read_data()) # data is not available yet |
|
185 Expecting: |
|
186 Please wait ... |
|
187 ok |
|
188 Trying: |
|
189 time.sleep(1) |
|
190 Expecting nothing |
|
191 ok |
|
192 Trying: |
|
193 print(read_data()) # data is not available yet |
|
194 Expecting: |
|
195 Please wait ... |
|
196 ok |
|
197 Trying: |
|
198 time.sleep(1) |
|
199 Expecting nothing |
|
200 ok |
|
201 Trying: |
|
202 print(read_data()) # data is not available yet |
|
203 Expecting: |
|
204 Please wait ... |
|
205 ok |
|
206 Trying: |
|
207 time.sleep(1.1) # after 3.1 seconds, data is available |
|
208 Expecting nothing |
|
209 ok |
|
210 Trying: |
|
211 print(read_data()) |
|
212 Expecting: |
|
213 some data |
|
214 ok |
|
215 Trying: |
|
216 @decorator(Future) |
|
217 def long_running(x): |
|
218 time.sleep(.5) |
|
219 return x |
|
220 Expecting nothing |
|
221 ok |
|
222 Trying: |
|
223 fut1 = long_running(1) |
|
224 Expecting nothing |
|
225 ok |
|
226 Trying: |
|
227 fut2 = long_running(2) |
|
228 Expecting nothing |
|
229 ok |
|
230 Trying: |
|
231 fut1.result() + fut2.result() |
|
232 Expecting: |
|
233 3 |
|
234 ok |
|
235 Trying: |
|
236 from contextlib import contextmanager |
|
237 Expecting nothing |
|
238 ok |
|
239 Trying: |
|
240 @contextmanager |
|
241 def before_after(before, after): |
|
242 print(before) |
|
243 yield |
|
244 print(after) |
|
245 Expecting nothing |
|
246 ok |
|
247 Trying: |
|
248 with before_after('BEFORE', 'AFTER'): |
|
249 print('hello') |
|
250 Expecting: |
|
251 BEFORE |
|
252 hello |
|
253 AFTER |
|
254 ok |
|
255 Trying: |
|
256 def f(*args, **kw): # a function with a generic signature |
|
257 print(args, kw) |
|
258 Expecting nothing |
|
259 ok |
|
260 Trying: |
|
261 f1 = FunctionMaker.create('f1(a, b)', 'f(a, b)', dict(f=f)) |
|
262 Expecting nothing |
|
263 ok |
|
264 Trying: |
|
265 f1(1,2) |
|
266 Expecting: |
|
267 (1, 2) {} |
|
268 ok |
|
269 Trying: |
|
270 f1 = FunctionMaker.create( |
|
271 'f1(a, b)', 'f(a, b)', dict(f=f), addsource=True) |
|
272 Expecting nothing |
|
273 ok |
|
274 Trying: |
|
275 print(f1.__source__) |
|
276 Expecting: |
|
277 def f1(a, b): |
|
278 f(a, b) |
|
279 <BLANKLINE> |
|
280 ok |
|
281 Trying: |
|
282 f1 = FunctionMaker.create( |
|
283 'f1(a, b)', 'f(a, b)', dict(f=f), addsource=True, defaults=(None,)) |
|
284 Expecting nothing |
|
285 ok |
|
286 Trying: |
|
287 print(getargspec(f1)) |
|
288 Expecting: |
|
289 ArgSpec(args=['a', 'b'], varargs=None, varkw=None, defaults=(None,)) |
|
290 ok |
|
291 Trying: |
|
292 import inspect |
|
293 Expecting nothing |
|
294 ok |
|
295 Trying: |
|
296 print(inspect.getsource(example)) |
|
297 Expecting: |
|
298 def wrapper(*args, **kw): |
|
299 return func(*args, **kw) |
|
300 <BLANKLINE> |
|
301 ok |
|
302 Trying: |
|
303 print(inspect.getsource(factorial.__wrapped__)) |
|
304 Expecting: |
|
305 @tail_recursive |
|
306 def factorial(n, acc=1): |
|
307 "The good old factorial" |
|
308 if n == 0: |
|
309 return acc |
|
310 return factorial(n-1, n*acc) |
|
311 <BLANKLINE> |
|
312 ok |
|
313 Trying: |
|
314 print(factorial(4)) |
|
315 Expecting: |
|
316 24 |
|
317 ok |
|
318 Trying: |
|
319 writer = XMLWriter() |
|
320 Expecting nothing |
|
321 ok |
|
322 Trying: |
|
323 writer.write(2.3) |
|
324 Expecting: |
|
325 '<float>2.3</float>' |
|
326 ok |
|
327 Trying: |
|
328 win(Paper(), Rock()) |
|
329 Expecting: |
|
330 1 |
|
331 ok |
|
332 Trying: |
|
333 win(Scissors(), Paper()) |
|
334 Expecting: |
|
335 1 |
|
336 ok |
|
337 Trying: |
|
338 win(Rock(), Scissors()) |
|
339 Expecting: |
|
340 1 |
|
341 ok |
|
342 Trying: |
|
343 win(Paper(), Paper()) |
|
344 Expecting: |
|
345 0 |
|
346 ok |
|
347 Trying: |
|
348 win(Rock(), Rock()) |
|
349 Expecting: |
|
350 0 |
|
351 ok |
|
352 Trying: |
|
353 win(Scissors(), Scissors()) |
|
354 Expecting: |
|
355 0 |
|
356 ok |
|
357 Trying: |
|
358 win(Rock(), Paper()) |
|
359 Expecting: |
|
360 -1 |
|
361 ok |
|
362 Trying: |
|
363 win(Paper(), Scissors()) |
|
364 Expecting: |
|
365 -1 |
|
366 ok |
|
367 Trying: |
|
368 win(Scissors(), Rock()) |
|
369 Expecting: |
|
370 -1 |
|
371 ok |
|
372 Trying: |
|
373 win(StrongRock(), Scissors()) |
|
374 Expecting: |
|
375 1 |
|
376 ok |
|
377 Trying: |
|
378 win.dispatch_info(StrongRock, Scissors) |
|
379 Expecting: |
|
380 [('StrongRock', 'Scissors'), ('Rock', 'Scissors')] |
|
381 ok |
|
382 Trying: |
|
383 issubclass(WithLength, collections.Sized) |
|
384 Expecting: |
|
385 True |
|
386 ok |
|
387 Trying: |
|
388 get_length(WithLength()) |
|
389 Expecting: |
|
390 0 |
|
391 ok |
|
392 Trying: |
|
393 _ = collections.Set.register(SomeSet) |
|
394 Expecting nothing |
|
395 ok |
|
396 Trying: |
|
397 issubclass(SomeSet, collections.Set) |
|
398 Expecting: |
|
399 True |
|
400 ok |
|
401 Trying: |
|
402 get_length(SomeSet()) # NB: the implementation for Sized would give 0 |
|
403 Expecting: |
|
404 1 |
|
405 ok |
|
406 Trying: |
|
407 g, V = singledispatch_example2() |
|
408 Expecting nothing |
|
409 ok |
|
410 Trying: |
|
411 g.dispatch_info(V) |
|
412 Expecting: |
|
413 [('V',), ('Sized',), ('S',), ('Container',)] |
|
414 ok |
|
415 Trying: |
|
416 @trace |
|
417 def f(): |
|
418 1/0 |
|
419 Expecting nothing |
|
420 ok |
|
421 Trying: |
|
422 f() # doctest: +ELLIPSIS |
|
423 Expecting: |
|
424 Traceback (most recent call last): |
|
425 ... |
|
426 File "<string>", line 2, in f |
|
427 File "<doctest __main__[22]>", line 4, in trace |
|
428 return f(*args, **kw) |
|
429 File "<doctest __main__[51]>", line 3, in f |
|
430 1/0 |
|
431 ZeroDivisionError: ... |
|
432 ok |
|
433 Trying: |
|
434 @memoize |
|
435 def getkeys(**kw): |
|
436 return kw.keys() |
|
437 Expecting nothing |
|
438 ok |
|
439 Trying: |
|
440 getkeys(func='a') # doctest: +ELLIPSIS |
|
441 Expecting: |
|
442 Traceback (most recent call last): |
|
443 ... |
|
444 TypeError: _memoize() got multiple values for ... 'func' |
|
445 ok |
|
446 Trying: |
|
447 @trace |
|
448 def f(_func_): print(f) |
|
449 Expecting: |
|
450 Traceback (most recent call last): |
|
451 ... |
|
452 NameError: _func_ is overridden in |
|
453 def f(_func_): |
|
454 return _call_(_func_, _func_) |
|
455 ok |
|
456 Trying: |
|
457 def f(): pass # the original function |
|
458 Expecting nothing |
|
459 ok |
|
460 Trying: |
|
461 f.attr1 = "something" # setting an attribute |
|
462 Expecting nothing |
|
463 ok |
|
464 Trying: |
|
465 f.attr2 = "something else" # setting another attribute |
|
466 Expecting nothing |
|
467 ok |
|
468 Trying: |
|
469 traced_f = trace(f) # the decorated function |
|
470 Expecting nothing |
|
471 ok |
|
472 Trying: |
|
473 traced_f.attr1 |
|
474 Expecting: |
|
475 'something' |
|
476 ok |
|
477 Trying: |
|
478 traced_f.attr2 = "something different" # setting attr |
|
479 Expecting nothing |
|
480 ok |
|
481 Trying: |
|
482 f.attr2 # the original attribute did not change |
|
483 Expecting: |
|
484 'something else' |
|
485 ok |
|
486 Trying: |
|
487 a = Action() |
|
488 Expecting nothing |
|
489 ok |
|
490 Trying: |
|
491 a.view() # ok |
|
492 Expecting nothing |
|
493 ok |
|
494 Trying: |
|
495 a.insert() # doctest: +IGNORE_EXCEPTION_DETAIL |
|
496 Expecting: |
|
497 Traceback (most recent call last): |
|
498 ... |
|
499 PermissionError: User does not have the permission to run insert! |
|
500 ok |
|
501 Trying: |
|
502 decorator(_memoize).__name__ |
|
503 Expecting: |
|
504 '_memoize' |
|
505 ok |
|
506 Trying: |
|
507 factorial.__doc__ |
|
508 Expecting: |
|
509 'The good old factorial' |
|
510 ok |
|
511 Trying: |
|
512 ba.__class__.__name__ |
|
513 Expecting: |
|
514 'ContextManager' |
|
515 ok |
|
516 Trying: |
|
517 hello('michele') |
|
518 Expecting: |
|
519 BEFORE |
|
520 hello michele |
|
521 AFTER |
|
522 ok |
|
523 Trying: |
|
524 @trace |
|
525 def f(**kw): pass |
|
526 Expecting nothing |
|
527 ok |
|
528 Trying: |
|
529 f() |
|
530 Expecting: |
|
531 calling f with args (), {} |
|
532 ok |
|
533 Trying: |
|
534 @trace |
|
535 def f(*, a=1, **kw): pass |
|
536 Expecting nothing |
|
537 ok |
|
538 Trying: |
|
539 import inspect |
|
540 Expecting nothing |
|
541 ok |
|
542 Trying: |
|
543 inspect.getfullargspec(f) |
|
544 Expecting: |
|
545 FullArgSpec(args=[], varargs=None, varkw='kw', defaults=None, kwonlyargs=['a'], kwonlydefaults={'a': 1}, annotations={}) |
|
546 ok |
|
547 Trying: |
|
548 @trace |
|
549 def func(a, b, *args, y=2, z=3, **kwargs): |
|
550 return y, z |
|
551 Expecting nothing |
|
552 ok |
|
553 Trying: |
|
554 func('a', 'b', 'c', 'd', 'e', y='y', z='z', cat='dog') |
|
555 Expecting: |
|
556 calling func with args ('a', 'b', 'c', 'd', 'e'), {'cat': 'dog', 'y': 'y', 'z': 'z'} |
|
557 ('y', 'z') |
|
558 ok |
|
559 Trying: |
|
560 @trace |
|
561 def f(arg, defarg=1, *args, kwonly=2): pass |
|
562 Expecting nothing |
|
563 ok |
|
564 Trying: |
|
565 f.__kwdefaults__ |
|
566 Expecting: |
|
567 {'kwonly': 2} |
|
568 ok |
|
569 52 items had no tests: |
|
570 documentation.Action.delete |
|
571 documentation.Action.insert |
|
572 documentation.Action.view |
|
573 documentation.Admin |
|
574 documentation.C |
|
575 documentation.Future |
|
576 documentation.Future.__init__ |
|
577 documentation.Future.result |
|
578 documentation.Paper |
|
579 documentation.PermissionError |
|
580 documentation.PowerUser |
|
581 documentation.Rock |
|
582 documentation.Scissors |
|
583 documentation.SomeSet |
|
584 documentation.SomeSet.__len__ |
|
585 documentation.StrongRock |
|
586 documentation.TailRecursive |
|
587 documentation.TailRecursive.__call__ |
|
588 documentation.TailRecursive.__init__ |
|
589 documentation.User |
|
590 documentation.WithLength |
|
591 documentation.WithLength.__len__ |
|
592 documentation.XMLWriter |
|
593 documentation.XMLWriter.__init__ |
|
594 documentation.XMLWriter.write |
|
595 documentation._memoize |
|
596 documentation._trace |
|
597 documentation.before_after |
|
598 documentation.blocking |
|
599 documentation.decorator_apply |
|
600 documentation.example |
|
601 documentation.f1 |
|
602 documentation.fact |
|
603 documentation.factorial |
|
604 documentation.get_length |
|
605 documentation.get_length_set |
|
606 documentation.get_length_sized |
|
607 documentation.get_userclass |
|
608 documentation.identity_dec |
|
609 documentation.memoize |
|
610 documentation.memoize_uw |
|
611 documentation.restricted |
|
612 documentation.singledispatch_example1 |
|
613 documentation.singledispatch_example2 |
|
614 documentation.tail_recursive |
|
615 documentation.trace |
|
616 documentation.win |
|
617 documentation.winPaperScissors |
|
618 documentation.winRockPaper |
|
619 documentation.winRockScissors |
|
620 documentation.winStrongRockPaper |
|
621 documentation.writefloat |
|
622 8 items passed all tests: |
|
623 88 tests in documentation |
|
624 3 tests in documentation.Action |
|
625 2 tests in documentation.a_test_for_pylons |
|
626 2 tests in documentation.hello |
|
627 2 tests in documentation.test_kwonly_no_args |
|
628 3 tests in documentation.test_kwonly_star_notation |
|
629 2 tests in documentation.test_kwonlyargs |
|
630 2 tests in documentation.test_kwonlydefaults |
|
631 104 tests in 60 items. |
|
632 104 passed and 0 failed. |
|
633 Test passed. |