# Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. """pytest fixtures.""" from __future__ import annotations import json import os import os.path as osp import shutil from os.path import join as pjoin from pathlib import Path from typing import Any, Callable import pytest from jupyter_server.serverapp import ServerApp from jupyterlab_server import LabServerApp pytest_plugins = ["pytest_jupyter.jupyter_server"] def mkdir(tmp_path: Path, *parts: str) -> Path: """Util for making a directory.""" path = tmp_path.joinpath(*parts) if not path.exists(): path.mkdir(parents=True) return path HERE = os.path.abspath(os.path.dirname(__file__)) 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")) labextensions_dir = pytest.fixture(lambda tmp_path: mkdir(tmp_path, "labextensions_dir")) @pytest.fixture def make_labserver_extension_app( jp_root_dir: Path, jp_template_dir: Path, app_settings_dir: Path, user_settings_dir: Path, schemas_dir: Path, workspaces_dir: Path, labextensions_dir: Path, ) -> Callable[..., LabServerApp]: """Return a factory function for a labserver extension app.""" def _make_labserver_extension_app(**kwargs: Any) -> LabServerApp: # noqa: ARG001 """Factory function for lab server extension apps.""" return LabServerApp( 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), extra_labextensions_path=[str(labextensions_dir)], ) # Create the index files. index = jp_template_dir.joinpath("index.html") index.write_text( """