Skip to content

Commit 7852f04

Browse files
committed
Added tests for '_analyse' for the CLEM, FIB, and SXT workflows, as well as for contextless files
1 parent ee8a175 commit 7852f04

1 file changed

Lines changed: 112 additions & 6 deletions

File tree

tests/client/test_analyser.py

Lines changed: 112 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from __future__ import annotations
22

3+
from pathlib import Path
4+
35
import pytest
6+
from pytest_mock import MockerFixture
47

58
from murfey.client.analyser import Analyser
69
from murfey.client.contexts.spa import SPAContext
@@ -143,16 +146,119 @@ def test_analyser_epu_determination(tmp_path):
143146
assert analyser._context._acquisition_software == "epu"
144147

145148

146-
def test_analyse_clem():
147-
pass
149+
@pytest.mark.parametrize("test_file", contextless_files)
150+
def test_analyse_no_context(
151+
test_file: str,
152+
mocker: MockerFixture,
153+
tmp_path: Path,
154+
):
155+
# Mock the 'post_transfer' class function
156+
mock_post_transfer = mocker.patch.object(Analyser, "post_transfer")
157+
spy_find_context = mocker.spy(Analyser, "_find_context")
148158

159+
# Initialise the Analyser
160+
analyser = Analyser(tmp_path, "")
161+
analyser._analyse(tmp_path / test_file)
149162

150-
def test_analyse_fib():
151-
pass
163+
# "_find_context" should be called
164+
assert spy_find_context.call_count == 1
152165

166+
# "post_transfer" should not be called
167+
mock_post_transfer.assert_not_called()
153168

154-
def test_analyse_sxt():
155-
pass
169+
170+
def test_analyse_clem(
171+
mocker: MockerFixture,
172+
tmp_path: Path,
173+
):
174+
# Gather example files related to the CLEM workflow
175+
test_files = [
176+
file
177+
for context, file_list in example_files.items()
178+
for file in file_list
179+
if context == "CLEMContext" and not file.endswith(".lif")
180+
]
181+
182+
# Mock the 'post_transfer' class function
183+
mock_post_transfer = mocker.patch.object(Analyser, "post_transfer")
184+
spy_find_context = mocker.spy(Analyser, "_find_context")
185+
186+
# Initialise the Analyser
187+
analyser = Analyser(tmp_path, "")
188+
for file in test_files:
189+
analyser._analyse(tmp_path / file)
190+
191+
# "_find_context" should be called only once
192+
assert spy_find_context.call_count == 1
193+
assert analyser._context is not None and "CLEMContext" in str(analyser._context)
194+
195+
# "_post_transfer" should be called on every one of these files
196+
assert mock_post_transfer.call_count == len(test_files)
197+
198+
199+
@pytest.mark.parametrize(
200+
"test_params",
201+
# Test the "autotem" and "maps" workflows separately
202+
[
203+
[software, [file for file in file_list if software in file]]
204+
for software in ("autotem", "maps")
205+
for context, file_list in example_files.items()
206+
if context == "FIBContext"
207+
],
208+
)
209+
def test_analyse_fib(
210+
mocker: MockerFixture,
211+
test_params: tuple[str, list[str]],
212+
tmp_path: Path,
213+
):
214+
# Unpack test params
215+
software, test_files = test_params
216+
217+
# Mock the 'post_transfer' class function
218+
mock_post_transfer = mocker.patch.object(Analyser, "post_transfer")
219+
spy_find_context = mocker.spy(Analyser, "_find_context")
220+
221+
# Initialise the Analyser
222+
analyser = Analyser(tmp_path, "")
223+
for file in test_files:
224+
analyser._analyse(tmp_path / file)
225+
226+
# "_find_context" should be called only once
227+
assert spy_find_context.call_count == 1
228+
assert analyser._context is not None and "FIBContext" in str(analyser._context)
229+
assert analyser._context._acquisition_software == software
230+
231+
# "_post_transfer" should be called on every one of these files
232+
assert mock_post_transfer.call_count == len(test_files)
233+
234+
235+
def test_analyse_sxt(
236+
mocker: MockerFixture,
237+
tmp_path: Path,
238+
):
239+
# Load the example files corresponding to the SXT workflow
240+
test_files = [
241+
file
242+
for context, file_list in example_files.items()
243+
for file in file_list
244+
if context == "SXTContext"
245+
]
246+
247+
# Mock the 'post_transfer' class function
248+
mock_post_transfer = mocker.patch.object(Analyser, "post_transfer")
249+
spy_find_context = mocker.spy(Analyser, "_find_context")
250+
251+
# Initialise the Analyser
252+
analyser = Analyser(tmp_path, "")
253+
for file in test_files:
254+
analyser._analyse(tmp_path / file)
255+
256+
# "_find_context" should be called only once
257+
assert spy_find_context.call_count == 1
258+
assert analyser._context is not None and "SXTContext" in str(analyser._context)
259+
260+
# "_post_transfer" should be called on every one of these files
261+
assert mock_post_transfer.call_count == len(test_files)
156262

157263

158264
def test_analyse_spa():

0 commit comments

Comments
 (0)