Skip to content

Commit 9697027

Browse files
committed
Added unit test for '_get_source' helper function
1 parent 825f1a4 commit 9697027

1 file changed

Lines changed: 27 additions & 7 deletions

File tree

tests/client/contexts/test_fib.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pytest
77
from pytest_mock import MockerFixture
88

9-
from murfey.client.contexts.fib import FIBContext, _number_from_name
9+
from murfey.client.contexts.fib import FIBContext, _get_source, _number_from_name
1010

1111
# -------------------------------------------------------------------------------------
1212
# FIBContext test utilty functions and fixtures
@@ -164,25 +164,32 @@ def create_fib_maps_xml_metadata(
164164

165165

166166
@pytest.fixture
167-
def fib_maps_metadata_file(tmp_path: Path):
167+
def visit_dir(tmp_path: Path):
168+
return tmp_path / "visit"
169+
170+
171+
@pytest.fixture
172+
def fib_maps_metadata_file(visit_dir: Path):
168173
metadata = create_fib_maps_xml_metadata(
169174
"test-project",
170175
fib_maps_test_datasets,
171176
)
172177
tree = ET.ElementTree(metadata)
173178
ET.indent(tree, space=" ")
174-
save_path = tmp_path / "EMproject.emxml"
179+
save_path = visit_dir / "maps/visit/EMproject.emxml"
180+
if not save_path.parent.exists():
181+
save_path.parent.mkdir(parents=True, exist_ok=True)
175182
tree.write(save_path, encoding="utf-8")
176183
return save_path
177184

178185

179186
@pytest.fixture
180-
def fib_maps_images(tmp_path: Path):
187+
def fib_maps_images(fib_maps_metadata_file: Path):
181188
image_list = []
182189
for dataset in fib_maps_test_datasets:
183190
name = str(dataset["name"])
184191
relative_path = str(dataset["relative_path"])
185-
file = tmp_path / relative_path / f"{name}.tiff"
192+
file = fib_maps_metadata_file.parent / relative_path / f"{name}.tiff"
186193
if not file.exists():
187194
file.parent.mkdir(parents=True, exist_ok=True)
188195
file.touch()
@@ -213,8 +220,21 @@ def test_number_from_name(test_params: tuple[str, int]):
213220
assert _number_from_name(name) == number
214221

215222

216-
def test_get_source():
217-
pass
223+
def test_get_source(
224+
tmp_path: Path,
225+
visit_dir: Path,
226+
fib_maps_images: list[Path],
227+
fib_maps_metadata_file: Path,
228+
):
229+
# Mock the MurfeyInstanceEnvironment
230+
mock_environment = MagicMock()
231+
mock_environment.sources = [
232+
visit_dir,
233+
tmp_path / "another_dir",
234+
]
235+
# Check that the correct source directory is found
236+
for file in [fib_maps_metadata_file, *fib_maps_images]:
237+
assert _get_source(file, mock_environment) == visit_dir
218238

219239

220240
def test_file_transferred_to():

0 commit comments

Comments
 (0)