Show More
@@ -1,52 +1,53 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 | import sys |
|
9 | import sys | |
10 |
|
10 | |||
11 | import nose.tools as nt |
|
11 | import nose.tools as nt | |
12 |
|
12 | |||
13 | from IPython.testing import decorators as dec |
|
13 | from IPython.testing import decorators as dec | |
|
14 | from IPython.utils.syspathcontext import prepended_to_syspath | |||
14 | from IPython.utils.tempdir import TemporaryDirectory |
|
15 | from IPython.utils.tempdir import TemporaryDirectory | |
15 | from IPython.lib.deepreload import reload as dreload |
|
16 | from IPython.lib.deepreload import reload as dreload | |
16 |
|
17 | |||
17 | #----------------------------------------------------------------------------- |
|
18 | #----------------------------------------------------------------------------- | |
18 | # Test functions begin |
|
19 | # Test functions begin | |
19 | #----------------------------------------------------------------------------- |
|
20 | #----------------------------------------------------------------------------- | |
20 |
|
21 | |||
21 | @dec.skipif_not_numpy |
|
22 | @dec.skipif_not_numpy | |
22 | def test_deepreload_numpy(): |
|
23 | def test_deepreload_numpy(): | |
23 | "Test that NumPy can be deep reloaded." |
|
24 | "Test that NumPy can be deep reloaded." | |
24 | import numpy |
|
25 | import numpy | |
25 | exclude = [ |
|
26 | exclude = [ | |
26 | # Standard exclusions: |
|
27 | # Standard exclusions: | |
27 | 'sys', 'os.path', '__builtin__', '__main__', |
|
28 | 'sys', 'os.path', '__builtin__', '__main__', | |
28 | # Test-related exclusions: |
|
29 | # Test-related exclusions: | |
29 | 'unittest', |
|
30 | 'unittest', | |
30 | ] |
|
31 | ] | |
31 | dreload(numpy, exclude=exclude) |
|
32 | dreload(numpy, exclude=exclude) | |
32 |
|
33 | |||
33 | def test_deepreload(): |
|
34 | def test_deepreload(): | |
34 | "Test that dreload does deep reloads and skips excluded modules." |
|
35 | "Test that dreload does deep reloads and skips excluded modules." | |
35 | with TemporaryDirectory() as tmpdir: |
|
36 | with TemporaryDirectory() as tmpdir: | |
36 |
sys |
|
37 | with prepended_to_syspath(tmpdir): | |
37 | with open(os.path.join(tmpdir, 'A.py'), 'w') as f: |
|
38 | with open(os.path.join(tmpdir, 'A.py'), 'w') as f: | |
38 | f.write("class Object(object):\n pass\n") |
|
39 | f.write("class Object(object):\n pass\n") | |
39 | with open(os.path.join(tmpdir, 'B.py'), 'w') as f: |
|
40 | with open(os.path.join(tmpdir, 'B.py'), 'w') as f: | |
40 | f.write("import A\n") |
|
41 | f.write("import A\n") | |
41 | import A |
|
42 | import A | |
42 | import B |
|
43 | import B | |
43 |
|
44 | |||
44 | # Test that A is not reloaded. |
|
45 | # Test that A is not reloaded. | |
45 | obj = A.Object() |
|
46 | obj = A.Object() | |
46 | dreload(B, exclude=['A']) |
|
47 | dreload(B, exclude=['A']) | |
47 | nt.assert_true(isinstance(obj, A.Object)) |
|
48 | nt.assert_true(isinstance(obj, A.Object)) | |
48 |
|
49 | |||
49 | # Test that A is reloaded. |
|
50 | # Test that A is reloaded. | |
50 | obj = A.Object() |
|
51 | obj = A.Object() | |
51 | dreload(B) |
|
52 | dreload(B) | |
52 | nt.assert_false(isinstance(obj, A.Object)) |
|
53 | nt.assert_false(isinstance(obj, A.Object)) |
General Comments 0
You need to be logged in to leave comments.
Login now