Skip to content

Commit

Permalink
create test dirs by copying test files from static dir into temp dirs…
Browse files Browse the repository at this point in the history
… instead of uploading test dirs for execution manager test
  • Loading branch information
andrii-i committed May 6, 2024
1 parent e55be92 commit 8223f6c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
5 changes: 5 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
TEST_ROOT_DIR = f"{HERE}/jupyter_scheduler/tests/test_root_dir"


@pytest.fixture
def static_test_files_dir():
return HERE / "jupyter_scheduler" / "tests" / "static"


@pytest.fixture
def jp_scheduler_root_dir(tmp_path):
root_dir = tmp_path / "workspace_root"
Expand Down
43 changes: 24 additions & 19 deletions jupyter_scheduler/tests/test_execution_manager.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
from pathlib import Path

import shutil
import pytest
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from jupyter_scheduler.executors import DefaultExecutionManager
from jupyter_scheduler.orm import Job

NOTEBOOK_NAME = "side_effects.ipynb"
SIDE_EFECT_FILE_NAME = "output_side_effect.txt"

NOTEBOOK_DIR = Path(__file__).resolve().parent / "test_staging_dir" / "job-4"
NOTEBOOK_PATH = NOTEBOOK_DIR / NOTEBOOK_NAME
SIDE_EFFECT_FILE = NOTEBOOK_DIR / SIDE_EFECT_FILE_NAME


@pytest.fixture
def staging_dir_with_side_effects(jp_scheduler_staging_dir):
return ("side_effects.ipynb", "output_side_effect.txt")
def staging_dir_with_side_effects(jp_scheduler_staging_dir, static_test_files_dir):
job_staging_dir = jp_scheduler_staging_dir / "job-4"
job_staging_dir.mkdir()
notebook_file_path = static_test_files_dir / "side_effects.ipynb"
side_effect_file_path = static_test_files_dir / "output_side_effect.txt"
shutil.copy2(notebook_file_path, job_staging_dir)
shutil.copy2(side_effect_file_path, job_staging_dir)

return (notebook_file_path, side_effect_file_path)


@pytest.fixture
def side_effects_job_record(jp_scheduler_db, staging_dir_with_side_effects):
notebook_name = staging_dir_with_side_effects[0]
def side_effects_job_record(staging_dir_with_side_effects, jp_scheduler_db):
notebook_name = staging_dir_with_side_effects[0].name
job = Job(
runtime_environment_name="abc",
input_filename=notebook_name,
Expand All @@ -33,16 +30,24 @@ def side_effects_job_record(jp_scheduler_db, staging_dir_with_side_effects):


def test_add_side_effects_files(
jp_scheduler_db, side_effects_job_record, jp_scheduler_db_url, jp_scheduler_root_dir
side_effects_job_record,
staging_dir_with_side_effects,
jp_scheduler_root_dir,
jp_scheduler_db_url,
jp_scheduler_db,
):
job_id = side_effects_job_record
staged_notebook_file_path = staging_dir_with_side_effects[0]
staged_notebook_dir = staged_notebook_file_path.parent
side_effect_file_name = staging_dir_with_side_effects[1].name

manager = DefaultExecutionManager(
job_id=job_id,
root_dir=jp_scheduler_root_dir,
db_url=jp_scheduler_db_url,
staging_paths={"input": str(NOTEBOOK_PATH)},
staging_paths={"input": staged_notebook_file_path},
)
manager.add_side_effects_files(str(NOTEBOOK_DIR))
manager.add_side_effects_files(staged_notebook_dir)

job = jp_scheduler_db.query(Job).filter(Job.job_id == job_id).one()
assert SIDE_EFECT_FILE_NAME in job.packaged_files
assert side_effect_file_name in job.packaged_files

0 comments on commit 8223f6c

Please sign in to comment.