11from __future__ import annotations
22
3+ import pytest
4+
35from murfey .client .analyser import Analyser
6+ from murfey .client .contexts .clem import CLEMContext
7+ from murfey .client .contexts .spa import SPAModularContext
8+ from murfey .client .contexts .spa_metadata import SPAMetadataContext
9+ from murfey .client .contexts .tomo import TomographyContext
10+ from murfey .client .contexts .tomo_metadata import TomographyMetadataContext
11+ from murfey .util .models import ProcessingParametersSPA , ProcessingParametersTomo
12+
13+ example_files = [
14+ # Tomography
15+ ["visit/Position_1_001_0.0_20250715_012434_fractions.tiff" , TomographyContext ],
16+ ["visit/Position_1_2_002_3.0_20250715_012434_Fractions.mrc" , TomographyContext ],
17+ ["visit/Position_1_2_003_6.0_20250715_012434_EER.eer" , TomographyContext ],
18+ ["visit/name1_004_9.0_20250715_012434_fractions.tiff" , TomographyContext ],
19+ ["visit/Position_1_[30.0].tiff" , TomographyContext ],
20+ ["visit/Position_1.mdoc" , TomographyContext ],
21+ ["visit/name1_2.mdoc" , TomographyContext ],
22+ # Tomography metadata
23+ ["visit/Session.dm" , TomographyMetadataContext ],
24+ ["visit/SearchMaps/SearchMap.xml" , TomographyMetadataContext ],
25+ ["visit/Batch/BatchPositionsList.xml" , TomographyMetadataContext ],
26+ ["visit/Thumbnails/file.mrc" , TomographyMetadataContext ],
27+ # SPA
28+ ["visit/FoilHole_01234_fractions.tiff" , SPAModularContext ],
29+ ["visit/FoilHole_01234_EER.eer" , SPAModularContext ],
30+ # SPA metadata
31+ ["atlas/atlas.mrc" , SPAMetadataContext ],
32+ ["visit/EpuSession.dm" , SPAMetadataContext ],
33+ ["visit/Metadata/GridSquare.dm" , SPAMetadataContext ],
34+ # CLEM LIF file
35+ ["visit/images/test_file.lif" , CLEMContext ],
36+ # CLEM TIFF files
37+ [
38+ "visit/images/2024_03_14_12_34_56--Project001/grid1/Position 12--Z02--C01.tif" ,
39+ CLEMContext ,
40+ ],
41+ [
42+ "visit/images/2024_03_14_12_34_56--Project001/grid1/Position 12_Lng_LVCC--Z02--C01.tif" ,
43+ CLEMContext ,
44+ ],
45+ [
46+ "visit/images/2024_03_14_12_34_56--Project001/grid1/Series001--Z00--C00.tif" ,
47+ CLEMContext ,
48+ ],
49+ [
50+ "visit/images/2024_03_14_12_34_56--Project001/grid1/Series001_Lng_LVCC--Z00--C00.tif" ,
51+ CLEMContext ,
52+ ],
53+ # CLEM TIFF file accompanying metadata
54+ [
55+ "visit/images/2024_03_14_12_34_56--Project001/grid1/Metadata/Position 12.xlif" ,
56+ CLEMContext ,
57+ ],
58+ [
59+ "visit/images/2024_03_14_12_34_56--Project001/grid1/Metadata/Position 12_Lng_LVCC.xlif" ,
60+ CLEMContext ,
61+ ],
62+ [
63+ "visit/images/2024_03_14_12_34_56--Project001/grid1/Position 12/Metadata/Position 12_histo.xlif" ,
64+ CLEMContext ,
65+ ],
66+ [
67+ "visit/images/2024_03_14_12_34_56--Project001/grid1/Position 12/Metadata/Position 12_Lng_LVCC_histo.xlif" ,
68+ CLEMContext ,
69+ ],
70+ [
71+ "visit/images/2024_03_14_12_34_56--Project001/grid1/Metadata/Series001.xlif" ,
72+ CLEMContext ,
73+ ],
74+ [
75+ "visit/images/2024_03_14_12_34_56--Project001/grid1/Metadata/Series001_Lng_LVCC.xlif" ,
76+ CLEMContext ,
77+ ],
78+ ]
79+
80+
81+ @pytest .mark .parametrize ("file_and_context" , example_files )
82+ def test_find_context (file_and_context , tmp_path ):
83+ # Unpack parametrised variables
84+ file_name , context = file_and_context
85+
86+ # Pass the file to the Analyser; add environment as needed
87+ analyser = Analyser (basepath_local = tmp_path )
88+
89+ # Check that the results are as expected
90+ assert analyser ._find_context (tmp_path / file_name )
91+ assert isinstance (analyser ._context , context )
92+
93+ # Checks for the specific workflow contexts
94+ if isinstance (analyser ._context , TomographyContext ):
95+ assert analyser .parameters_model == ProcessingParametersTomo
96+ if isinstance (analyser ._context , SPAModularContext ):
97+ assert analyser .parameters_model == ProcessingParametersSPA
98+
99+
100+ contextless_files = [
101+ "visit/Position_1_gain.tiff" ,
102+ "visit/FoilHole_01234_gain.tiff" ,
103+ "visit/file_1.mrc" ,
104+ "visit/FoilHole_01234.mrc" ,
105+ "visit/FoilHole_01234.jpg" ,
106+ "visit/FoilHole_01234.xml" ,
107+ "visit/images/test_file.lifext" ,
108+ "visit/images/2024_03_14_12_34_56--Project001/Project001.xlef" ,
109+ "visit/images/2024_03_14_12_34_56--Project001/Project001.xlef.lock" ,
110+ "visit/images/2024_03_14_12_34_56--Project001/grid1/Position 12/Position 12_histo.lof" ,
111+ "visit/images/2024_03_14_12_34_56--Project001/grid1/Position 12/Series001_histo.lof" ,
112+ ]
113+
114+
115+ @pytest .mark .parametrize ("bad_file" , contextless_files )
116+ def test_ignore_contextless_files (bad_file , tmp_path ):
117+ analyser = Analyser (tmp_path )
118+ assert not analyser ._find_context (tmp_path / bad_file )
119+ assert not analyser ._context
4120
5121
6122def test_analyser_setup_and_stopping (tmp_path ):
@@ -23,7 +139,7 @@ def test_analyser_tomo_determination(tmp_path):
23139
24140
25141def test_analyser_epu_determination (tmp_path ):
26- tomo_file = tmp_path / "FoilHole_12345_Data_6789 .tiff"
142+ tomo_file = tmp_path / "FoilHole_12345_Data_6789_Fractions .tiff"
27143 analyser = Analyser (tmp_path )
28144 analyser .start ()
29145 analyser .queue .put (tomo_file )
0 commit comments