##// END OF EJS Templates
the __future__ is now.
the __future__ is now.

File last commit:

r21551:1d9ef762
r22963:2961b531
Show More
test_deepreload.py
59 lines | 2.1 KiB | text/x-python | PythonLexer
/ IPython / lib / tests / test_deepreload.py
Bradley M. Froehle
Reformat test to a standard style.
r6534 # -*- coding: utf-8 -*-
Bradley M. Froehle
Add deepreload unit test....
r6533 """Test suite for the deepreload module."""
Bradley M. Froehle
Reformat test to a standard style.
r6534 #-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
Bradley M. Froehle
Add deepreload functionality test.
r6535 import os
import nose.tools as nt
Bradley M. Froehle
Add deepreload unit test....
r6533 from IPython.testing import decorators as dec
Matthias Bussonnier
Do not deep-reload collection to fix tests....
r21384 from IPython.utils.py3compat import builtin_mod_name, PY3
Bradley M. Froehle
Clean up sys.path entry.
r6541 from IPython.utils.syspathcontext import prepended_to_syspath
Bradley M. Froehle
Add deepreload functionality test.
r6535 from IPython.utils.tempdir import TemporaryDirectory
Bradley M. Froehle
Add deepreload unit test....
r6533 from IPython.lib.deepreload import reload as dreload
Bradley M. Froehle
Reformat test to a standard style.
r6534 #-----------------------------------------------------------------------------
# Test functions begin
#-----------------------------------------------------------------------------
Bradley M. Froehle
Add deepreload unit test....
r6533 @dec.skipif_not_numpy
def test_deepreload_numpy():
Bradley M. Froehle
Add deepreload functionality test.
r6535 "Test that NumPy can be deep reloaded."
Bradley M. Froehle
Add deepreload unit test....
r6533 import numpy
Thomas Kluyver
Exclude some more modules from deepreload test...
r21550 # TODO: Find a way to exclude all standard library modules from reloading.
Bradley M. Froehle
Add deepreload unit test....
r6533 exclude = [
# Standard exclusions:
Thomas Kluyver
Fix imports of builtins module
r13351 'sys', 'os.path', builtin_mod_name, '__main__',
Bradley M. Froehle
Add deepreload unit test....
r6533 # Test-related exclusions:
Thomas Kluyver
Another attempt at blacklisting collections for dreload...
r21445 'unittest', 'UserDict', '_collections_abc', 'tokenize',
Thomas Kluyver
Wake up, Travis!
r21446 'collections', 'collections.abc',
Thomas Kluyver
Exclude some more import-related modules from deepreload test
r21551 'importlib', 'importlib.machinery', '_imp',
'importlib._bootstrap', 'importlib._bootstrap_external',
'_frozen_importlib', '_frozen_importlib_external',
Bradley M. Froehle
Add deepreload unit test....
r6533 ]
Matthias Bussonnier
Do not deep-reload collection to fix tests....
r21384
Bradley M. Froehle
Add deepreload unit test....
r6533 dreload(numpy, exclude=exclude)
Bradley M. Froehle
Add deepreload functionality test.
r6535
def test_deepreload():
"Test that dreload does deep reloads and skips excluded modules."
with TemporaryDirectory() as tmpdir:
Bradley M. Froehle
Clean up sys.path entry.
r6541 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))