|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import os |
| 4 | +import subprocess |
4 | 5 | from unittest import mock |
5 | 6 |
|
6 | 7 | import pytest |
@@ -188,6 +189,7 @@ def test_denoise_local_topaz_service( |
188 | 189 | "tomogram": f"{tmp_path}/Denoise/job007/denoised/test_stack_aretomo.denoised.mrc", |
189 | 190 | "output_dir": f"{tmp_path}/Segmentation/job008/tomograms", |
190 | 191 | "pixel_size": "1.0", |
| 192 | + "copy_output": False, |
191 | 193 | "relion_options": output_relion_options, |
192 | 194 | }, |
193 | 195 | ) |
@@ -216,9 +218,18 @@ def test_denoise_local_subprocess_service( |
216 | 218 | This should call the mock subprocess then send messages on to |
217 | 219 | the membrain-seg and images services. |
218 | 220 | """ |
219 | | - mock_subprocess().returncode = 0 |
220 | | - mock_subprocess().stdout = "stdout".encode("ascii") |
221 | | - mock_subprocess().stderr = "stderr".encode("ascii") |
| 221 | + |
| 222 | + def touch_denoise_output(*args, **kwargs): |
| 223 | + (tmp_path / "Denoise/job007/denoised").mkdir(parents=True, exist_ok=True) |
| 224 | + (tmp_path / "Denoise/job007/denoised/test_stack_aretomo.denoised.mrc").touch() |
| 225 | + return subprocess.CompletedProcess( |
| 226 | + "", |
| 227 | + returncode=0, |
| 228 | + stdout="stdout".encode("ascii"), |
| 229 | + stderr="stderr".encode("ascii"), |
| 230 | + ) |
| 231 | + |
| 232 | + mock_subprocess.side_effect = touch_denoise_output |
222 | 233 |
|
223 | 234 | header = { |
224 | 235 | "message-id": mock.sentinel, |
@@ -250,6 +261,7 @@ def test_denoise_local_subprocess_service( |
250 | 261 | "patch_size": 96, |
251 | 262 | "patch_padding": 48, |
252 | 263 | "device": "-2", |
| 264 | + "copy_output": True, |
253 | 265 | "relion_options": {"pixel_size_downscaled": 1}, |
254 | 266 | } |
255 | 267 | output_relion_options = dict(RelionServiceOptions()) |
@@ -310,7 +322,10 @@ def test_denoise_local_subprocess_service( |
310 | 322 | "-d", |
311 | 323 | "-2", |
312 | 324 | ] |
313 | | - mock_subprocess.assert_any_call(denoise_command, capture_output=True) |
| 325 | + mock_subprocess.assert_called_once_with(denoise_command, capture_output=True) |
| 326 | + |
| 327 | + # Check output copy |
| 328 | + assert (tmp_path / "Denoise/test_stack_aretomo.denoised.mrc").is_file() |
314 | 329 |
|
315 | 330 | # Check the images service request |
316 | 331 | assert offline_transport.send.call_count == 6 |
@@ -356,6 +371,7 @@ def test_denoise_local_subprocess_service( |
356 | 371 | "tomogram": f"{tmp_path}/Denoise/job007/denoised/test_stack_aretomo.denoised.mrc", |
357 | 372 | "output_dir": f"{tmp_path}/Segmentation/job008/tomograms", |
358 | 373 | "pixel_size": "1.0", |
| 374 | + "copy_output": True, |
359 | 375 | "relion_options": output_relion_options, |
360 | 376 | }, |
361 | 377 | ) |
@@ -568,6 +584,7 @@ def write_denoised_files(**kwargs): |
568 | 584 | "tomogram": f"{tmp_path}/cm12345-6/Denoise/job007/denoised/test_stack_aretomo.denoised.mrc", |
569 | 585 | "output_dir": f"{tmp_path}/cm12345-6/Segmentation/job008/tomograms", |
570 | 586 | "pixel_size": "1.0", |
| 587 | + "copy_output": False, |
571 | 588 | "relion_options": output_relion_options, |
572 | 589 | }, |
573 | 590 | ) |
@@ -654,6 +671,7 @@ def test_denoise_local_topaz_service_rerun( |
654 | 671 | "tomogram": f"{tmp_path}/Denoise/job007/denoised/test_stack_aretomo.denoised.mrc", |
655 | 672 | "output_dir": f"{tmp_path}/Segmentation/job008/tomograms", |
656 | 673 | "pixel_size": "1.0", |
| 674 | + "copy_output": False, |
657 | 675 | "relion_options": output_relion_options, |
658 | 676 | }, |
659 | 677 | ) |
|
0 commit comments