From c27c82eb47518684e163a6b72f6eedecbbaf22a5 Mon Sep 17 00:00:00 2001 From: Joep Vanlier Date: Tue, 30 Jan 2024 11:57:32 +0100 Subject: [PATCH] ci: fix tests for `pytest>=8.0.0` pytest changed its warning/exception order starting from 8.0.0 (see https://github.com/pytest-dev/pytest/issues/9036). This updates our tests to fit the new spec. For kymographs, this meant explicitly passing a motion blur parameter such that we don't issue that error instead of what we are looking for. For the dwelltime analysis, we have to make sure we don't get any of the deprecation warnings so that we can see the warning we are testing for. For touchdown, we have to explicitly silence the covariance matrix is undefined error (which actually already tells us that the problem will be non-identifiable). --- changelog.md | 1 + .../pylake/force_calibration/tests/test_touchdown.py | 1 + lumicks/pylake/kymotracker/tests/conftest.py | 4 +++- lumicks/pylake/kymotracker/tests/test_kymotrack.py | 12 ++++++++++-- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index 38497f413..e39382c59 100644 --- a/changelog.md +++ b/changelog.md @@ -12,6 +12,7 @@ * Fixed a bug where the time between frames was incorrectly not excluded when calling [`ImageStack.frame_timestamp_ranges()`](https://lumicks-pylake.readthedocs.io/en/latest/_api/lumicks.pylake.ImageStack.html#lumicks.pylake.ImageStack.frame_timestamp_ranges) with `include_dead_time=False`. Note that `Scan` and `Kymo` are not affected. * Fixed a bug where [`ImageStack.plot_correlated()`](https://lumicks-pylake.readthedocs.io/en/v1.3.0/_api/lumicks.pylake.ImageStack.html#lumicks.pylake.ImageStack.plot_correlated) was not excluding the dead time between frames. * Changed the `DateTime` tag on TIFFs exported with Pylake from `Scan` and `Kymo` objects. Before the change, the start and end of the scanning period in nanoseconds was stored. After the change, we store the starting timestamp of the frame, followed by the starting timestamp of the next frame to be consistent with data exported from Bluelake. The scanning time is stored in the field `Exposure time (ms)` on the Description tag. +* Fixed tests to be compatible with `pytest>=8.0.0`. ## v1.3.1 | 2023-12-07 diff --git a/lumicks/pylake/force_calibration/tests/test_touchdown.py b/lumicks/pylake/force_calibration/tests/test_touchdown.py index aa2665ab3..dee583396 100644 --- a/lumicks/pylake/force_calibration/tests/test_touchdown.py +++ b/lumicks/pylake/force_calibration/tests/test_touchdown.py @@ -145,6 +145,7 @@ def test_exp_sine_fits(decay, amplitude, frequency, phase_shift): np.testing.assert_allclose(par, frequency, rtol=1e-6) +@pytest.mark.filterwarnings("ignore:Covariance of the parameters could not be estimated") def test_insufficient_data(mack_parameters): stage_positions, simulation = simulate_touchdown(102.5, 103.5, 0.01, mack_parameters) diff --git a/lumicks/pylake/kymotracker/tests/conftest.py b/lumicks/pylake/kymotracker/tests/conftest.py index b0812408f..f5d1d953b 100644 --- a/lumicks/pylake/kymotracker/tests/conftest.py +++ b/lumicks/pylake/kymotracker/tests/conftest.py @@ -66,7 +66,7 @@ def two_gaussians_1d(): @pytest.fixture def blank_kymo(): - return generate_kymo( + kymo = generate_kymo( "", np.ones((1, 10)), pixel_size_nm=1000, @@ -75,6 +75,8 @@ def blank_kymo(): samples_per_pixel=1, line_padding=0, ) + kymo._motion_blur_constant = 0 + return kymo @pytest.fixture diff --git a/lumicks/pylake/kymotracker/tests/test_kymotrack.py b/lumicks/pylake/kymotracker/tests/test_kymotrack.py index 6e57a3acf..248c182f5 100644 --- a/lumicks/pylake/kymotracker/tests/test_kymotrack.py +++ b/lumicks/pylake/kymotracker/tests/test_kymotrack.py @@ -867,7 +867,9 @@ def test_fit_binding_times_nonzero(blank_kymo, blank_kymo_track_args): r"analysis. If you wish to not see this warning, filter the tracks with " r"`lk.filter_tracks` with a minimum length of 2 samples.", ): - dwelltime_model = tracks.fit_binding_times(1) + dwelltime_model = tracks.fit_binding_times( + n_components=1, observed_minimum=True, discrete_model=False + ) np.testing.assert_equal(dwelltime_model.dwelltimes, [4, 4, 4, 4]) np.testing.assert_equal(dwelltime_model._observation_limits[0], 4) np.testing.assert_allclose(dwelltime_model.lifetimes[0], [0.4]) @@ -1145,6 +1147,7 @@ def test_kymotrack_group_diffusion_filter(): image = np.random.randint(0, 20, size=(10, 10, 3)) kwargs = dict(line_time_seconds=10e-3, start=np.int64(20e9), pixel_size_um=0.05, name="test") kymo = _kymo_from_array(image, "rgb", **kwargs) + kymo._motion_blur_constant = 0 base_coordinates = ( np.arange(1, 10), @@ -1408,7 +1411,12 @@ def test_ensemble_diffusion_different_attributes(): line_times = (1, 0.5) pixel_sizes = (0.1, 0.05) kwargs = [{"line_time_seconds": t, "pixel_size_um": s} for t in line_times for s in pixel_sizes] - kymos = [_kymo_from_array(np.random.poisson(5, (25, 25, 3)), "rgb", **k) for k in kwargs] + kymos = [] + for k in kwargs: + kymo = _kymo_from_array(np.random.poisson(5, (25, 25, 3)), "rgb", **k) + kymo._motion_blur_constant = 0 + kymos.append(kymo) + tracks = [ KymoTrackGroup( [KymoTrack(np.arange(5), np.random.uniform(3, 5, 5), k, "green", 0) for _ in range(5)]