|
1 | | -"""Tests for _bioio_plugin_utils module.""" |
| 1 | +"""Tests for _bioio_plugin_utils module. |
2 | 2 |
|
3 | | -import logging |
| 3 | +This module tests: |
| 4 | +- suggest_plugins_for_path: maps file extensions to bioio plugin names |
| 5 | +- format_plugin_installation_message: formats installation instructions |
| 6 | +- BIOIO_PLUGINS: the plugin metadata registry |
| 7 | +""" |
| 8 | + |
| 9 | +import pytest |
4 | 10 |
|
5 | 11 |
|
6 | 12 | class TestSuggestPluginsForPath: |
7 | 13 | """Test suggest_plugins_for_path function.""" |
8 | 14 |
|
9 | | - def test_czi_file(self): |
10 | | - """Test that CZI file suggests bioio-czi.""" |
11 | | - from ndevio._bioio_plugin_utils import suggest_plugins_for_path |
12 | | - |
13 | | - plugins = suggest_plugins_for_path('test.czi') |
14 | | - |
15 | | - assert len(plugins) == 1 |
16 | | - assert plugins[0] == 'bioio-czi' |
17 | | - |
18 | | - def test_lif_file(self): |
19 | | - """Test that LIF file suggests bioio-lif.""" |
| 15 | + @pytest.mark.parametrize( |
| 16 | + ('filename', 'expected_plugins'), |
| 17 | + [ |
| 18 | + ('test.czi', ['bioio-czi']), |
| 19 | + ('test.lif', ['bioio-lif']), |
| 20 | + ('test.nd2', ['bioio-nd2']), |
| 21 | + ('test.dv', ['bioio-dv']), |
| 22 | + ('test.xyz', []), # Unsupported returns empty |
| 23 | + ], |
| 24 | + ) |
| 25 | + def test_extension_to_plugin_mapping(self, filename, expected_plugins): |
| 26 | + """Test that file extensions map to correct plugin suggestions.""" |
20 | 27 | from ndevio._bioio_plugin_utils import suggest_plugins_for_path |
21 | 28 |
|
22 | | - plugins = suggest_plugins_for_path('test.lif') |
| 29 | + plugins = suggest_plugins_for_path(filename) |
| 30 | + assert plugins == expected_plugins |
23 | 31 |
|
24 | | - assert len(plugins) == 1 |
25 | | - assert plugins[0] == 'bioio-lif' |
26 | | - |
27 | | - def test_tiff_file_suggests_all(self): |
| 32 | + def test_tiff_suggests_multiple_plugins(self): |
28 | 33 | """Test that TIFF files suggest all TIFF-compatible plugins.""" |
29 | 34 | from ndevio._bioio_plugin_utils import suggest_plugins_for_path |
30 | 35 |
|
31 | 36 | plugins = suggest_plugins_for_path('test.tiff') |
32 | 37 |
|
33 | | - # Should get bioio-ome-tiff, bioio-tifffile, bioio-tiff-glob |
| 38 | + # TIFF has multiple compatible readers |
34 | 39 | assert 'bioio-ome-tiff' in plugins |
35 | 40 | assert 'bioio-tifffile' in plugins |
36 | 41 | assert 'bioio-tiff-glob' in plugins |
37 | 42 |
|
38 | | - def test_unsupported_extension(self): |
39 | | - """Test that unsupported extensions return empty list.""" |
40 | | - from ndevio._bioio_plugin_utils import suggest_plugins_for_path |
41 | | - |
42 | | - plugins = suggest_plugins_for_path('test.xyz') |
43 | | - |
44 | | - assert len(plugins) == 0 |
45 | | - |
46 | | - |
47 | | -class TestReaderPluginManager: |
48 | | - """Test ReaderPluginManager class.""" |
49 | | - |
50 | | - def test_manager_filters_installed_plugins(self): |
51 | | - """Test that manager correctly identifies installable plugins.""" |
52 | | - from unittest.mock import Mock, patch |
53 | | - |
54 | | - from ndevio._plugin_manager import ReaderPluginManager |
55 | | - |
56 | | - # Mock feasibility report showing bioio-czi as installed |
57 | | - with patch('bioio.plugin_feasibility_report') as mock_report: |
58 | | - mock_report.return_value = { |
59 | | - 'bioio-czi': Mock(supported=False), |
60 | | - 'ArrayLike': Mock(supported=False), |
61 | | - } |
62 | | - |
63 | | - manager = ReaderPluginManager('test.czi') |
64 | | - |
65 | | - # bioio-czi should be in installed_plugins |
66 | | - assert 'bioio-czi' in manager.installed_plugins |
67 | | - |
68 | | - # bioio-czi should NOT be in installable_plugins (already installed) |
69 | | - assert 'bioio-czi' not in manager.installable_plugins |
70 | | - |
71 | | - def test_manager_suggests_uninstalled_plugins(self): |
72 | | - """Test that manager suggests uninstalled plugins.""" |
73 | | - from unittest.mock import Mock, patch |
74 | | - |
75 | | - from ndevio._plugin_manager import ReaderPluginManager |
76 | | - |
77 | | - # Mock feasibility report with no bioio-lif installed |
78 | | - with patch('bioio.plugin_feasibility_report') as mock_report: |
79 | | - mock_report.return_value = { |
80 | | - 'bioio-ome-tiff': Mock(supported=False), |
81 | | - 'ArrayLike': Mock(supported=False), |
82 | | - } |
83 | | - |
84 | | - manager = ReaderPluginManager('test.lif') |
85 | | - |
86 | | - # bioio-lif should be in suggested_plugins |
87 | | - assert 'bioio-lif' in manager.suggested_plugins |
88 | | - |
89 | | - # bioio-lif should also be in installable_plugins |
90 | | - assert 'bioio-lif' in manager.installable_plugins |
91 | | - |
92 | | - def test_manager_excludes_core_plugins_from_installable(self): |
93 | | - """Test that core plugins are excluded from installable list.""" |
94 | | - from unittest.mock import Mock, patch |
95 | | - |
96 | | - from ndevio._plugin_manager import ReaderPluginManager |
97 | | - |
98 | | - # Mock report showing no plugins installed |
99 | | - with patch('bioio.plugin_feasibility_report') as mock_report: |
100 | | - mock_report.return_value = { |
101 | | - 'ArrayLike': Mock(supported=False), |
102 | | - } |
103 | | - |
104 | | - manager = ReaderPluginManager('test.tiff') |
105 | | - |
106 | | - # Core plugins should not be in installable |
107 | | - installable_plugins = manager.installable_plugins |
108 | | - |
109 | | - # These are core plugins, shouldn't need installation |
110 | | - core_plugins = [ |
111 | | - 'bioio-ome-tiff', |
112 | | - 'bioio-imageio', |
113 | | - 'bioio-ome-zarr', |
114 | | - 'bioio-tifffile', |
115 | | - ] |
116 | | - for core in core_plugins: |
117 | | - assert core not in installable_plugins |
118 | | - |
119 | | - # bioio-tiff-glob is not core, should be installable |
120 | | - assert 'bioio-tiff-glob' in installable_plugins |
121 | | - |
122 | | - def test_get_working_reader_no_path_(self, caplog): |
123 | | - from ndevio._plugin_manager import ReaderPluginManager |
124 | | - |
125 | | - manager = ReaderPluginManager() # No path |
126 | | - |
127 | | - with caplog.at_level(logging.WARNING): |
128 | | - result = manager.get_working_reader() |
129 | | - |
130 | | - assert result is None |
131 | | - assert 'Cannot get working reader without a path' in caplog.text |
132 | | - |
133 | | - def test_get_installation_message_no_path_returns_empty(self): |
134 | | - """Test that get_installation_message returns empty string without path.""" |
135 | | - from ndevio._plugin_manager import ReaderPluginManager |
136 | | - |
137 | | - manager = ReaderPluginManager() # No path |
138 | | - |
139 | | - install_msg = manager.get_installation_message() |
140 | | - |
141 | | - assert install_msg == '' |
142 | | - |
143 | 43 |
|
144 | 44 | class TestFormatPluginInstallationMessage: |
145 | 45 | """Test format_plugin_installation_message function.""" |
146 | 46 |
|
147 | | - def test_czi_message_basic(self): |
148 | | - """Test message generation for CZI file.""" |
| 47 | + def test_message_with_installable_plugins(self): |
| 48 | + """Test message includes plugin name and install command.""" |
149 | 49 | from ndevio._bioio_plugin_utils import ( |
150 | 50 | format_plugin_installation_message, |
151 | | - suggest_plugins_for_path, |
152 | 51 | ) |
153 | 52 |
|
154 | | - suggested = suggest_plugins_for_path('test.czi') |
155 | 53 | message = format_plugin_installation_message( |
156 | | - filename='test.czi', |
157 | | - suggested_plugins=suggested, |
158 | | - installed_plugins=set(), |
159 | | - installable_plugins=suggested, |
| 54 | + filename='test.nd2', |
| 55 | + suggested_plugins=['bioio-nd2'], |
| 56 | + installed_plugins=set(), # Not installed |
| 57 | + installable_plugins=['bioio-nd2'], |
160 | 58 | ) |
161 | 59 |
|
162 | | - assert 'bioio-czi' in message |
| 60 | + assert 'bioio-nd2' in message |
163 | 61 | assert 'pip install' in message or 'conda install' in message |
164 | 62 |
|
165 | | - def test_unsupported_extension_message(self): |
166 | | - """Test message for completely unsupported extension.""" |
| 63 | + def test_message_for_unsupported_extension(self): |
| 64 | + """Test message for extension with no known plugins.""" |
167 | 65 | from ndevio._bioio_plugin_utils import ( |
168 | 66 | format_plugin_installation_message, |
169 | 67 | ) |
|
0 commit comments