2
2
import os
3
3
import shutil
4
4
import tarfile
5
- import tempfile
5
+ import time
6
6
from pathlib import Path
7
7
from unittest .mock import patch
8
8
9
9
import pytest
10
10
11
11
from jupyter_scheduler .job_files_manager import Downloader , JobFilesManager
12
12
from jupyter_scheduler .models import DescribeJob , JobFile
13
- from jupyter_scheduler .scheduler import BaseScheduler
14
13
15
14
16
15
async def test_copy_from_staging ():
@@ -68,6 +67,9 @@ async def test_copy_from_staging():
68
67
def clear_outputs_dir ():
69
68
yield
70
69
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 )
71
73
72
74
73
75
@pytest .mark .parametrize (
@@ -76,9 +78,9 @@ def clear_outputs_dir():
76
78
(
77
79
["ipynb" , "html" ],
78
80
{
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" ,
82
84
},
83
85
{
84
86
"ipynb" : os .path .join (HERE , "test_staging_dir" , "job-1" , "helloworld-1.ipynb" ),
@@ -91,9 +93,9 @@ def clear_outputs_dir():
91
93
(
92
94
["ipynb" , "html" ],
93
95
{
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" ,
97
99
},
98
100
{
99
101
"tar.gz" : os .path .join (HERE , "test_staging_dir" , "job-2" , "helloworld.tar.gz" ),
@@ -120,10 +122,13 @@ def test_downloader_download(
120
122
121
123
assert os .path .exists (output_dir )
122
124
for format in output_formats :
125
+ # get path to output file corresponding to this format
123
126
out_filepath = os .path .join (output_dir , output_filenames [format ])
124
127
128
+ # assert each output file exists
125
129
assert os .path .exists (out_filepath )
126
130
131
+ # assert integrity of each output file
127
132
if "tar.gz" in staging_paths :
128
133
with tarfile .open (staging_paths ["tar.gz" ]) as tar :
129
134
input_file = tar .extractfile (member = staging_paths [format ])
0 commit comments