6932N/Atest (__main__.DocumentationTestCase) ... Trying:
6932N/A from decorator import getargspec # akin to inspect.getargspec
3840N/AExpecting nothing
3840N/Aok
3840N/ATrying:
6932N/A print(getargspec(f1))
3840N/AExpecting:
6932N/A ArgSpec(args=[], varargs='args', varkw='kw', defaults=None)
3840N/Aok
3840N/ATrying:
6932N/A f1(0, 1) # doctest: +IGNORE_EXCEPTION_DETAIL
3840N/AExpecting:
3840N/A Traceback (most recent call last):
3840N/A ...
6932N/A TypeError: f1() takes exactly 1 positional argument (2 given)
3840N/Aok
3840N/ATrying:
6932N/A from decorator import decorate
3840N/AExpecting nothing
3840N/Aok
3840N/ATrying:
3840N/A @memoize
3840N/A def heavy_computation():
3840N/A time.sleep(2)
3840N/A return "done"
3840N/AExpecting nothing
3840N/Aok
3840N/ATrying:
6932N/A print(heavy_computation()) # the first time it will take 2 seconds
3840N/AExpecting:
3840N/A done
3840N/Aok
3840N/ATrying:
6932N/A print(heavy_computation()) # the second time it will be instantaneous
3840N/AExpecting:
3840N/A done
3840N/Aok
3840N/ATrying:
6932N/A print(getargspec(heavy_computation))
3840N/AExpecting:
6932N/A ArgSpec(args=[], varargs=None, varkw=None, defaults=None)
3840N/Aok
3840N/ATrying:
3840N/A @trace
3840N/A def f1(x):
3840N/A pass
3840N/AExpecting nothing
3840N/Aok
3840N/ATrying:
3840N/A f1(0)
3840N/AExpecting:
3840N/A calling f1 with args (0,), {}
3840N/Aok
3840N/ATrying:
6932N/A print(getargspec(f1))
3840N/AExpecting:
6932N/A ArgSpec(args=['x'], varargs=None, varkw=None, defaults=None)
3840N/Aok
3840N/ATrying:
3840N/A @trace
3840N/A def f(x, y=1, z=2, *args, **kw):
3840N/A pass
3840N/AExpecting nothing
3840N/Aok
3840N/ATrying:
3840N/A f(0, 3)
3840N/AExpecting:
3840N/A calling f with args (0, 3, 2), {}
3840N/Aok
3840N/ATrying:
6932N/A print(getargspec(f))
3840N/AExpecting:
6932N/A ArgSpec(args=['x', 'y', 'z'], varargs='args', varkw='kw', defaults=(1, 2))
3840N/Aok
3840N/ATrying:
6932N/A from decorator import decorator
3840N/AExpecting nothing
3840N/Aok
3840N/ATrying:
6932N/A print(decorator.__doc__)
3840N/AExpecting:
6932N/A decorator(caller) converts a caller function into a decorator
3840N/Aok
3840N/ATrying:
3840N/A @decorator
3840N/A def trace(f, *args, **kw):
6932N/A kwstr = ', '.join('%r: %r' % (k, kw[k]) for k in sorted(kw))
6932N/A print("calling %s with args %s, {%s}" % (f.__name__, args, kwstr))
3840N/A return f(*args, **kw)
3840N/AExpecting nothing
3840N/Aok
3840N/ATrying:
3840N/A trace # doctest: +ELLIPSIS
3840N/AExpecting:
3840N/A <function trace at 0x...>
3840N/Aok
3840N/ATrying:
3840N/A @trace
3840N/A def func(): pass
3840N/AExpecting nothing
3840N/Aok
3840N/ATrying:
3840N/A func()
3840N/AExpecting:
3840N/A calling func with args (), {}
3840N/Aok
3840N/ATrying:
3840N/A @blocking("Please wait ...")
3840N/A def read_data():
3840N/A time.sleep(3) # simulate a blocking resource
3840N/A return "some data"
3840N/AExpecting nothing
3840N/Aok
3840N/ATrying:
6932N/A print(read_data()) # data is not available yet
3840N/AExpecting:
3840N/A Please wait ...
3840N/Aok
3840N/ATrying:
6932N/A time.sleep(1)
3840N/AExpecting nothing
3840N/Aok
3840N/ATrying:
6932N/A print(read_data()) # data is not available yet
3840N/AExpecting:
3840N/A Please wait ...
3840N/Aok
3840N/ATrying:
3840N/A time.sleep(1)
3840N/AExpecting nothing
3840N/Aok
3840N/ATrying:
6932N/A print(read_data()) # data is not available yet
3840N/AExpecting:
3840N/A Please wait ...
3840N/Aok
3840N/ATrying:
6932N/A time.sleep(1.1) # after 3.1 seconds, data is available
3840N/AExpecting nothing
3840N/Aok
3840N/ATrying:
6932N/A print(read_data())
3840N/AExpecting:
3840N/A some data
3840N/Aok
3840N/ATrying:
6932N/A @decorator(Future)
6932N/A def long_running(x):
6932N/A time.sleep(.5)
6932N/A return x
3840N/AExpecting nothing
3840N/Aok
3840N/ATrying:
6932N/A fut1 = long_running(1)
3840N/AExpecting nothing
3840N/Aok
3840N/ATrying:
6932N/A fut2 = long_running(2)
3840N/AExpecting nothing
3840N/Aok
3840N/ATrying:
6932N/A fut1.result() + fut2.result()
3840N/AExpecting:
6932N/A 3
3840N/Aok
3840N/ATrying:
3840N/A from contextlib import contextmanager
3840N/AExpecting nothing
3840N/Aok
3840N/ATrying:
3840N/A @contextmanager
3840N/A def before_after(before, after):
3840N/A print(before)
3840N/A yield
3840N/A print(after)
3840N/AExpecting nothing
3840N/Aok
3840N/ATrying:
6932N/A with before_after('BEFORE', 'AFTER'):
6932N/A print('hello')
3840N/AExpecting:
3840N/A BEFORE
3840N/A hello
3840N/A AFTER
3840N/Aok
3840N/ATrying:
3840N/A def f(*args, **kw): # a function with a generic signature
6932N/A print(args, kw)
3840N/AExpecting nothing
3840N/Aok
3840N/ATrying:
3840N/A f1 = FunctionMaker.create('f1(a, b)', 'f(a, b)', dict(f=f))
3840N/AExpecting nothing
3840N/Aok
3840N/ATrying:
3840N/A f1(1,2)
3840N/AExpecting:
3840N/A (1, 2) {}
3840N/Aok
3840N/ATrying:
3840N/A f1 = FunctionMaker.create(
3840N/A 'f1(a, b)', 'f(a, b)', dict(f=f), addsource=True)
3840N/AExpecting nothing
3840N/Aok
3840N/ATrying:
6932N/A print(f1.__source__)
3840N/AExpecting:
3840N/A def f1(a, b):
3840N/A f(a, b)
3840N/A <BLANKLINE>
3840N/Aok
3840N/ATrying:
6932N/A f1 = FunctionMaker.create(
6932N/A 'f1(a, b)', 'f(a, b)', dict(f=f), addsource=True, defaults=(None,))
6932N/AExpecting nothing
6932N/Aok
6932N/ATrying:
6932N/A print(getargspec(f1))
6932N/AExpecting:
6932N/A ArgSpec(args=['a', 'b'], varargs=None, varkw=None, defaults=(None,))
6932N/Aok
6932N/ATrying:
6932N/A import inspect
6932N/AExpecting nothing
6932N/Aok
6932N/ATrying:
6932N/A print(inspect.getsource(example))
3840N/AExpecting:
3840N/A def wrapper(*args, **kw):
3840N/A return func(*args, **kw)
3840N/A <BLANKLINE>
3840N/Aok
3840N/ATrying:
6932N/A print(inspect.getsource(factorial.__wrapped__))
3840N/AExpecting:
3840N/A @tail_recursive
3840N/A def factorial(n, acc=1):
3840N/A "The good old factorial"
6932N/A if n == 0:
6932N/A return acc
3840N/A return factorial(n-1, n*acc)
3840N/A <BLANKLINE>
3840N/Aok
3840N/ATrying:
6932N/A print(factorial(4))
3840N/AExpecting:
3840N/A 24
3840N/Aok
3840N/ATrying:
6932N/A writer = XMLWriter()
6932N/AExpecting nothing
6932N/Aok
6932N/ATrying:
6932N/A writer.write(2.3)
6932N/AExpecting:
6932N/A '<float>2.3</float>'
6932N/Aok
6932N/ATrying:
6932N/A win(Paper(), Rock())
6932N/AExpecting:
6932N/A 1
6932N/Aok
6932N/ATrying:
6932N/A win(Scissors(), Paper())
6932N/AExpecting:
6932N/A 1
6932N/Aok
6932N/ATrying:
6932N/A win(Rock(), Scissors())
6932N/AExpecting:
6932N/A 1
6932N/Aok
6932N/ATrying:
6932N/A win(Paper(), Paper())
6932N/AExpecting:
6932N/A 0
6932N/Aok
6932N/ATrying:
6932N/A win(Rock(), Rock())
6932N/AExpecting:
6932N/A 0
6932N/Aok
6932N/ATrying:
6932N/A win(Scissors(), Scissors())
6932N/AExpecting:
6932N/A 0
6932N/Aok
6932N/ATrying:
6932N/A win(Rock(), Paper())
6932N/AExpecting:
6932N/A -1
6932N/Aok
6932N/ATrying:
6932N/A win(Paper(), Scissors())
6932N/AExpecting:
6932N/A -1
6932N/Aok
6932N/ATrying:
6932N/A win(Scissors(), Rock())
6932N/AExpecting:
6932N/A -1
6932N/Aok
6932N/ATrying:
6932N/A win(StrongRock(), Scissors())
6932N/AExpecting:
6932N/A 1
6932N/Aok
6932N/ATrying:
6932N/A win.dispatch_info(StrongRock, Scissors)
6932N/AExpecting:
6932N/A [('StrongRock', 'Scissors'), ('Rock', 'Scissors')]
6932N/Aok
6932N/ATrying:
6932N/A issubclass(WithLength, collections.Sized)
6932N/AExpecting:
6932N/A True
6932N/Aok
6932N/ATrying:
6932N/A get_length(WithLength())
6932N/AExpecting:
6932N/A 0
6932N/Aok
6932N/ATrying:
6932N/A _ = collections.Set.register(SomeSet)
6932N/AExpecting nothing
6932N/Aok
6932N/ATrying:
6932N/A issubclass(SomeSet, collections.Set)
6932N/AExpecting:
6932N/A True
6932N/Aok
6932N/ATrying:
6932N/A get_length(SomeSet()) # NB: the implementation for Sized would give 0
6932N/AExpecting:
6932N/A 1
6932N/Aok
6932N/ATrying:
6932N/A g, V = singledispatch_example2()
6932N/AExpecting nothing
6932N/Aok
6932N/ATrying:
6932N/A g.dispatch_info(V)
6932N/AExpecting:
6932N/A [('V',), ('Sized',), ('S',), ('Container',)]
6932N/Aok
6932N/ATrying:
3840N/A @trace
3840N/A def f():
3840N/A 1/0
3840N/AExpecting nothing
3840N/Aok
3840N/ATrying:
6932N/A f() # doctest: +ELLIPSIS
3840N/AExpecting:
3840N/A Traceback (most recent call last):
3840N/A ...
3840N/A File "<string>", line 2, in f
6932N/A File "<doctest __main__[22]>", line 4, in trace
3840N/A return f(*args, **kw)
6932N/A File "<doctest __main__[51]>", line 3, in f
3840N/A 1/0
6932N/A ZeroDivisionError: ...
3840N/Aok
3840N/ATrying:
6932N/A @memoize
6932N/A def getkeys(**kw):
6932N/A return kw.keys()
3840N/AExpecting nothing
3840N/Aok
3840N/ATrying:
6932N/A getkeys(func='a') # doctest: +ELLIPSIS
3840N/AExpecting:
3840N/A Traceback (most recent call last):
6932N/A ...
6932N/A TypeError: _memoize() got multiple values for ... 'func'
3840N/Aok
3840N/ATrying:
3840N/A @trace
6932N/A def f(_func_): print(f)
3840N/AExpecting:
3840N/A Traceback (most recent call last):
3840N/A ...
3840N/A NameError: _func_ is overridden in
3840N/A def f(_func_):
3840N/A return _call_(_func_, _func_)
3840N/Aok
3840N/ATrying:
3840N/A def f(): pass # the original function
3840N/AExpecting nothing
3840N/Aok
3840N/ATrying:
3840N/A f.attr1 = "something" # setting an attribute
3840N/AExpecting nothing
3840N/Aok
3840N/ATrying:
3840N/A f.attr2 = "something else" # setting another attribute
3840N/AExpecting nothing
3840N/Aok
3840N/ATrying:
3840N/A traced_f = trace(f) # the decorated function
3840N/AExpecting nothing
3840N/Aok
3840N/ATrying:
3840N/A traced_f.attr1
3840N/AExpecting:
3840N/A 'something'
3840N/Aok
3840N/ATrying:
3840N/A traced_f.attr2 = "something different" # setting attr
3840N/AExpecting nothing
3840N/Aok
3840N/ATrying:
3840N/A f.attr2 # the original attribute did not change
3840N/AExpecting:
3840N/A 'something else'
3840N/Aok
3840N/ATrying:
3840N/A a = Action()
3840N/AExpecting nothing
3840N/Aok
3840N/ATrying:
3840N/A a.view() # ok
3840N/AExpecting nothing
3840N/Aok
3840N/ATrying:
6932N/A a.insert() # doctest: +IGNORE_EXCEPTION_DETAIL
3840N/AExpecting:
3840N/A Traceback (most recent call last):
3840N/A ...
3840N/A PermissionError: User does not have the permission to run insert!
3840N/Aok
3840N/ATrying:
3840N/A decorator(_memoize).__name__
3840N/AExpecting:
3840N/A '_memoize'
3840N/Aok
3840N/ATrying:
3840N/A factorial.__doc__
3840N/AExpecting:
3840N/A 'The good old factorial'
3840N/Aok
3840N/ATrying:
3840N/A ba.__class__.__name__
3840N/AExpecting:
3840N/A 'ContextManager'
3840N/Aok
3840N/ATrying:
3840N/A hello('michele')
3840N/AExpecting:
3840N/A BEFORE
3840N/A hello michele
3840N/A AFTER
3840N/Aok
6932N/A52 items had no tests:
6932N/A documentation.Action.delete
6932N/A documentation.Action.insert
6932N/A documentation.Action.view
6932N/A documentation.Admin
6932N/A documentation.C
6932N/A documentation.Future
6932N/A documentation.Future.__init__
6932N/A documentation.Future.result
6932N/A documentation.Paper
6932N/A documentation.PermissionError
6932N/A documentation.PowerUser
6932N/A documentation.Rock
6932N/A documentation.Scissors
6932N/A documentation.SomeSet
6932N/A documentation.SomeSet.__len__
6932N/A documentation.StrongRock
6932N/A documentation.TailRecursive
6932N/A documentation.TailRecursive.__call__
6932N/A documentation.TailRecursive.__init__
6932N/A documentation.User
6932N/A documentation.WithLength
6932N/A documentation.WithLength.__len__
6932N/A documentation.XMLWriter
6932N/A documentation.XMLWriter.__init__
6932N/A documentation.XMLWriter.write
6932N/A documentation._memoize
6932N/A documentation._trace
6932N/A documentation.before_after
6932N/A documentation.blocking
6932N/A documentation.decorator_apply
6932N/A documentation.example
6932N/A documentation.f1
6932N/A documentation.fact
6932N/A documentation.factorial
6932N/A documentation.get_length
6932N/A documentation.get_length_set
6932N/A documentation.get_length_sized
6932N/A documentation.get_userclass
6932N/A documentation.identity_dec
6932N/A documentation.memoize
6932N/A documentation.memoize_uw
6932N/A documentation.restricted
6932N/A documentation.singledispatch_example1
6932N/A documentation.singledispatch_example2
6932N/A documentation.tail_recursive
6932N/A documentation.trace
6932N/A documentation.win
6932N/A documentation.winPaperScissors
6932N/A documentation.winRockPaper
6932N/A documentation.winRockScissors
6932N/A documentation.winStrongRockPaper
6932N/A documentation.writefloat
3840N/A4 items passed all tests:
6932N/A 78 tests in documentation
6932N/A 3 tests in documentation.Action
6932N/A 2 tests in documentation.a_test_for_pylons
6932N/A 2 tests in documentation.hello
6932N/A85 teok
6932N/Atest_singledispatch1 (__main__.DocumentationTestCase) ... ok
6932N/Atest_singledispatch2 (__main__.DocumentationTestCase) ... ok
6932N/Atest_no_first_arg (__main__.ExtraTestCase) ... ok
6932N/Atest_qualname (__main__.ExtraTestCase) ... ok
6932N/Atest_signature (__main__.ExtraTestCase) ... ok
6932N/Atest_unique_filenames (__main__.ExtraTestCase) ... ok
6932N/Atest_c_classes (__main__.TestSingleDispatch) ... ok
6932N/Atest_mro (__main__.TestSingleDispatch) ... ok
6932N/Atest_mro_conflicts (__main__.TestSingleDispatch) ... ok
6932N/Atest_register_abc (__main__.TestSingleDispatch) ... ok
6932N/Atest_register_decorator (__main__.TestSingleDispatch) ... ok
6932N/Atest_register_error (__main__.TestSingleDispatch) ... ok
6932N/Atest_simple_overloads (__main__.TestSingleDispatch) ... ok
6932N/Atest_wrapping_attributes (__main__.TestSingleDispatch) ... ok
6932N/A
6932N/A----------------------------------------------------------------------
6932N/ARan 15 tests in
6932N/A
6932N/AOK
6932N/Asts in 56 items.
6932N/A85 passed and 0 failed.
3840N/ATest passed.