Skip to content

Commit cd98ad8

Browse files
committed
Tests for finding context
1 parent be88af8 commit cd98ad8

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

src/murfey/client/analyser.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ def _find_context(self, file_path: Path) -> bool:
128128
elif (
129129
"Batch" in file_path.parts
130130
or "SearchMaps" in file_path.parts
131+
or "Thumbnails" in file_path.parts
131132
or file_path.name == "Session.dm"
132133
):
133134
self._context = TomographyMetadataContext("tomo", self._basepath)
@@ -160,6 +161,9 @@ def _find_context(self, file_path: Path) -> bool:
160161
# Tomography and SPA workflow checks
161162
split_file_name = file_path.name.split("_")
162163
if split_file_name:
164+
if "gain" in split_file_name[-1]:
165+
return False
166+
163167
# Files starting with "FoilHole" belong to the SPA workflow
164168
if split_file_name[0].startswith("FoilHole"):
165169
if not self._context:
@@ -175,6 +179,7 @@ def _find_context(self, file_path: Path) -> bool:
175179
or "Fractions" in split_file_name[-1]
176180
or "fractions" in split_file_name[-1]
177181
or "EER" in split_file_name[-1]
182+
or file_path.suffix == ".mdoc"
178183
):
179184
if not self._context:
180185
logger.info("Acquisition software: tomo")

tests/client/test_analyser.py

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

3+
import pytest
4+
35
from murfey.client.analyser import Analyser
6+
from murfey.client.contexts.spa import SPAModularContext
7+
from murfey.client.contexts.spa_metadata import SPAMetadataContext
8+
from murfey.client.contexts.tomo import TomographyContext
9+
from murfey.client.contexts.tomo_metadata import TomographyMetadataContext
10+
from murfey.util.models import ProcessingParametersSPA, ProcessingParametersTomo
11+
12+
example_files = [
13+
["visit/Position_1_001_0.0_20250715_012434_fractions.tiff", TomographyContext],
14+
["visit/Position_1_2_002_3.0_20250715_012434_Fractions.mrc", TomographyContext],
15+
["visit/Position_1_2_003_6.0_20250715_012434_EER.eer", TomographyContext],
16+
["visit/name1_004_9.0_20250715_012434_fractions.tiff", TomographyContext],
17+
["visit/Position_1_[30.0].tiff", TomographyContext],
18+
["visit/Position_1.mdoc", TomographyContext],
19+
["visit/name1_2.mdoc", TomographyContext],
20+
["visit/Session.dm", TomographyMetadataContext],
21+
["visit/SearchMaps/SearchMap.xml", TomographyMetadataContext],
22+
["visit/Batch/BatchPositionsList.xml", TomographyMetadataContext],
23+
["visit/Thumbnails/file.mrc", TomographyMetadataContext],
24+
["visit/FoilHole_01234_fractions.tiff", SPAModularContext],
25+
["atlas/atlas.mrc", SPAMetadataContext],
26+
["visit/EpuSession.dm", SPAMetadataContext],
27+
["visit/Metadata/GridSquare.dm", SPAMetadataContext],
28+
]
29+
30+
31+
@pytest.mark.parametrize("file_and_context", example_files)
32+
def test_find_context(file_and_context, tmp_path):
33+
file_name, context = file_and_context
34+
35+
analyser = Analyser(tmp_path)
36+
assert analyser._find_context(tmp_path / file_name)
37+
assert isinstance(analyser._context, context)
38+
if isinstance(analyser._context, TomographyContext):
39+
assert analyser.parameters_model == ProcessingParametersTomo
40+
if isinstance(analyser._context, SPAModularContext):
41+
assert analyser.parameters_model == ProcessingParametersSPA
42+
43+
44+
contextless_files = [
45+
"visit/Position_1_gain.tiff",
46+
"visit/FoilHole_01234_gain.tiff",
47+
"visit/file_1.mrc",
48+
]
49+
50+
51+
@pytest.mark.parametrize("bad_file", contextless_files)
52+
def test_ignore_contextless_files(bad_file, tmp_path):
53+
analyser = Analyser(tmp_path)
54+
assert not analyser._find_context(tmp_path / bad_file)
55+
assert not analyser._context
456

557

658
def test_analyser_setup_and_stopping(tmp_path):

0 commit comments

Comments
 (0)