Skip to content

Commit

Permalink
Merge pull request #208 from neutrinoceros/test_against_pytest_pre
Browse files Browse the repository at this point in the history
TST: test against pytest pre-releases
  • Loading branch information
DrSoulain committed Mar 14, 2024
2 parents a0516b9 + 6b71461 commit 429e376
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
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

0 comments on commit 429e376

Please sign in to comment.