Show More
@@ -1,53 +1,60 | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """Test suite for the deepreload module.""" |
|
3 | 3 | |
|
4 | 4 | #----------------------------------------------------------------------------- |
|
5 | 5 | # Imports |
|
6 | 6 | #----------------------------------------------------------------------------- |
|
7 | 7 | |
|
8 | 8 | import os |
|
9 | 9 | |
|
10 | 10 | import nose.tools as nt |
|
11 | 11 | |
|
12 | 12 | from IPython.testing import decorators as dec |
|
13 | from IPython.utils.py3compat import builtin_mod_name | |
|
13 | from IPython.utils.py3compat import builtin_mod_name, PY3 | |
|
14 | 14 | from IPython.utils.syspathcontext import prepended_to_syspath |
|
15 | 15 | from IPython.utils.tempdir import TemporaryDirectory |
|
16 | 16 | from IPython.lib.deepreload import reload as dreload |
|
17 | 17 | |
|
18 | 18 | #----------------------------------------------------------------------------- |
|
19 | 19 | # Test functions begin |
|
20 | 20 | #----------------------------------------------------------------------------- |
|
21 | 21 | |
|
22 | 22 | @dec.skipif_not_numpy |
|
23 | 23 | def test_deepreload_numpy(): |
|
24 | 24 | "Test that NumPy can be deep reloaded." |
|
25 | 25 | import numpy |
|
26 | 26 | exclude = [ |
|
27 | 27 | # Standard exclusions: |
|
28 | 28 | 'sys', 'os.path', builtin_mod_name, '__main__', |
|
29 | 29 | # Test-related exclusions: |
|
30 | 30 | 'unittest', 'UserDict', |
|
31 | 31 | ] |
|
32 | ||
|
33 | # `collections` builtin shall not be reloaded to avoid failure | |
|
34 | # of lib.pretty collections related pretty printing. | |
|
35 | # of course this make nose crash on Py3 because of Py 2.3 compat... | |
|
36 | if not PY3: | |
|
37 | exclude.append('collections') | |
|
38 | ||
|
32 | 39 | dreload(numpy, exclude=exclude) |
|
33 | 40 | |
|
34 | 41 | def test_deepreload(): |
|
35 | 42 | "Test that dreload does deep reloads and skips excluded modules." |
|
36 | 43 | with TemporaryDirectory() as tmpdir: |
|
37 | 44 | with prepended_to_syspath(tmpdir): |
|
38 | 45 | with open(os.path.join(tmpdir, 'A.py'), 'w') as f: |
|
39 | 46 | f.write("class Object(object):\n pass\n") |
|
40 | 47 | with open(os.path.join(tmpdir, 'B.py'), 'w') as f: |
|
41 | 48 | f.write("import A\n") |
|
42 | 49 | import A |
|
43 | 50 | import B |
|
44 | 51 | |
|
45 | 52 | # Test that A is not reloaded. |
|
46 | 53 | obj = A.Object() |
|
47 | 54 | dreload(B, exclude=['A']) |
|
48 | 55 | nt.assert_true(isinstance(obj, A.Object)) |
|
49 | 56 | |
|
50 | 57 | # Test that A is reloaded. |
|
51 | 58 | obj = A.Object() |
|
52 | 59 | dreload(B) |
|
53 | 60 | nt.assert_false(isinstance(obj, A.Object)) |
General Comments 0
You need to be logged in to leave comments.
Login now