##// END OF EJS Templates
Merge pull request #2868 from takluyver/import-performance...
Merge pull request #2868 from takluyver/import-performance Import performance Defer various imports for a small reduction in startup time. IPython.lib.__init__ previously loaded IPython.lib.inputhook to export some of its functions. This meant that importing anything from IPython.lib also loaded inputhook. For now, I've just removed that import, but that is an API change, because the functions are no longer accessible as e.g. IPython.lib.enable_qt4 Added a note about the API change. Timing command, borrowed from Openoffice to simulate cold start: $ sync ; echo 3 | sudo tee /proc/sys/vm/drop_caches; time ipython3 -c pass Results with this branch: 7.68, 7.64, 7.35, 7.38 s 'real' Results with master: 8.17, 8.04, 7.81, 7.77

File last commit:

r6612:9b5abe14
r9459:ff3032f2 merge
Show More
test_deepreload.py
53 lines | 1.7 KiB | text/x-python | PythonLexer
# -*- coding: utf-8 -*-
"""Test suite for the deepreload module."""
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
import os
import sys
import nose.tools as nt
from IPython.testing import decorators as dec
from IPython.utils.syspathcontext import prepended_to_syspath
from IPython.utils.tempdir import TemporaryDirectory
from IPython.lib.deepreload import reload as dreload
#-----------------------------------------------------------------------------
# Test functions begin
#-----------------------------------------------------------------------------
@dec.skipif_not_numpy
def test_deepreload_numpy():
"Test that NumPy can be deep reloaded."
import numpy
exclude = [
# Standard exclusions:
'sys', 'os.path', '__builtin__', '__main__',
# Test-related exclusions:
'unittest', 'UserDict',
]
dreload(numpy, exclude=exclude)
def test_deepreload():
"Test that dreload does deep reloads and skips excluded modules."
with TemporaryDirectory() as tmpdir:
with prepended_to_syspath(tmpdir):
with open(os.path.join(tmpdir, 'A.py'), 'w') as f:
f.write("class Object(object):\n pass\n")
with open(os.path.join(tmpdir, 'B.py'), 'w') as f:
f.write("import A\n")
import A
import B
# Test that A is not reloaded.
obj = A.Object()
dreload(B, exclude=['A'])
nt.assert_true(isinstance(obj, A.Object))
# Test that A is reloaded.
obj = A.Object()
dreload(B)
nt.assert_false(isinstance(obj, A.Object))