From 7dad9a8a942bd016d7522c529c0913dbb3ab9452 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Robert?= Date: Wed, 3 Jan 2024 16:57:37 +0100 Subject: [PATCH 1/2] TST: test against pytest pre-releases --- .github/workflows/bleeding-edge.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/bleeding-edge.yaml b/.github/workflows/bleeding-edge.yaml index 7aa57bb..31a7fab 100644 --- a/.github/workflows/bleeding-edge.yaml +++ b/.github/workflows/bleeding-edge.yaml @@ -42,7 +42,7 @@ jobs: - name: Build amical run: | - python -m pip install --requirement requirements/tests.txt + python -m pip install --requirement requirements/tests.txt --pre python -m pip install --no-build-isolation . - name: Run tests From 6b7146117ba9d9e9f9ecdb03e82fe9e6bb9b966e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Robert?= Date: Wed, 3 Jan 2024 16:59:20 +0100 Subject: [PATCH 2/2] TST: fix compat with pytest 8.0.0rc1 --- amical/tests/test_processing.py | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/amical/tests/test_processing.py b/amical/tests/test_processing.py index 809c616..4282a5e 100644 --- a/amical/tests/test_processing.py +++ b/amical/tests/test_processing.py @@ -100,16 +100,21 @@ def test_sky_correction_mask_all(): def test_sky_correction_mask_zeros(): - # Check that empty correction mask gives warning and does nothing + # Check that empty correction mask gives warnings and does nothing img_dim = 80 img = np.random.random((img_dim, img_dim)) mask = np.zeros_like(img, dtype=bool) - with pytest.warns( - RuntimeWarning, - match="Background not computed because mask has no True values", - ): + with pytest.warns(RuntimeWarning) as record: img_corr = sky_correction(img, mask=mask)[0] + assert len(record) == 2 + assert ( + record[0].message.args[0] + == "Background not computed because mask has no True values" + ) + assert record[1].message.args[0] == ( + "Background not computed, likely because specified radius is out of bounds" + ) assert np.all(img_corr == img) @@ -173,12 +178,21 @@ def test_clean_data_none_kwargs(): data = np.random.random((n_im, img_dim, img_dim)) # sky=True raises a warning by default because required kwargs are None - with pytest.warns( - RuntimeWarning, - match="sky is set to True, but r1 and mask are set to None. Skipping sky correction", - ): + with pytest.warns(RuntimeWarning) as record: cube_clean_sky = clean_data(data) + # we might record many more than 2 warnings, but we filter duplicates + # to replicate Python's default behaviour: warnings only pop once per call site + unique_messages = {_.message.args[0] for _ in record} + assert len(unique_messages) == 2, "\n".join(unique_messages) + assert unique_messages == { + ( + "sky is set to True, but r1 and mask are set to None. " + "Skipping sky correction" + ), + "apod is set to True, but window is None. Skipping apodisation", + } + # apod=True raises a warning by default because required kwargs are None with pytest.warns( RuntimeWarning,