def test_umr_run(user_module): """Test that UMR's run method is working correctly.""" # Create user module user_module('foo1') # Activate verbose mode in the UMR os.environ['SPY_UMR_VERBOSE'] = 'True' # Create UMR umr = UserModuleReloader() from foo1.bar import square umr.run() umr.modnames_to_reload == ['foo', 'foo.bar']
def test_umr_skip_cython(user_module): """ Test that the UMR doesn't try to reload modules when Cython support is active. """ # Create user module user_module('foo') # Activate Cython support os.environ['SPY_RUN_CYTHON'] = 'True' # Create UMR umr = UserModuleReloader() import foo assert umr.is_module_reloadable(foo, 'foo') == False # Deactivate Cython support os.environ['SPY_RUN_CYTHON'] = 'False'
def test_umr_reload_modules(user_module): """Test that the UMR only tries to reload user modules.""" # Create user module user_module('foo3') # Create UMR umr = UserModuleReloader() # Don't reload stdlib modules import xml assert not umr.is_module_reloadable(xml, 'xml') # Don't reload third-party modules import numpy assert not umr.is_module_reloadable(numpy, 'numpy') # Reload user modules import foo3 assert umr.is_module_reloadable(foo3, 'foo3')
def test_umr_previous_modules(user_module): """Test that UMR's previos_modules is working as expected.""" # Create user module user_module('foo2') # Create UMR umr = UserModuleReloader() import foo2 assert 'IPython' in umr.previous_modules assert 'foo2' not in umr.previous_modules
def test_umr_namelist(): """Test that the UMR skips modules according to its name.""" umr = UserModuleReloader() assert umr.is_module_in_namelist('tensorflow') assert umr.is_module_in_namelist('pytorch') assert umr.is_module_in_namelist('spyder_kernels') assert not umr.is_module_in_namelist('foo')
# ============================================================================= def cmd_input(prompt=''): return get_ipython().kernel.cmd_input(prompt) pdb.Pdb = SpyderPdb if PY2: cmd.raw_input = cmd_input else: cmd.input = cmd_input # ============================================================================= # User module reloader # ============================================================================= __umr__ = UserModuleReloader(namelist=os.environ.get("SPY_UMR_NAMELIST", None)) # ============================================================================= # Handle Post Mortem Debugging and Traceback Linkage to Spyder # ============================================================================= def post_mortem_excepthook(type, value, tb): """ For post mortem exception handling, print a banner and enable post mortem debugging. """ ipython_shell = get_ipython() ipython_shell.showtraceback((type, value, tb)) p = pdb.Pdb(ipython_shell.colors) if not type == SyntaxError: