-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b02f4b
commit 268deed
Showing
1 changed file
with
64 additions
and
63 deletions.
There are no files selected for viewing
127 changes: 64 additions & 63 deletions
127
tests/unit/spectrum/peak_filtering/test_chain_filters.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,76 @@ | ||
import unittest | ||
from unittest.mock import MagicMock | ||
import pytest | ||
from pytest_mock import MockerFixture | ||
|
||
from depiction.spectrum.peak_filtering import ChainFilters | ||
|
||
|
||
class TestChainFilters(unittest.TestCase): | ||
def setUp(self) -> None: | ||
self.mock_filter_1 = MagicMock(name="mock_filter_1") | ||
self.mock_filter_2 = MagicMock(name="mock_filter_2") | ||
self.chain_filters = ChainFilters( | ||
filters=[ | ||
self.mock_filter_1, | ||
self.mock_filter_2, | ||
] | ||
) | ||
@pytest.fixture() | ||
def mock_filter_1(mocker: MockerFixture): | ||
return mocker.MagicMock(name="mock_filter_1") | ||
|
||
def test_filter_index_peaks(self) -> None: | ||
self.mock_filter_1.filter_index_peaks.return_value = [1, 2, 3] | ||
self.mock_filter_2.filter_index_peaks.return_value = [2, 3] | ||
mock_spectrum_mz_arr = MagicMock(name="mock_spectrum_mz_arr") | ||
mock_spectrum_int_arr = MagicMock(name="mock_spectrum_int_arr") | ||
peak_idx_arr = [1, 2, 3, 4] | ||
|
||
result_peak_idx_arr = self.chain_filters.filter_index_peaks( | ||
spectrum_mz_arr=mock_spectrum_mz_arr, | ||
spectrum_int_arr=mock_spectrum_int_arr, | ||
peak_idx_arr=peak_idx_arr, | ||
) | ||
@pytest.fixture() | ||
def mock_filter_2(mocker: MockerFixture): | ||
return mocker.MagicMock(name="mock_filter_2") | ||
|
||
self.assertEqual(result_peak_idx_arr, [2, 3]) | ||
self.mock_filter_1.filter_index_peaks.assert_called_once_with( | ||
mock_spectrum_mz_arr, | ||
mock_spectrum_int_arr, | ||
peak_idx_arr, | ||
) | ||
self.mock_filter_2.filter_index_peaks.assert_called_once_with( | ||
mock_spectrum_mz_arr, | ||
mock_spectrum_int_arr, | ||
[1, 2, 3], | ||
) | ||
|
||
def test_filter_peaks(self) -> None: | ||
self.mock_filter_1.filter_peaks.return_value = ([1, 2, 3], [4, 5, 6]) | ||
self.mock_filter_2.filter_peaks.return_value = ([2, 3], [5, 6]) | ||
mock_spectrum_mz_arr = MagicMock(name="mock_spectrum_mz_arr") | ||
mock_spectrum_int_arr = MagicMock(name="mock_spectrum_int_arr") | ||
peak_mz_arr = [1, 2, 3, 4] | ||
peak_int_arr = [4, 5, 6, 7] | ||
@pytest.fixture() | ||
def chain_filters(mock_filter_1, mock_filter_2): | ||
return ChainFilters(filters=[mock_filter_1, mock_filter_2]) | ||
|
||
result_peak_mz_arr, result_peak_int_arr = self.chain_filters.filter_peaks( | ||
spectrum_mz_arr=mock_spectrum_mz_arr, | ||
spectrum_int_arr=mock_spectrum_int_arr, | ||
peak_mz_arr=peak_mz_arr, | ||
peak_int_arr=peak_int_arr, | ||
) | ||
|
||
self.assertEqual(result_peak_mz_arr, [2, 3]) | ||
self.assertEqual(result_peak_int_arr, [5, 6]) | ||
self.mock_filter_1.filter_peaks.assert_called_once_with( | ||
mock_spectrum_mz_arr, | ||
mock_spectrum_int_arr, | ||
peak_mz_arr, | ||
peak_int_arr, | ||
) | ||
self.mock_filter_2.filter_peaks.assert_called_once_with( | ||
mock_spectrum_mz_arr, | ||
mock_spectrum_int_arr, | ||
[1, 2, 3], | ||
[4, 5, 6], | ||
) | ||
def test_filter_index_peaks(mocker, mock_filter_1, mock_filter_2, chain_filters) -> None: | ||
mock_filter_1.filter_index_peaks.return_value = [1, 2, 3] | ||
mock_filter_2.filter_index_peaks.return_value = [2, 3] | ||
mock_spectrum_mz_arr = mocker.MagicMock(name="mock_spectrum_mz_arr") | ||
mock_spectrum_int_arr = mocker.MagicMock(name="mock_spectrum_int_arr") | ||
peak_idx_arr = [1, 2, 3, 4] | ||
|
||
result_peak_idx_arr = chain_filters.filter_index_peaks( | ||
spectrum_mz_arr=mock_spectrum_mz_arr, | ||
spectrum_int_arr=mock_spectrum_int_arr, | ||
peak_idx_arr=peak_idx_arr, | ||
) | ||
|
||
if __name__ == "__main__": | ||
unittest.main() | ||
assert result_peak_idx_arr == [2, 3] | ||
mock_filter_1.filter_index_peaks.assert_called_once_with( | ||
mock_spectrum_mz_arr, | ||
mock_spectrum_int_arr, | ||
peak_idx_arr, | ||
) | ||
mock_filter_2.filter_index_peaks.assert_called_once_with( | ||
mock_spectrum_mz_arr, | ||
mock_spectrum_int_arr, | ||
[1, 2, 3], | ||
) | ||
|
||
|
||
def test_filter_peaks(mocker, mock_filter_1, mock_filter_2, chain_filters) -> None: | ||
mock_filter_1.filter_peaks.return_value = ([1, 2, 3], [4, 5, 6]) | ||
mock_filter_2.filter_peaks.return_value = ([2, 3], [5, 6]) | ||
mock_spectrum_mz_arr = mocker.MagicMock(name="mock_spectrum_mz_arr") | ||
mock_spectrum_int_arr = mocker.MagicMock(name="mock_spectrum_int_arr") | ||
peak_mz_arr = [1, 2, 3, 4] | ||
peak_int_arr = [4, 5, 6, 7] | ||
|
||
result_peak_mz_arr, result_peak_int_arr = chain_filters.filter_peaks( | ||
spectrum_mz_arr=mock_spectrum_mz_arr, | ||
spectrum_int_arr=mock_spectrum_int_arr, | ||
peak_mz_arr=peak_mz_arr, | ||
peak_int_arr=peak_int_arr, | ||
) | ||
|
||
assert result_peak_mz_arr == [2, 3] | ||
assert result_peak_int_arr == [5, 6] | ||
mock_filter_1.filter_peaks.assert_called_once_with( | ||
mock_spectrum_mz_arr, | ||
mock_spectrum_int_arr, | ||
peak_mz_arr, | ||
peak_int_arr, | ||
) | ||
mock_filter_2.filter_peaks.assert_called_once_with( | ||
mock_spectrum_mz_arr, | ||
mock_spectrum_int_arr, | ||
[1, 2, 3], | ||
[4, 5, 6], | ||
) |