##// END OF EJS Templates
Automatically open a comm on creation of widgets...
Automatically open a comm on creation of widgets This will immediately create a model on the javascript side when a widget is created. This means that, for example, a widget that only interacts with its model can work without "displaying" it.

File last commit:

r16506:e56ff8b2
r17612:cf808d21
Show More
test_pickleutil.py
61 lines | 1.1 KiB | text/x-python | PythonLexer
MinRK
handle simple closures in pickleutil...
r16506
import pickle
import nose.tools as nt
from IPython.utils import codeutil
from IPython.utils.pickleutil import can, uncan
def interactive(f):
f.__module__ = '__main__'
return f
def dumps(obj):
return pickle.dumps(can(obj))
def loads(obj):
return uncan(pickle.loads(obj))
def test_no_closure():
@interactive
def foo():
a = 5
return a
pfoo = dumps(foo)
bar = loads(pfoo)
nt.assert_equal(foo(), bar())
def test_generator_closure():
# this only creates a closure on Python 3
@interactive
def foo():
i = 'i'
r = [ i for j in (1,2) ]
return r
pfoo = dumps(foo)
bar = loads(pfoo)
nt.assert_equal(foo(), bar())
def test_nested_closure():
@interactive
def foo():
i = 'i'
def g():
return i
return g()
pfoo = dumps(foo)
bar = loads(pfoo)
nt.assert_equal(foo(), bar())
def test_closure():
i = 'i'
@interactive
def foo():
return i
pfoo = dumps(foo)
bar = loads(pfoo)
nt.assert_equal(foo(), bar())