Skip to content

Commit 82440c6

Browse files
committed
fix utils and func unit tests
1 parent 16354b8 commit 82440c6

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

src/rbc/core/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ def get_base_entities(
4848
def rename(in_file: str | Path, new_name: str) -> Path:
4949
"""Rename a file, keeping it in the same directory."""
5050
in_file = Path(in_file)
51-
target = in_file.with_name(new_name)
51+
target = in_file.parent / Path(new_name).name
5252
if in_file == target:
5353
return in_file
54+
if target.exists():
55+
raise FileExistsError(f"Target file {target} already exists.")
5456
return Path(shutil.move(str(in_file), str(target)))
5557

5658

tests/unit/test_func.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
"""Unit tests for functional workflow."""
22

3+
import shutil
4+
import pytest
35
from types import SimpleNamespace
46

57
from niwrap import afni
68

79
from rbc.core import functional
810

11+
DOCKER_MISSING = shutil.which("docker") is None
912

1013
class TestFuncInitialization:
1114
"""Test suite for functional workflow initialization."""
@@ -16,6 +19,7 @@ def test_truncate_string_logic(self) -> None:
1619
selector = f"[{start_tr}..$]"
1720
assert selector == "[4..$]"
1821

22+
@pytest.mark.skipif(DOCKER_MISSING, reason="Docker is required")
1923
def test_truncate_to_min_volume(self, test_subject: SimpleNamespace) -> None:
2024
"""Test truncating to minimum volume count of 1."""
2125
original_info = afni.v_3dinfo(dataset=[test_subject.bold], nv=True)
@@ -41,6 +45,7 @@ def test_middle_index_logic(self) -> None:
4145
results = [nv // 2 for nv in volumes_list]
4246
assert results == [50, 50, 1, 0]
4347

48+
@pytest.mark.skipif(DOCKER_MISSING, reason="Docker is required")
4449
def test_motion_reference_volume_count(self, test_subject: SimpleNamespace) -> None:
4550
"""Test motion reference volume count is 1."""
4651
reference = functional.generate_motion_reference(

0 commit comments

Comments
 (0)