Skip to content

Commit 1c5a54d

Browse files
committed
fix test_copy_from_staging test case
1 parent ee52e43 commit 1c5a54d

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from pathlib import Path
2+
from unittest.mock import AsyncMock
23

34
import pytest
45
from sqlalchemy import create_engine
@@ -59,6 +60,7 @@ def jp_scheduler(jp_scheduler_db_url, jp_scheduler_root_dir, jp_scheduler_db):
5960
db_url=jp_scheduler_db_url,
6061
root_dir=str(jp_scheduler_root_dir),
6162
environments_manager=MockEnvironmentManager(),
63+
dask_client_future=AsyncMock(),
6264
)
6365

6466

jupyter_scheduler/tests/test_job_files_manager.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1+
import asyncio
12
import filecmp
23
import os
34
import shutil
45
import tarfile
5-
import time
6-
from pathlib import Path
7-
from unittest.mock import patch
6+
from unittest.mock import MagicMock, patch
87

98
import pytest
109

@@ -41,23 +40,25 @@ async def test_copy_from_staging():
4140
}
4241
output_dir = "jobs/1"
4342
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
50-
manager = JobFilesManager(scheduler=mock_scheduler)
51-
await manager.copy_from_staging(1)
52-
53-
mock_downloader.assert_called_once_with(
54-
output_formats=job.output_formats,
55-
output_filenames=job_filenames,
56-
staging_paths=staging_paths,
57-
output_dir=output_dir,
58-
redownload=False,
59-
include_staging_files=None,
60-
)
43+
with patch("jupyter_scheduler.scheduler.Scheduler") as mock_scheduler:
44+
mock_future = asyncio.Future()
45+
mock_future.set_result(MagicMock())
46+
mock_scheduler.dask_client_future = mock_future
47+
mock_scheduler.get_job.return_value = job
48+
mock_scheduler.get_staging_paths.return_value = staging_paths
49+
mock_scheduler.get_local_output_path.return_value = output_dir
50+
mock_scheduler.get_job_filenames.return_value = job_filenames
51+
manager = JobFilesManager(scheduler=mock_scheduler)
52+
await manager.copy_from_staging(1)
53+
54+
mock_downloader.assert_called_once_with(
55+
output_formats=job.output_formats,
56+
output_filenames=job_filenames,
57+
staging_paths=staging_paths,
58+
output_dir=output_dir,
59+
redownload=False,
60+
include_staging_files=None,
61+
)
6162

6263

6364
@pytest.fixture

0 commit comments

Comments
 (0)