Skip to content

Commit

Permalink
more testing deps
Browse files Browse the repository at this point in the history
  • Loading branch information
leoschwarz committed May 31, 2024
1 parent 5b7eb14 commit aaad371
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ testing = [
"hypothesis>=6.99.11",
"mypy>=1.9.0",
"pytype>=2023.12.18",
"logot"
"logot",
"pytest",
"pytest-mock"
]
dev = [
"bokeh>=3.3.2",
Expand Down
35 changes: 15 additions & 20 deletions tests/unit/spectrum/peak_picking/test_basic_peak_picker.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import unittest
from functools import cached_property
from unittest.mock import patch, MagicMock

import numpy as np
import pytest

from depiction.spectrum.peak_picking.basic_peak_picker import BasicPeakPicker


class TestBasicPeakPicker(unittest.TestCase):
def setUp(self) -> None:
class TestBasicPeakPicker:
def setup_method(self) -> None:
self.mock_smooth_sigma = 0.1
self.mock_min_prominence = 2.0
self.mock_min_distance = None
Expand All @@ -33,15 +33,15 @@ def test_get_smoothed_intensities(self, mock_gaussian_filter1d) -> None:
mock_int_arr = MagicMock(name="mock_int_arr", spec=[])
mock_mz_arr = np.array([5, 7, 9, 11, 11.5, 15])
int_arr_smooth = self.mock_picker.get_smoothed_intensities(mz_arr=mock_mz_arr, int_arr=mock_int_arr)
self.assertEqual(mock_gaussian_filter1d.return_value, int_arr_smooth)
assert mock_gaussian_filter1d.return_value == int_arr_smooth
mock_gaussian_filter1d.assert_called_once_with(mock_int_arr, sigma=2.5)

def test_get_smoothed_intensities_when_sigma_is_none(self) -> None:
self.mock_smooth_sigma = None
mock_int_arr = MagicMock(name="mock_int_arr", spec=[])
mock_mz_arr = MagicMock(name="mock_mz_arr", spec=[])
smoothed = self.mock_picker.get_smoothed_intensities(mz_arr=mock_mz_arr, int_arr=mock_int_arr)
self.assertEqual(mock_int_arr, smoothed)
assert mock_int_arr == smoothed

def test_pick_peaks_index(self) -> None:
indices = self.mock_picker.pick_peaks_index(self.mock_mz_arr, self.mock_int_arr)
Expand Down Expand Up @@ -71,37 +71,32 @@ def test_pick_peaks_mz(self, method_pick_peaks_index) -> None:

def test_clone(self) -> None:
copy = self.mock_picker.clone()
self.assertIsNot(self.mock_picker, copy)
self.assertEqual(self.mock_picker.smooth_sigma, copy.smooth_sigma)
self.assertEqual(self.mock_picker.min_prominence, copy.min_prominence)
assert self.mock_picker is not copy
assert self.mock_picker.smooth_sigma == copy.smooth_sigma
assert self.mock_picker.min_prominence == copy.min_prominence

def test_get_min_distance_indices_when_none(self) -> None:
mock_mz_arr = MagicMock(name="mock_mz_arr", spec=[])
self.assertIsNone(
assert (
BasicPeakPicker.get_min_distance_indices(min_distance=None, min_distance_unit=None, mz_arr=mock_mz_arr)
is None
)

def test_get_min_distance_indices_when_unit_index(self) -> None:
mock_min_distance = 3
mock_min_distance_unit = "index"
mock_mz_arr = MagicMock(name="mock_mz_arr", spec=[])
self.assertEqual(
3,
BasicPeakPicker.get_min_distance_indices(
min_distance=mock_min_distance, min_distance_unit=mock_min_distance_unit, mz_arr=mock_mz_arr
),
assert 3 == BasicPeakPicker.get_min_distance_indices(
min_distance=mock_min_distance, min_distance_unit=mock_min_distance_unit, mz_arr=mock_mz_arr
)

def test_get_min_distance_indices_when_unit_mz(self) -> None:
mock_min_distance = 0.5
mock_min_distance_unit = "mz"
self.assertEqual(
5,
BasicPeakPicker.get_min_distance_indices(
min_distance=mock_min_distance, min_distance_unit=mock_min_distance_unit, mz_arr=self.mock_mz_arr
),
assert 5 == BasicPeakPicker.get_min_distance_indices(
min_distance=mock_min_distance, min_distance_unit=mock_min_distance_unit, mz_arr=self.mock_mz_arr
)


if __name__ == "__main__":
unittest.main()
pytest.main()

0 comments on commit aaad371

Please sign in to comment.