Skip to content

Commit 2ed7d56

Browse files
authored
Fix JFM tests (#424)
* fix JFM tests * pre-commit * add minor comment
1 parent b897aa5 commit 2ed7d56

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

jupyter_scheduler/job_files_manager.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,11 @@ def __init__(
5252

5353
def generate_filepaths(self):
5454
"""A generator that produces filepaths"""
55-
output_dir = self.output_dir
56-
if not os.path.exists(output_dir):
57-
os.makedirs(output_dir)
58-
5955
output_formats = self.output_formats + ["input"]
6056

6157
for output_format in output_formats:
6258
input_filepath = self.staging_paths[output_format]
63-
output_filename = self.output_filenames[output_format]
64-
output_filepath = os.path.join(output_dir, output_filename)
59+
output_filepath = os.path.join(self.output_dir, self.output_filenames[output_format])
6560
if not os.path.exists(output_filepath) or self.redownload:
6661
yield input_filepath, output_filepath
6762

@@ -74,9 +69,15 @@ def download_tar(self, archive_format: str = "tar"):
7469
tar.extractall(self.output_dir, filter="data")
7570

7671
def download(self):
72+
# ensure presence of staging paths
7773
if not self.staging_paths:
7874
return
7975

76+
# ensure presence of output dir
77+
output_dir = self.output_dir
78+
if not os.path.exists(output_dir):
79+
os.makedirs(output_dir)
80+
8081
if "tar" in self.staging_paths:
8182
self.download_tar()
8283
elif "tar.gz" in self.staging_paths:

jupyter_scheduler/tests/test_job_files_manager.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
import os
33
import shutil
44
import tarfile
5-
import tempfile
5+
import time
66
from pathlib import Path
77
from unittest.mock import patch
88

99
import pytest
1010

1111
from jupyter_scheduler.job_files_manager import Downloader, JobFilesManager
1212
from jupyter_scheduler.models import DescribeJob, JobFile
13-
from jupyter_scheduler.scheduler import BaseScheduler
1413

1514

1615
async def test_copy_from_staging():
@@ -68,6 +67,9 @@ async def test_copy_from_staging():
6867
def clear_outputs_dir():
6968
yield
7069
shutil.rmtree(OUTPUTS_DIR)
70+
# rmtree() is not synchronous; wait until it has finished running
71+
while os.path.isdir(OUTPUTS_DIR):
72+
time.sleep(0.01)
7173

7274

7375
@pytest.mark.parametrize(
@@ -76,9 +78,9 @@ def clear_outputs_dir():
7678
(
7779
["ipynb", "html"],
7880
{
79-
"ipynb": "helloworld-out.ipynb",
80-
"html": "helloworld-out.html",
81-
"input": "helloworld-input.ipynb",
81+
"ipynb": "job-1/helloworld-out.ipynb",
82+
"html": "job-1/helloworld-out.html",
83+
"input": "job-1/helloworld-input.ipynb",
8284
},
8385
{
8486
"ipynb": os.path.join(HERE, "test_staging_dir", "job-1", "helloworld-1.ipynb"),
@@ -91,9 +93,9 @@ def clear_outputs_dir():
9193
(
9294
["ipynb", "html"],
9395
{
94-
"ipynb": "helloworld-out.ipynb",
95-
"html": "helloworld-out.html",
96-
"input": "helloworld-input.ipynb",
96+
"ipynb": "job-2/helloworld-1.ipynb",
97+
"html": "job-2/helloworld-1.html",
98+
"input": "job-2/helloworld.ipynb",
9799
},
98100
{
99101
"tar.gz": os.path.join(HERE, "test_staging_dir", "job-2", "helloworld.tar.gz"),
@@ -120,10 +122,13 @@ def test_downloader_download(
120122

121123
assert os.path.exists(output_dir)
122124
for format in output_formats:
125+
# get path to output file corresponding to this format
123126
out_filepath = os.path.join(output_dir, output_filenames[format])
124127

128+
# assert each output file exists
125129
assert os.path.exists(out_filepath)
126130

131+
# assert integrity of each output file
127132
if "tar.gz" in staging_paths:
128133
with tarfile.open(staging_paths["tar.gz"]) as tar:
129134
input_file = tar.extractfile(member=staging_paths[format])

0 commit comments

Comments
 (0)