Show More
@@ -92,15 +92,16 b' class ExtensionManager(Configurable):' | |||||
92 | return "already loaded" |
|
92 | return "already loaded" | |
93 |
|
93 | |||
94 | from IPython.utils.syspathcontext import prepended_to_syspath |
|
94 | from IPython.utils.syspathcontext import prepended_to_syspath | |
95 |
|
95 | |||
96 | if module_str not in sys.modules: |
|
96 | with self.shell.builtin_trap: | |
97 | with prepended_to_syspath(self.ipython_extension_dir): |
|
97 | if module_str not in sys.modules: | |
98 | __import__(module_str) |
|
98 | with prepended_to_syspath(self.ipython_extension_dir): | |
99 | mod = sys.modules[module_str] |
|
99 | __import__(module_str) | |
100 | if self._call_load_ipython_extension(mod): |
|
100 | mod = sys.modules[module_str] | |
101 | self.loaded.add(module_str) |
|
101 | if self._call_load_ipython_extension(mod): | |
102 | else: |
|
102 | self.loaded.add(module_str) | |
103 | return "no load function" |
|
103 | else: | |
|
104 | return "no load function" | |||
104 |
|
105 | |||
105 | def unload_extension(self, module_str): |
|
106 | def unload_extension(self, module_str): | |
106 | """Unload an IPython extension by its module name. |
|
107 | """Unload an IPython extension by its module name. |
@@ -19,6 +19,12 b' def load_ipython_extension(ip):' | |||||
19 | print("Running ext2 load") |
|
19 | print("Running ext2 load") | |
20 | """ |
|
20 | """ | |
21 |
|
21 | |||
|
22 | ext3_content = """ | |||
|
23 | def load_ipython_extension(ip): | |||
|
24 | ip2 = get_ipython() | |||
|
25 | print(ip is ip2) | |||
|
26 | """ | |||
|
27 | ||||
22 | def test_extension_loading(): |
|
28 | def test_extension_loading(): | |
23 | em = get_ipython().extension_manager |
|
29 | em = get_ipython().extension_manager | |
24 | with TemporaryDirectory() as td: |
|
30 | with TemporaryDirectory() as td: | |
@@ -68,6 +74,23 b' def test_extension_loading():' | |||||
68 | with tt.AssertPrints("Running ext2 load"): |
|
74 | with tt.AssertPrints("Running ext2 load"): | |
69 | em.reload_extension('ext2') |
|
75 | em.reload_extension('ext2') | |
70 |
|
76 | |||
|
77 | ||||
|
78 | def test_extension_builtins(): | |||
|
79 | em = get_ipython().extension_manager | |||
|
80 | with TemporaryDirectory() as td: | |||
|
81 | ext3 = os.path.join(td, 'ext3.py') | |||
|
82 | with open(ext3, 'w') as f: | |||
|
83 | f.write(ext3_content) | |||
|
84 | ||||
|
85 | assert 'ext3' not in em.loaded | |||
|
86 | ||||
|
87 | with prepended_to_syspath(td): | |||
|
88 | # Load extension | |||
|
89 | with tt.AssertPrints("True"): | |||
|
90 | assert em.load_extension('ext3') is None | |||
|
91 | assert 'ext3' in em.loaded | |||
|
92 | ||||
|
93 | ||||
71 | def test_non_extension(): |
|
94 | def test_non_extension(): | |
72 | em = get_ipython().extension_manager |
|
95 | em = get_ipython().extension_manager | |
73 | nt.assert_equal(em.load_extension('sys'), "no load function") |
|
96 | nt.assert_equal(em.load_extension('sys'), "no load function") |
General Comments 0
You need to be logged in to leave comments.
Login now