Skip to content

Commit 110a94e

Browse files
committed
Add httomo version comment to pipeline file copied to output dir
1 parent 13f2757 commit 110a94e

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

‎httomo/cli.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from contextlib import AbstractContextManager, nullcontext
22
from datetime import datetime
33
from pathlib import Path, PurePath
4-
from shutil import copy
54
import sys
65
import tempfile
76
from typing import List, Optional, TextIO, Union, Any
@@ -340,7 +339,11 @@ def initialise_output_directory(pipeline: Union[Path, str]) -> None:
340339

341340
# If pipeline is a file path, copy it to output directory
342341
if isinstance(pipeline, Path):
343-
copy(pipeline, httomo.globals.run_out_dir)
342+
with open(pipeline, "r") as input:
343+
pipeline_contents = input.read()
344+
with open(Path(httomo.globals.run_out_dir) / pipeline.name, "a") as output:
345+
output.write(f"# Created with HTTomo version {__version__}\n")
346+
output.write(pipeline_contents)
344347
# If pipeline is a JSON string, write it to a file in the output directory
345348
else:
346349
with open(httomo.globals.run_out_dir / "pipeline.json", "w") as f:

‎tests/test_cli.py‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,27 +192,25 @@ def test_initialise_output_directory_handles_json_string(tmp_path):
192192
assert written_content == json_string
193193

194194

195-
def test_initialise_output_directory_handles_path_input(mocker, tmp_path):
195+
def test_initialise_output_directory_handles_path_input(
196+
mocker, tmp_path, standard_loader: str
197+
):
196198
"""Test that initialise_output_directory correctly handles Path input (existing behavior)."""
197199
from httomo.cli import initialise_output_directory
198200

199201
# Set up the global output directory
200202
output_dir = tmp_path / "output"
201203
httomo.globals.run_out_dir = output_dir
202-
203-
# Mock copy to avoid actual file operations
204-
mock_copy = mocker.patch("httomo.cli.copy")
205-
206-
pipeline_path = Path("some/pipeline.yaml")
204+
pipeline_path = Path(__file__).parent.parent / standard_loader
207205

208206
# Call the function with a Path
209207
initialise_output_directory(pipeline_path)
210208

211209
# Verify directory was created
212210
assert output_dir.exists()
213211

214-
# Verify that copy was called for the file
215-
mock_copy.assert_called_once_with(pipeline_path, output_dir)
212+
# Verify that pipeline file was copied to output dir
213+
assert (output_dir / pipeline_path.name).exists()
216214

217215

218216
@pytest.mark.cupy

0 commit comments

Comments
 (0)