MCPcopy Create free account
hub / github.com/ipython/ipython / test_extension_loading

Function test_extension_loading

IPython/core/tests/test_extension.py:28–75  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

26"""
27
28def test_extension_loading():
29 em = get_ipython().extension_manager
30 with TemporaryDirectory() as td:
31 ext1 = os.path.join(td, 'ext1.py')
32 with open(ext1, 'w') as f:
33 f.write(ext1_content)
34
35 ext2 = os.path.join(td, 'ext2.py')
36 with open(ext2, 'w') as f:
37 f.write(ext2_content)
38
39 with prepended_to_syspath(td):
40 assert 'ext1' not in em.loaded
41 assert 'ext2' not in em.loaded
42
43 # Load extension
44 with tt.AssertPrints("Running ext1 load"):
45 assert em.load_extension('ext1') is None
46 assert 'ext1' in em.loaded
47
48 # Should refuse to load it again
49 with tt.AssertNotPrints("Running ext1 load"):
50 assert em.load_extension('ext1') == 'already loaded'
51
52 # Reload
53 with tt.AssertPrints("Running ext1 unload"):
54 with tt.AssertPrints("Running ext1 load", suppress=False):
55 em.reload_extension('ext1')
56
57 # Unload
58 with tt.AssertPrints("Running ext1 unload"):
59 assert em.unload_extension('ext1') is None
60
61 # Can't unload again
62 with tt.AssertNotPrints("Running ext1 unload"):
63 assert em.unload_extension('ext1') == 'not loaded'
64 assert em.unload_extension('ext2') == 'not loaded'
65
66 # Load extension 2
67 with tt.AssertPrints("Running ext2 load"):
68 assert em.load_extension('ext2') is None
69
70 # Can't unload this
71 assert em.unload_extension('ext2') == 'no unload function'
72
73 # But can reload it
74 with tt.AssertPrints("Running ext2 load"):
75 em.reload_extension('ext2')
76
77
78def test_extension_builtins():

Callers

nothing calls this directly

Calls 6

load_extensionMethod · 0.80
reload_extensionMethod · 0.80
unload_extensionMethod · 0.80
get_ipythonFunction · 0.50
writeMethod · 0.45

Tested by

no test coverage detected