4
4
import tarfile
5
5
import time
6
6
from pathlib import Path
7
- from unittest .mock import patch
7
+ from unittest .mock import patch , MagicMock
8
8
9
9
import pytest
10
10
@@ -40,13 +40,20 @@ async def test_copy_from_staging():
40
40
"input" : "helloworld.ipynb" ,
41
41
}
42
42
output_dir = "jobs/1"
43
+
44
+ mock_scheduler = MagicMock ()
45
+ mock_scheduler .get_job .return_value = job
46
+ mock_scheduler .get_staging_paths .return_value = staging_paths
47
+ mock_scheduler .get_local_output_path .return_value = output_dir
48
+ mock_scheduler .get_job_filenames .return_value = job_filenames
49
+
50
+ mock_context = MagicMock ()
51
+ mock_process = MagicMock ()
52
+ mock_context .Process .return_value = mock_process
53
+
43
54
with patch ("jupyter_scheduler.job_files_manager.Downloader" ) as mock_downloader :
44
- with patch ("jupyter_scheduler.job_files_manager.Process" ) as mock_process :
45
- with patch ("jupyter_scheduler.scheduler.Scheduler" ) as mock_scheduler :
46
- mock_scheduler .get_job .return_value = job
47
- mock_scheduler .get_staging_paths .return_value = staging_paths
48
- mock_scheduler .get_local_output_path .return_value = output_dir
49
- mock_scheduler .get_job_filenames .return_value = job_filenames
55
+ with patch ("jupyter_scheduler.scheduler.Scheduler" , return_value = mock_scheduler ):
56
+ with patch ("multiprocessing.get_context" , return_value = mock_context ):
50
57
manager = JobFilesManager (scheduler = mock_scheduler )
51
58
await manager .copy_from_staging (1 )
52
59
@@ -58,6 +65,7 @@ async def test_copy_from_staging():
58
65
redownload = False ,
59
66
include_staging_files = None ,
60
67
)
68
+ mock_process .start .assert_called_once ()
61
69
62
70
63
71
HERE = Path (__file__ ).parent .resolve ()
0 commit comments