Can we pickle objects defined interactively (GH-29)
(self)
| 180 | ip.compile.reset_compiler_flags() |
| 181 | |
| 182 | def test_can_pickle(self): |
| 183 | "Can we pickle objects defined interactively (GH-29)" |
| 184 | ip = get_ipython() |
| 185 | ip.reset() |
| 186 | ip.run_cell( |
| 187 | ( |
| 188 | "class Mylist(list):\n" |
| 189 | " def __init__(self,x=[]):\n" |
| 190 | " list.__init__(self,x)" |
| 191 | ) |
| 192 | ) |
| 193 | ip.run_cell("w=Mylist([1,2,3])") |
| 194 | |
| 195 | from pickle import dumps |
| 196 | |
| 197 | # We need to swap in our main module - this is only necessary |
| 198 | # inside the test framework, because IPython puts the interactive module |
| 199 | # in place (but the test framework undoes this). |
| 200 | _main = sys.modules["__main__"] |
| 201 | sys.modules["__main__"] = ip.user_module |
| 202 | try: |
| 203 | res = dumps(ip.user_ns["w"]) |
| 204 | finally: |
| 205 | sys.modules["__main__"] = _main |
| 206 | self.assertTrue(isinstance(res, bytes)) |
| 207 | |
| 208 | def test_global_ns(self): |
| 209 | "Code in functions must be able to access variables outside them." |
nothing calls this directly
no test coverage detected