Skip to content

Commit

Permalink
Update common test helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeNaccarato committed Sep 8, 2023
1 parent b45a849 commit 95eaeb6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
// * Changes below should persist in significant template updates.

{
"label": "proj: local pyrightconfig.json",
"label": "proj: local pyrightconfig",
"type": "process",
"command": "pwsh",
"args": ["-Command", "python .tools/scripts/local_pyrightconfig.py"],
Expand Down
29 changes: 8 additions & 21 deletions src/boilercore/testing.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"""Test helpers."""

from contextlib import contextmanager
from pathlib import Path
from shutil import copy, copytree
from types import ModuleType
from types import ModuleType, SimpleNamespace

import pytest
from ploomber_engine.ipython import PloomberClient
Expand All @@ -21,25 +20,13 @@ def get_session_path(
return session_path


def get_nb_client(request: pytest.FixtureRequest, session_path: Path):
"""Prepare a temporary working directory and return a notebook client."""
nb_source = request.param
def get_nb_namespace(nb_client: PloomberClient) -> SimpleNamespace:
"""Copy a notebook and get its namespace."""
return SimpleNamespace(**nb_client.get_namespace())


def get_nb_client(nb_source: Path, session_path: Path) -> PloomberClient:
"""Copy a notebook and get its client."""
nb = session_path / nb_source.name
copy(nb_source, nb)
return PloomberClient.from_path(nb)


def tmp_workdir(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
"""Prepare a temporary working directory."""
with before_tmp_workdir(tmp_path, monkeypatch):
...


@contextmanager
def before_tmp_workdir(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
"""Copy files over, allow changes, then change the working directory."""
try:
copytree(Path("tests") / "tmp_path", tmp_path, dirs_exist_ok=True)
yield
finally:
monkeypatch.chdir(tmp_path)

0 comments on commit 95eaeb6

Please sign in to comment.