From b721d3f17c304f1824a25491d24afde809b5e8c0 Mon Sep 17 00:00:00 2001 From: Kian Eliasi Date: Wed, 16 Nov 2022 13:40:00 +0100 Subject: [PATCH] Use pathlib instead of os.path.join in 'tests/conftest.py' --- tests/conftest.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 878e5d809a..edbdee980a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,9 +2,9 @@ import json import os import os.path as osp +import pathlib import shutil from importlib.resources import files -from os.path import join as pjoin import pytest @@ -89,8 +89,8 @@ def _make_notebook_app(**kwargs): # Copy the schema files. test_data = str(files("jupyterlab_server.test_data").joinpath("")) - src = pjoin(test_data, "schemas", "@jupyterlab") - dst = pjoin(str(schemas_dir), "@jupyterlab") + src = pathlib.PurePath(test_data, "schemas", "@jupyterlab") + dst = pathlib.PurePath(str(schemas_dir), "@jupyterlab") if os.path.exists(dst): shutil.rmtree(dst) shutil.copytree(src, dst) @@ -98,28 +98,28 @@ def _make_notebook_app(**kwargs): # Create the federated extensions for name in ["apputils-extension", "codemirror-extension"]: target_name = name + "-federated" - target = pjoin(str(labextensions_dir), "@jupyterlab", target_name) - src = pjoin(test_data, "schemas", "@jupyterlab", name) - dst = pjoin(target, "schemas", "@jupyterlab", target_name) + target = pathlib.PurePath(str(labextensions_dir), "@jupyterlab", target_name) + src = pathlib.PurePath(test_data, "schemas", "@jupyterlab", name) + dst = target / "schemas" / "@jupyterlab" / target_name if osp.exists(dst): shutil.rmtree(dst) shutil.copytree(src, dst) - with open(pjoin(target, "package.orig.json"), "w") as fid: + with open(target / "package.orig.json", "w") as fid: data = dict(name=target_name, jupyterlab=dict(extension=True)) json.dump(data, fid) # Copy the overrides file. - src = pjoin(test_data, "app-settings", "overrides.json") - dst = pjoin(str(app_settings_dir), "overrides.json") + src = pathlib.PurePath(test_data, "app-settings", "overrides.json") + dst = pathlib.PurePath(str(app_settings_dir), "overrides.json") if os.path.exists(dst): os.remove(dst) shutil.copyfile(src, dst) # Copy workspaces. - data = pjoin(test_data, "workspaces") + data = pathlib.PurePath(test_data, "workspaces") for item in os.listdir(data): - src = pjoin(data, item) - dst = pjoin(str(workspaces_dir), item) + src = data / item + dst = pathlib.PurePath(str(workspaces_dir), item) if os.path.exists(dst): os.remove(dst) shutil.copy(src, str(workspaces_dir))