-
Notifications
You must be signed in to change notification settings - Fork 6
Added tests for 100% coverage #416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,5 @@ | ||||||||||||
| from collections.abc import Callable | ||||||||||||
| from unittest.mock import MagicMock | ||||||||||||
|
|
||||||||||||
| import numpy as np | ||||||||||||
| import pytest | ||||||||||||
|
|
@@ -320,6 +321,47 @@ def test_apply_with_extra_kwargs_on_array_raises(labelled_boolean_mask: Callable | |||||||||||
| _ = collection.apply(array, sample_frequency="test") | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def test_apply_unsupported_type(): | ||||||||||||
| pm = PixelMask([[True, False], [False, True]]) | ||||||||||||
| collection = PixelMaskCollection([pm]) | ||||||||||||
|
|
||||||||||||
| # Passing a string should trigger the `case _:` TypeError | ||||||||||||
| with pytest.raises(TypeError) as excinfo: | ||||||||||||
| collection.apply("not a valid type") | ||||||||||||
| assert "Unsupported data type" in str(excinfo.value) | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def test_apply_to_eitdata_branch(): | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this test add over test_apply_to_eitdata_labelled?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For some reason test_apply_to_eitdata_labelled does not cover lines 308 and 309 in PixelMaskCollection.py: This new test does but perhaps a better solution would be to understand why test_apply_to_eitdata_labelled doesn't....
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does for me... Doesn't it skip/fail some tests because of missing data on your side?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh check, it does. That explains (blonde moment)... |
||||||||||||
| # Create a MagicMock that is recognized as an instance of EITData | ||||||||||||
| eit_data_mock = MagicMock(spec=EITData) | ||||||||||||
| eit_data_mock.pixel_impedance = np.array([[1.0, 2.0], [3.0, 4.0]]) | ||||||||||||
|
|
||||||||||||
| # Ensure .apply() on a PixelMask returns an EITData instance (or mock) | ||||||||||||
| def mock_apply( | ||||||||||||
| _self: "PixelMaskCollection", | ||||||||||||
| _data: "EITData | np.ndarray | PixelMap", | ||||||||||||
| *, | ||||||||||||
| _label: str | None = None, | ||||||||||||
| **_kwargs: object, | ||||||||||||
| ) -> EITData: | ||||||||||||
| """Mock apply method for PixelMaskCollection.""" | ||||||||||||
| return MagicMock(spec=EITData) | ||||||||||||
|
|
||||||||||||
| # Patch PixelMask.apply for this test | ||||||||||||
| PixelMask.apply = mock_apply | ||||||||||||
|
|
||||||||||||
| pm1 = PixelMask([[True, False], [False, True]], label="mask1") | ||||||||||||
| pm2 = PixelMask([[True, True], [False, False]], label="mask2") | ||||||||||||
|
|
||||||||||||
| collection = PixelMaskCollection([pm1, pm2]) | ||||||||||||
|
|
||||||||||||
| result = collection.apply(eit_data_mock) | ||||||||||||
|
|
||||||||||||
| assert isinstance(result, dict) | ||||||||||||
| assert set(result.keys()) == {"mask1", "mask2"} | ||||||||||||
| assert all(isinstance(v, EITData) for v in result.values()) | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def test_empty_collection_behavior(): | ||||||||||||
| # Allow emtpy collection initialization | ||||||||||||
| _ = PixelMaskCollection() # No masks provided | ||||||||||||
|
|
@@ -488,3 +530,22 @@ def test_combine_weighted(): | |||||||||||
| multiplied_mask = collection.combine(method="product", label="combined_product") | ||||||||||||
| assert multiplied_mask.label == "combined_product" | ||||||||||||
| assert np.array_equal(multiplied_mask.mask, np.array([[np.nan, 0.1], [0.06, 0.2]]), equal_nan=True) | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def test_combine_method_argument(): | ||||||||||||
| pm1 = PixelMask([[True, False], [False, True]]) | ||||||||||||
| pm2 = PixelMask([[True, True], [False, False]]) | ||||||||||||
| collection = PixelMaskCollection([pm1, pm2]) | ||||||||||||
|
|
||||||||||||
| # Test sum method | ||||||||||||
| summed = collection.combine(method="sum") | ||||||||||||
| assert isinstance(summed, PixelMask) | ||||||||||||
|
|
||||||||||||
| # Test product method | ||||||||||||
| product = collection.combine(method="product") | ||||||||||||
| assert isinstance(product, PixelMask) | ||||||||||||
|
Comment on lines
+540
to
+546
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't these be done in another combine test? This function now tests three things that are not really related, while other tests already test the functioning of combine. |
||||||||||||
|
|
||||||||||||
| # Test unsupported method raises ValueError | ||||||||||||
| with pytest.raises(ValueError) as excinfo: | ||||||||||||
| collection.combine(method="invalid") | ||||||||||||
| assert "Unsupported method" in str(excinfo.value) | ||||||||||||
|
Comment on lines
+549
to
+551
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.