def test_stop_extension(jp_serverapp, caplog): """Test the stop_extension method. This should be fired by ServerApp.cleanup_extensions. """ calls = 0 # load extensions (make sure we only have the one extension loaded jp_serverapp.extension_manager.load_all_extensions(jp_serverapp) extension_name = 'jupyter_server.tests.extension.mockextensions' assert list( jp_serverapp.extension_manager.extension_apps) == [extension_name] # add a stop_extension method for the extension app async def _stop(*args): nonlocal calls calls += 1 for apps in jp_serverapp.extension_manager.extension_apps.values(): for app in apps: if app: app.stop_extension = _stop # call cleanup_extensions, check the logging is correct caplog.clear() run_sync(jp_serverapp.cleanup_extensions()) assert [msg for *_, msg in caplog.record_tuples] == [ 'Shutting down 1 extension', '{} | extension app "mockextension" stopping'.format(extension_name), '{} | extension app "mockextension" stopped'.format(extension_name), ] # check the shutdown method was called once assert calls == 1
def test_stop_extension(jp_serverapp, caplog): """Test the stop_extension method. This should be fired by ServerApp.cleanup_extensions. """ calls = 0 # load extensions (make sure we only have the one extension loaded # as well as jp_serverapp.extension_manager.load_all_extensions() extension_name = "tests.extension.mockextensions" apps = set(jp_serverapp.extension_manager.extension_apps) assert apps == {"jupyter_server_terminals", extension_name} # add a stop_extension method for the extension app async def _stop(*args): nonlocal calls calls += 1 for apps in jp_serverapp.extension_manager.extension_apps.values(): for app in apps: if app: app.stop_extension = _stop # call cleanup_extensions, check the logging is correct caplog.clear() run_sync(jp_serverapp.cleanup_extensions()) assert { msg for *_, msg in caplog.record_tuples } == { "Shutting down 2 extensions", "jupyter_server_terminals | extension app 'jupyter_server_terminals' stopping", f"{extension_name} | extension app 'mockextension' stopping", "jupyter_server_terminals | extension app 'jupyter_server_terminals' stopped", f"{extension_name} | extension app 'mockextension' stopped", } # check the shutdown method was called twice assert calls == 2
def jp_serverapp(jp_ensure_app_fixture, jp_server_config, jp_argv, jp_configurable_serverapp): """Starts a Jupyter Server instance based on the established configuration values.""" app = jp_configurable_serverapp(config=jp_server_config, argv=jp_argv) yield app run_sync(app._cleanup())
def stop(self): shutil.rmtree(self.connection_dir) run_sync(self.kernel_manager.shutdown_all())