-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tests for Scheduler job and job definition creation with input folder, refactor execution manager test #513
Add tests for Scheduler job and job definition creation with input folder, refactor execution manager test #513
Conversation
4689b25
to
adbde71
Compare
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for contributing this! I left some feedback below. The feedback mostly centers around using fixtures instead of hard-coded paths, so these fixtures can be easily re-used in future tests.
TEST_ROOT_DIR = f"{HERE}/jupyter_scheduler/tests/test_root_dir" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
os.path.join()
should be used to construct file paths, as the directory delimiter can be platform-dependent.- Windows uses backslashes instead of forward slashes, e.g.
C:\some_dir\child_dir
.
- Windows uses backslashes instead of forward slashes, e.g.
-
When using directories in tests, we should not commit the test dirs into the source repo, as this doesn't scale well when more tests are added. Instead, you should use the
tmp_path
fixture provided bypytest
. When used, this will create a new temporary directory (under/tmp
on Linux) and return the path to that temporary directory.So here you would want to replace
TEST_ROOT_DIR
with something like:@pytest.fixture def scheduler_root_dir(tmp_path): return os.path.join(tmp_path, 'workspace_root')
For DB_FILE_PATH
, you should use the jp_data_dir
fixture provided by jupyter_server.pytest_plugin
. This fixture is already under tmp_path
.
NOTEBOOK_NAME = "side_effects.ipynb" | ||
SIDE_EFECT_FILE_NAME = "output_side_effect.txt" | ||
|
||
NOTEBOOK_DIR = Path(__file__).resolve().parent / "test_staging_dir" / "job-4" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should have a fixture for the staging directory which uses the default staging directory name in Jupyter Scheduler:
@pytest.fixture
def staging_dir(jp_data_dir):
return os.path.join(jp_data_dir, "scheduler_staging_area")
For the side effect test:
- Move
output_side_effect.txt
andside_effects.ipynb
under a new directory containing static files used in tests, e.g.jupyter_scheduler/tests/static
. - Write a new
staging_dir_with_side_effects
fixture that copies these files tostaging_dir
, and returns a two-tuple of the input URI and the side effect file. So this fixture should return('side_effects.ipynb', 'output_side_effect.txt')
job = Job( | ||
runtime_environment_name="abc", | ||
input_filename=NOTEBOOK_NAME, | ||
job_id="123", | ||
job_id=JOB_ID, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of hard-coding the job ID, you should modify this fixture to return the ID of the job record it created. This is more similar to how jobs are created by the Scheduler backend.
def test_create_job_definition_with_input_folder(jp_scheduler): | ||
job_definition_id = jp_scheduler.create_job_definition( | ||
CreateJobDefinition( | ||
input_uri="job-5/import-helloworld.ipynb", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to my previous comment, you can replace this with a input_file_with_input_dir
fixture that moves import-helloworld.ipynb
and a/b/helloworld.txt
to scheduler_root_dir
, and then return the tuple ('import-helloworld.ipynb', 'a/b/helloworld.txt')
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for looking into this @dlqqq |
…lder, refactor execution manager test (jupyter-server#513) * use fixtures, rename job used to job-4 * test scheduler job creation and job def creation with input folder * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * remove duplciate fixture --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
…lder, refactor execution manager test (#513) (#515) * use fixtures, rename job used to job-4 * test scheduler job creation and job def creation with input folder * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * remove duplciate fixture --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Scheduler
job and job definition creation with input folderDefaultExecutionManager
test to use db fixtures