Show More
@@ -92,15 +92,16 b' class ExtensionManager(Configurable):' | |||
|
92 | 92 | return "already loaded" |
|
93 | 93 | |
|
94 | 94 | from IPython.utils.syspathcontext import prepended_to_syspath |
|
95 | ||
|
96 | if module_str not in sys.modules: | |
|
97 | with prepended_to_syspath(self.ipython_extension_dir): | |
|
98 | __import__(module_str) | |
|
99 | mod = sys.modules[module_str] | |
|
100 | if self._call_load_ipython_extension(mod): | |
|
101 | self.loaded.add(module_str) | |
|
102 | else: | |
|
103 | return "no load function" | |
|
95 | ||
|
96 | with self.shell.builtin_trap: | |
|
97 | if module_str not in sys.modules: | |
|
98 | with prepended_to_syspath(self.ipython_extension_dir): | |
|
99 | __import__(module_str) | |
|
100 | mod = sys.modules[module_str] | |
|
101 | if self._call_load_ipython_extension(mod): | |
|
102 | self.loaded.add(module_str) | |
|
103 | else: | |
|
104 | return "no load function" | |
|
104 | 105 | |
|
105 | 106 | def unload_extension(self, module_str): |
|
106 | 107 | """Unload an IPython extension by its module name. |
@@ -19,6 +19,12 b' def load_ipython_extension(ip):' | |||
|
19 | 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 | 28 | def test_extension_loading(): |
|
23 | 29 | em = get_ipython().extension_manager |
|
24 | 30 | with TemporaryDirectory() as td: |
@@ -68,6 +74,23 b' def test_extension_loading():' | |||
|
68 | 74 | with tt.AssertPrints("Running ext2 load"): |
|
69 | 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 | 94 | def test_non_extension(): |
|
72 | 95 | em = get_ipython().extension_manager |
|
73 | 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