##// END OF EJS Templates
Display exception notes in tracebacks
Display exception notes in tracebacks

File last commit:

r27548:6d40fd89 merge
r28242:074040ed
Show More
test_extension.py
95 lines | 3.0 KiB | text/x-python | PythonLexer
Thomas Kluyver
Add test for extension loading and unloading
r8551 import os.path
Matthias Bussonnier
MAINT: cleanup imports of tempdir....
r27509 from tempfile import TemporaryDirectory
Thomas Kluyver
Add test for extension loading and unloading
r8551 import IPython.testing.tools as tt
from IPython.utils.syspathcontext import prepended_to_syspath
ext1_content = """
def load_ipython_extension(ip):
print("Running ext1 load")
def unload_ipython_extension(ip):
print("Running ext1 unload")
"""
ext2_content = """
def load_ipython_extension(ip):
print("Running ext2 load")
"""
MinRK
load extensions in builtin trap...
r10574 ext3_content = """
def load_ipython_extension(ip):
ip2 = get_ipython()
print(ip is ip2)
"""
Thomas Kluyver
Add test for extension loading and unloading
r8551 def test_extension_loading():
em = get_ipython().extension_manager
with TemporaryDirectory() as td:
gousaiyang
Format code
r27495 ext1 = os.path.join(td, "ext1.py")
with open(ext1, "w", encoding="utf-8") as f:
Thomas Kluyver
Add test for extension loading and unloading
r8551 f.write(ext1_content)
gousaiyang
Format code
r27495
ext2 = os.path.join(td, "ext2.py")
with open(ext2, "w", encoding="utf-8") as f:
Thomas Kluyver
Add test for extension loading and unloading
r8551 f.write(ext2_content)
with prepended_to_syspath(td):
assert 'ext1' not in em.loaded
assert 'ext2' not in em.loaded
# Load extension
with tt.AssertPrints("Running ext1 load"):
assert em.load_extension('ext1') is None
assert 'ext1' in em.loaded
# Should refuse to load it again
with tt.AssertNotPrints("Running ext1 load"):
assert em.load_extension('ext1') == 'already loaded'
# Reload
with tt.AssertPrints("Running ext1 unload"):
with tt.AssertPrints("Running ext1 load", suppress=False):
em.reload_extension('ext1')
# Unload
with tt.AssertPrints("Running ext1 unload"):
assert em.unload_extension('ext1') is None
# Can't unload again
with tt.AssertNotPrints("Running ext1 unload"):
assert em.unload_extension('ext1') == 'not loaded'
assert em.unload_extension('ext2') == 'not loaded'
# Load extension 2
with tt.AssertPrints("Running ext2 load"):
assert em.load_extension('ext2') is None
# Can't unload this
assert em.unload_extension('ext2') == 'no unload function'
# But can reload it
with tt.AssertPrints("Running ext2 load"):
em.reload_extension('ext2')
Thomas Kluyver
Add message when trying to %load_ext a module that is not an IPython extension.
r8586
MinRK
load extensions in builtin trap...
r10574
def test_extension_builtins():
em = get_ipython().extension_manager
with TemporaryDirectory() as td:
gousaiyang
Format code
r27495 ext3 = os.path.join(td, "ext3.py")
with open(ext3, "w", encoding="utf-8") as f:
MinRK
load extensions in builtin trap...
r10574 f.write(ext3_content)
assert 'ext3' not in em.loaded
with prepended_to_syspath(td):
# Load extension
with tt.AssertPrints("True"):
assert em.load_extension('ext3') is None
assert 'ext3' in em.loaded
Thomas Kluyver
Add message when trying to %load_ext a module that is not an IPython extension.
r8586 def test_non_extension():
em = get_ipython().extension_manager
Samuel Gaist
[core][tests][extension] Remove nose
r26893 assert em.load_extension("sys") == "no load function"