# Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. import urllib.parse import pytest from jupyter_server.utils import url_path_join from jupyterlab_server import LabConfig from tornado.escape import url_escape from traitlets import Unicode from jupyterlab.labapp import LabApp def mkdir(tmp_path, *parts): path = tmp_path.joinpath(*parts) if not path.exists(): path.mkdir(parents=True) return path app_settings_dir = pytest.fixture(lambda tmp_path: mkdir(tmp_path, "app_settings")) user_settings_dir = pytest.fixture(lambda tmp_path: mkdir(tmp_path, "user_settings")) schemas_dir = pytest.fixture(lambda tmp_path: mkdir(tmp_path, "schemas")) workspaces_dir = pytest.fixture(lambda tmp_path: mkdir(tmp_path, "workspaces")) @pytest.fixture def make_lab_app( jp_root_dir, jp_template_dir, app_settings_dir, user_settings_dir, schemas_dir, workspaces_dir ): def _make_lab_app(**kwargs): class TestLabApp(LabApp): base_url = "/lab" extension_url = "/lab" default_url = Unicode("/", help="The default URL to redirect to from `/`") lab_config = LabConfig( app_name="JupyterLab Test App", static_dir=str(jp_root_dir), templates_dir=str(jp_template_dir), app_url="/lab", app_settings_dir=str(app_settings_dir), user_settings_dir=str(user_settings_dir), schemas_dir=str(schemas_dir), workspaces_dir=str(workspaces_dir), ) app = TestLabApp() return app # Create the index files. index = jp_template_dir.joinpath("index.html") index.write_text( """