Skip to content

Commit

Permalink
TST, BUG: add default None -> UserWarning (#4747)
Browse files Browse the repository at this point in the history
* add default None -> UserWarning for `no_deprecated_call`
decorator

* Add a regression test that serves the dual purpose of ensuring
that the `no_deprecated_call` decorator behaves properly when
the warning category is `None`, and also enforces our intended
warnings behavior for the element guessing changes in gh-4744.

---------

Co-authored-by: Tyler Reddy <[email protected]>
  • Loading branch information
lilyminium and tylerjereddy authored Dec 6, 2024
1 parent 557f27d commit 4e903c7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions testsuite/MDAnalysisTests/topology/test_itp.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import numpy as np
from numpy.testing import assert_allclose, assert_equal

from MDAnalysisTests.util import no_deprecated_call
from MDAnalysisTests.topology.base import ParserBase
from MDAnalysisTests.datafiles import (
ITP, # GROMACS itp
Expand Down Expand Up @@ -490,6 +491,8 @@ def test_missing_elements_no_attribute():
u = mda.Universe(ITP_atomtypes)
with pytest.raises(AttributeError):
_ = u.atoms.elements
with no_deprecated_call():
mda.Universe(ITP_atomtypes)


def test_elements_deprecation_warning():
Expand Down
5 changes: 5 additions & 0 deletions testsuite/MDAnalysisTests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ def _warn(self, message, category=None, *args, **kwargs):
if isinstance(message, Warning):
self._captured_categories.append(message.__class__)
else:
# as follows Python documentation at
# https://docs.python.org/3/library/warnings.html#warnings.warn
# if category is None, the default UserWarning is used
if category is None:
category = UserWarning
self._captured_categories.append(category)

def __exit__(self, exc_type, exc_val, exc_tb):
Expand Down

0 comments on commit 4e903c7

Please sign in to comment.