##// END OF EJS Templates
Exclude some more import-related modules from deepreload test
Thomas Kluyver -
Show More
@@ -1,58 +1,59 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """Test suite for the deepreload module."""
2 """Test suite for the deepreload module."""
3
3
4 #-----------------------------------------------------------------------------
4 #-----------------------------------------------------------------------------
5 # Imports
5 # Imports
6 #-----------------------------------------------------------------------------
6 #-----------------------------------------------------------------------------
7
7
8 import os
8 import os
9
9
10 import nose.tools as nt
10 import nose.tools as nt
11
11
12 from IPython.testing import decorators as dec
12 from IPython.testing import decorators as dec
13 from IPython.utils.py3compat import builtin_mod_name, PY3
13 from IPython.utils.py3compat import builtin_mod_name, PY3
14 from IPython.utils.syspathcontext import prepended_to_syspath
14 from IPython.utils.syspathcontext import prepended_to_syspath
15 from IPython.utils.tempdir import TemporaryDirectory
15 from IPython.utils.tempdir import TemporaryDirectory
16 from IPython.lib.deepreload import reload as dreload
16 from IPython.lib.deepreload import reload as dreload
17
17
18 #-----------------------------------------------------------------------------
18 #-----------------------------------------------------------------------------
19 # Test functions begin
19 # Test functions begin
20 #-----------------------------------------------------------------------------
20 #-----------------------------------------------------------------------------
21
21
22 @dec.skipif_not_numpy
22 @dec.skipif_not_numpy
23 def test_deepreload_numpy():
23 def test_deepreload_numpy():
24 "Test that NumPy can be deep reloaded."
24 "Test that NumPy can be deep reloaded."
25 import numpy
25 import numpy
26 # TODO: Find a way to exclude all standard library modules from reloading.
26 # TODO: Find a way to exclude all standard library modules from reloading.
27 exclude = [
27 exclude = [
28 # Standard exclusions:
28 # Standard exclusions:
29 'sys', 'os.path', builtin_mod_name, '__main__',
29 'sys', 'os.path', builtin_mod_name, '__main__',
30 # Test-related exclusions:
30 # Test-related exclusions:
31 'unittest', 'UserDict', '_collections_abc', 'tokenize',
31 'unittest', 'UserDict', '_collections_abc', 'tokenize',
32 'collections', 'collections.abc',
32 'collections', 'collections.abc',
33 'importlib', 'importlib._bootstrap', '_frozen_importlib',
33 'importlib', 'importlib.machinery', '_imp',
34 '_frozen_importlib_external',
34 'importlib._bootstrap', 'importlib._bootstrap_external',
35 '_frozen_importlib', '_frozen_importlib_external',
35 ]
36 ]
36
37
37 dreload(numpy, exclude=exclude)
38 dreload(numpy, exclude=exclude)
38
39
39 def test_deepreload():
40 def test_deepreload():
40 "Test that dreload does deep reloads and skips excluded modules."
41 "Test that dreload does deep reloads and skips excluded modules."
41 with TemporaryDirectory() as tmpdir:
42 with TemporaryDirectory() as tmpdir:
42 with prepended_to_syspath(tmpdir):
43 with prepended_to_syspath(tmpdir):
43 with open(os.path.join(tmpdir, 'A.py'), 'w') as f:
44 with open(os.path.join(tmpdir, 'A.py'), 'w') as f:
44 f.write("class Object(object):\n pass\n")
45 f.write("class Object(object):\n pass\n")
45 with open(os.path.join(tmpdir, 'B.py'), 'w') as f:
46 with open(os.path.join(tmpdir, 'B.py'), 'w') as f:
46 f.write("import A\n")
47 f.write("import A\n")
47 import A
48 import A
48 import B
49 import B
49
50
50 # Test that A is not reloaded.
51 # Test that A is not reloaded.
51 obj = A.Object()
52 obj = A.Object()
52 dreload(B, exclude=['A'])
53 dreload(B, exclude=['A'])
53 nt.assert_true(isinstance(obj, A.Object))
54 nt.assert_true(isinstance(obj, A.Object))
54
55
55 # Test that A is reloaded.
56 # Test that A is reloaded.
56 obj = A.Object()
57 obj = A.Object()
57 dreload(B)
58 dreload(B)
58 nt.assert_false(isinstance(obj, A.Object))
59 nt.assert_false(isinstance(obj, A.Object))
General Comments 0
You need to be logged in to leave comments. Login now