|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +import pytest |
| 4 | + |
3 | 5 | 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 |
4 | 56 |
|
5 | 57 |
|
6 | 58 | def test_analyser_setup_and_stopping(tmp_path): |
|
0 commit comments