Skip to content

Commit d0c3ec2

Browse files
authored
Clean up test suite (#41)
# Description Generally cleans up the test suite and speeds it up by having fewer `make_napari_viewer()` tests. The tests were mostly internal duplications, in the wrong file, or testing the same thing as another test.
1 parent 3b37a37 commit d0c3ec2

8 files changed

+283
-676
lines changed

pixi.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/test_bioio_plugin_utils.py

Lines changed: 33 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -1,169 +1,67 @@
1-
"""Tests for _bioio_plugin_utils module."""
1+
"""Tests for _bioio_plugin_utils module.
22
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
410

511

612
class TestSuggestPluginsForPath:
713
"""Test suggest_plugins_for_path function."""
814

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."""
2027
from ndevio._bioio_plugin_utils import suggest_plugins_for_path
2128

22-
plugins = suggest_plugins_for_path('test.lif')
29+
plugins = suggest_plugins_for_path(filename)
30+
assert plugins == expected_plugins
2331

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):
2833
"""Test that TIFF files suggest all TIFF-compatible plugins."""
2934
from ndevio._bioio_plugin_utils import suggest_plugins_for_path
3035

3136
plugins = suggest_plugins_for_path('test.tiff')
3237

33-
# Should get bioio-ome-tiff, bioio-tifffile, bioio-tiff-glob
38+
# TIFF has multiple compatible readers
3439
assert 'bioio-ome-tiff' in plugins
3540
assert 'bioio-tifffile' in plugins
3641
assert 'bioio-tiff-glob' in plugins
3742

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-
14343

14444
class TestFormatPluginInstallationMessage:
14545
"""Test format_plugin_installation_message function."""
14646

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."""
14949
from ndevio._bioio_plugin_utils import (
15050
format_plugin_installation_message,
151-
suggest_plugins_for_path,
15251
)
15352

154-
suggested = suggest_plugins_for_path('test.czi')
15553
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'],
16058
)
16159

162-
assert 'bioio-czi' in message
60+
assert 'bioio-nd2' in message
16361
assert 'pip install' in message or 'conda install' in message
16462

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."""
16765
from ndevio._bioio_plugin_utils import (
16866
format_plugin_installation_message,
16967
)

tests/test_napari_reader.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,8 @@ def test_reader_supported_formats(
7171
expected_dtype,
7272
expected_has_scale: bool,
7373
expected_num_layers: int,
74-
make_napari_viewer,
7574
) -> None:
7675
"""Test reader with formats that should work with core dependencies."""
77-
make_napari_viewer()
7876

7977
# Resolve filename to filepath
8078
if isinstance(filename, str):
@@ -233,14 +231,6 @@ def test_napari_get_reader_general_exception(caplog):
233231
assert 'Test exception' in caplog.text
234232

235233

236-
def test_napari_get_reader_png(resources_dir: Path) -> None:
237-
reader = napari_get_reader(
238-
str(resources_dir / PNG_FILE),
239-
)
240-
241-
assert callable(reader)
242-
243-
244234
def test_napari_get_reader_supported_formats_work(resources_dir: Path):
245235
"""Test that supported formats return valid readers."""
246236
# PNG should work (bioio-imageio is core)

tests/test_nimage.py

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from bioio_base.exceptions import UnsupportedFileFormatError
1515

1616
from ndevio import nImage
17-
from ndevio.nimage import determine_reader_plugin
1817

1918
RGB_TIFF = (
2019
'RGB_bad_metadata.tiff' # has two scenes, with really difficult metadata
@@ -204,10 +203,6 @@ def test_get_layer_data_tuples_ome_validation_error_logged(
204203
assert caplog.records[0].levelname == 'WARNING'
205204
assert 'Could not parse OME metadata' in caplog.records[0].message
206205
assert 'LatticeLightsheet' in caplog.records[0].message
207-
assert len(caplog.records) == 1
208-
assert caplog.records[0].levelname == 'WARNING'
209-
assert 'Could not parse OME metadata' in caplog.records[0].message
210-
assert 'LatticeLightsheet' in caplog.records[0].message
211206

212207

213208
def test_get_layer_data_tuples_ome_not_implemented_silent(
@@ -278,63 +273,6 @@ def test_get_layer_data_mosaic_tile_not_in_memory(
278273
assert img.napari_layer_data.shape == (3,)
279274

280275

281-
@pytest.mark.parametrize(
282-
('filename', 'should_work', 'expected_plugin_suggestion'),
283-
[
284-
(LOGO_PNG, True, None), # PNG works with bioio-imageio (core)
285-
(
286-
CELLS3D2CH_OME_TIFF,
287-
True,
288-
None,
289-
), # OME-TIFF works with bioio-ome-tiff (core)
290-
(CZI_FILE, True, None),
291-
(ND2_FILE, False, 'bioio-nd2'), # ND2 needs bioio-nd2
292-
(RGB_TIFF, True, None),
293-
],
294-
)
295-
def test_determine_reader_plugin_behavior(
296-
resources_dir: Path,
297-
filename: str,
298-
should_work: bool | str,
299-
expected_plugin_suggestion: str | None,
300-
):
301-
"""Test determine_reader_plugin with various file formats.
302-
303-
Parameters
304-
----------
305-
filename : str
306-
Test file name
307-
should_work : bool | "maybe"
308-
True = must succeed, False = must fail, "maybe" = can succeed or fail
309-
expected_plugin_suggestion : str | None
310-
If failure expected, the plugin name that should be suggested
311-
"""
312-
if should_work is True:
313-
# Must successfully determine a reader
314-
reader = determine_reader_plugin(resources_dir / filename)
315-
assert reader is not None
316-
elif should_work is False:
317-
# Must fail with helpful error message
318-
with pytest.raises(UnsupportedFileFormatError) as exc_info:
319-
determine_reader_plugin(resources_dir / filename)
320-
321-
error_msg = str(exc_info.value)
322-
assert filename in error_msg
323-
if expected_plugin_suggestion:
324-
assert expected_plugin_suggestion in error_msg
325-
assert 'pip install' in error_msg
326-
else: # "maybe"
327-
# Can succeed or fail; if fails, check for helpful message
328-
try:
329-
reader = determine_reader_plugin(resources_dir / filename)
330-
assert reader is not None
331-
except UnsupportedFileFormatError as e:
332-
error_msg = str(e)
333-
if expected_plugin_suggestion:
334-
assert expected_plugin_suggestion in error_msg
335-
assert 'pip install' in error_msg
336-
337-
338276
@pytest.mark.parametrize(
339277
('filename', 'should_work', 'expected_error_contains'),
340278
[

0 commit comments

Comments
 (0)