Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions httomo/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from contextlib import AbstractContextManager, nullcontext
from datetime import datetime
from pathlib import Path, PurePath
from shutil import copy
import sys
import tempfile
from typing import List, Optional, TextIO, Union, Any
Expand Down Expand Up @@ -345,7 +344,11 @@ def initialise_output_directory(pipeline: Union[Path, str]) -> None:

# If pipeline is a file path, copy it to output directory
if isinstance(pipeline, Path):
copy(pipeline, httomo.globals.run_out_dir)
with open(pipeline, "r") as input:
pipeline_contents = input.read()
with open(Path(httomo.globals.run_out_dir) / pipeline.name, "a") as output:
output.write(f"# Created with HTTomo version {__version__}\n")
output.write(pipeline_contents)
# If pipeline is a JSON string, write it to a file in the output directory
else:
with open(httomo.globals.run_out_dir / "pipeline.json", "w") as f:
Expand Down
14 changes: 6 additions & 8 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,27 +192,25 @@ def test_initialise_output_directory_handles_json_string(tmp_path):
assert written_content == json_string


def test_initialise_output_directory_handles_path_input(mocker, tmp_path):
def test_initialise_output_directory_handles_path_input(
mocker, tmp_path, standard_loader: str
):
"""Test that initialise_output_directory correctly handles Path input (existing behavior)."""
from httomo.cli import initialise_output_directory

# Set up the global output directory
output_dir = tmp_path / "output"
httomo.globals.run_out_dir = output_dir

# Mock copy to avoid actual file operations
mock_copy = mocker.patch("httomo.cli.copy")

pipeline_path = Path("some/pipeline.yaml")
pipeline_path = Path(__file__).parent.parent / standard_loader

# Call the function with a Path
initialise_output_directory(pipeline_path)

# Verify directory was created
assert output_dir.exists()

# Verify that copy was called for the file
mock_copy.assert_called_once_with(pipeline_path, output_dir)
# Verify that pipeline file was copied to output dir
assert (output_dir / pipeline_path.name).exists()


@pytest.mark.cupy
Expand Down
4 changes: 2 additions & 2 deletions tests/test_ui_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_can_read_cpu_pipeline(tomopy_gridrec: str):
assert pipline_stage_config[6]["method"] == "calculate_stats"
assert pipline_stage_config[6]["module_path"] == "httomo.methods"
assert pipline_stage_config[7]["method"] == "rescale_to_int"
assert pipline_stage_config[7]["module_path"] == "httomolibgpu.misc.rescale"
assert pipline_stage_config[7]["module_path"] == "httomolib.misc.rescale"
assert pipline_stage_config[8]["method"] == "save_to_images"
assert pipline_stage_config[8]["module_path"] == "httomolib.misc.images"

Expand All @@ -57,7 +57,7 @@ def test_can_read_gpu_pipeline(FBP3d_tomobar: str):
assert pipline_stage_config[6]["method"] == "calculate_stats"
assert pipline_stage_config[6]["module_path"] == "httomo.methods"
assert pipline_stage_config[7]["method"] == "rescale_to_int"
assert pipline_stage_config[7]["module_path"] == "httomolibgpu.misc.rescale"
assert pipline_stage_config[7]["module_path"] == "httomolib.misc.rescale"
assert pipline_stage_config[8]["method"] == "save_to_images"
assert pipline_stage_config[8]["module_path"] == "httomolib.misc.images"

Expand Down