Show More
@@ -0,0 +1,69 b'' | |||||
|
1 | import os.path | |||
|
2 | ||||
|
3 | import nose.tools as nt | |||
|
4 | ||||
|
5 | import IPython.testing.tools as tt | |||
|
6 | from IPython.utils.syspathcontext import prepended_to_syspath | |||
|
7 | from IPython.utils.tempdir import TemporaryDirectory | |||
|
8 | ||||
|
9 | ext1_content = """ | |||
|
10 | def load_ipython_extension(ip): | |||
|
11 | print("Running ext1 load") | |||
|
12 | ||||
|
13 | def unload_ipython_extension(ip): | |||
|
14 | print("Running ext1 unload") | |||
|
15 | """ | |||
|
16 | ||||
|
17 | ext2_content = """ | |||
|
18 | def load_ipython_extension(ip): | |||
|
19 | print("Running ext2 load") | |||
|
20 | """ | |||
|
21 | ||||
|
22 | def test_extension_loading(): | |||
|
23 | em = get_ipython().extension_manager | |||
|
24 | with TemporaryDirectory() as td: | |||
|
25 | ext1 = os.path.join(td, 'ext1.py') | |||
|
26 | with open(ext1, 'w') as f: | |||
|
27 | f.write(ext1_content) | |||
|
28 | ||||
|
29 | ext2 = os.path.join(td, 'ext2.py') | |||
|
30 | with open(ext2, 'w') as f: | |||
|
31 | f.write(ext2_content) | |||
|
32 | ||||
|
33 | with prepended_to_syspath(td): | |||
|
34 | assert 'ext1' not in em.loaded | |||
|
35 | assert 'ext2' not in em.loaded | |||
|
36 | ||||
|
37 | # Load extension | |||
|
38 | with tt.AssertPrints("Running ext1 load"): | |||
|
39 | assert em.load_extension('ext1') is None | |||
|
40 | assert 'ext1' in em.loaded | |||
|
41 | ||||
|
42 | # Should refuse to load it again | |||
|
43 | with tt.AssertNotPrints("Running ext1 load"): | |||
|
44 | assert em.load_extension('ext1') == 'already loaded' | |||
|
45 | ||||
|
46 | # Reload | |||
|
47 | with tt.AssertPrints("Running ext1 unload"): | |||
|
48 | with tt.AssertPrints("Running ext1 load", suppress=False): | |||
|
49 | em.reload_extension('ext1') | |||
|
50 | ||||
|
51 | # Unload | |||
|
52 | with tt.AssertPrints("Running ext1 unload"): | |||
|
53 | assert em.unload_extension('ext1') is None | |||
|
54 | ||||
|
55 | # Can't unload again | |||
|
56 | with tt.AssertNotPrints("Running ext1 unload"): | |||
|
57 | assert em.unload_extension('ext1') == 'not loaded' | |||
|
58 | assert em.unload_extension('ext2') == 'not loaded' | |||
|
59 | ||||
|
60 | # Load extension 2 | |||
|
61 | with tt.AssertPrints("Running ext2 load"): | |||
|
62 | assert em.load_extension('ext2') is None | |||
|
63 | ||||
|
64 | # Can't unload this | |||
|
65 | assert em.unload_extension('ext2') == 'no unload function' | |||
|
66 | ||||
|
67 | # But can reload it | |||
|
68 | with tt.AssertPrints("Running ext2 load"): | |||
|
69 | em.reload_extension('ext2') |
General Comments 0
You need to be logged in to leave comments.
Login now