Skip to content

Commit

Permalink
Merge pull request #6624 from kianelbo/conftest-pathlib
Browse files Browse the repository at this point in the history
Use pathlib instead of os.path.join in `tests/conftest.py`
  • Loading branch information
jtpio authored Nov 17, 2022
2 parents a0f7713 + b721d3f commit 707e9c4
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -89,37 +89,37 @@ 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)

# 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))
Expand Down

0 comments on commit 707e9c4

Please sign in to comment.