Skip to content
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

TST: test against pytest pre-releases #208

Merged
merged 2 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/bleeding-edge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 23 additions & 9 deletions amical/tests/test_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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,
Expand Down