Permalink
Browse files

Add test that we can pickle objects defined interactively.

  • Loading branch information...
1 parent 5411be8 commit 66c14cf7d1f1fa274f7fb8afda7eec264be9818e @takluyver committed Apr 15, 2011
Showing with 18 additions and 1 deletion.
  1. +14 −0 IPython/core/tests/test_interactiveshell.py
  2. +4 −1 IPython/testing/globalipapp.py
@@ -91,3 +91,17 @@ def test_magic_names_in_string(self):
ip = get_ipython()
ip.run_cell('a = """\n%exit\n"""')
self.assertEquals(ip.user_ns['a'], '\n%exit\n')
+
+ def test_can_pickle(self):
+ ip = get_ipython()
+ ip.run_cell(("class Mylist(list):\n"
+ " def __init__(self,x=[]):\n"
+ " list.__init__(self,x)"))
+ ip.run_cell("w=Mylist([1,2,3])")
+
+ from cPickle import dumps
+ res = dumps(ip.user_ns["w"])
+ self.assertTrue(isinstance(res, bytes))
+
+
+
@@ -82,6 +82,9 @@ def __init__(self,*a):
# namespace in doctests that call '_'.
self.protect_underscore = False
+ # We set this so that the tests don't clash with __main__
+ self["__name__"] = "__test_main__"
+
def clear(self):
dict.clear(self)
self.update(self._savedict)
@@ -158,7 +161,7 @@ def start_ipython():
# Create and initialize our test-friendly IPython instance.
shell = TerminalInteractiveShell.instance(config=config,
user_ns=ipnsdict(),
- user_global_ns={}
+ user_global_ns={'__name__':'__test_main__'}
)
# A few more tweaks needed for playing nicely with doctests...

0 comments on commit 66c14cf

Please sign in to comment.