From 44d19a9a8895212bc5ed0df32563996f79a0f137 Mon Sep 17 00:00:00 2001 From: Antonio Valentino Date: Sat, 28 Oct 2023 10:17:51 +0200 Subject: [PATCH] Drop the no longer needed tests/helpers.py --- erfa/tests/helper.py | 122 ---------------------------------------- erfa/tests/test_erfa.py | 9 +-- liberfa/erfa | 2 +- 3 files changed, 3 insertions(+), 130 deletions(-) delete mode 100644 erfa/tests/helper.py diff --git a/erfa/tests/helper.py b/erfa/tests/helper.py deleted file mode 100644 index a208477..0000000 --- a/erfa/tests/helper.py +++ /dev/null @@ -1,122 +0,0 @@ -# Licensed under a 3-clause BSD style license - see LICENSE.rst -# Code imported form astropy/tests/helper.py -""" -This module provides the tools used to internally run the erfa test suite. -""" -import sys -import types -import warnings - - -_deprecations_as_exceptions = False -_modules_to_ignore_on_import = set([]) -_warnings_to_ignore_entire_module = set([]) -_warnings_to_ignore_by_pyver = { - None: set([]), # Python version agnostic -} - - -def treat_deprecations_as_exceptions(): - """ - Turn all DeprecationWarnings (which indicate deprecated uses of - Python itself or Numpy) into exceptions so that we find - out about them early. - - This completely resets the warning filters and any "already seen" - warning state. - """ - # First, totally reset the warning state. The modules may change during - # this iteration thus we copy the original state to a list to iterate - # on. See https://github.com/astropy/astropy/pull/5513. - for module in list(sys.modules.values()): - # We don't want to deal with six.MovedModules, only "real" - # modules. FIXME: we no more use six, this should be useless ? - if (isinstance(module, types.ModuleType) and - hasattr(module, '__warningregistry__')): - del module.__warningregistry__ - - if not _deprecations_as_exceptions: - return - - warnings.resetwarnings() - - # Hide the next couple of DeprecationWarnings - warnings.simplefilter('ignore', DeprecationWarning) - # Here's the wrinkle: a couple of our third-party dependencies - # (py.test and scipy) are still using deprecated features - # themselves, and we'd like to ignore those. Fortunately, those - # show up only at import time, so if we import those things *now*, - # before we turn the warnings into exceptions, we're golden. - for m in _modules_to_ignore_on_import: - try: - __import__(m) - except ImportError: - pass - - # Now, start over again with the warning filters - warnings.resetwarnings() - # Now, turn these warnings into exceptions - _all_warns = [DeprecationWarning, FutureWarning, ImportWarning] - - for w in _all_warns: - warnings.filterwarnings("error", ".*", w) - - # This ignores all specified warnings from given module(s). - for m in _warnings_to_ignore_entire_module: - for w in _all_warns: - warnings.filterwarnings('ignore', category=w, module=m) - - # This ignores only specified warnings by Python version, if applicable. - for v in _warnings_to_ignore_by_pyver: - if v is None or sys.version_info[:2] == v: - for s in _warnings_to_ignore_by_pyver[v]: - warnings.filterwarnings("ignore", s[0], s[1]) - - # If using Matplotlib < 3, we should ignore the following warning since - # this is beyond our control - try: - import matplotlib - except ImportError: - pass - else: - if matplotlib.__version__[0] < '3': - warnings.filterwarnings('ignore', category=DeprecationWarning, - module='numpy.lib.type_check') - - -class catch_warnings(warnings.catch_warnings): - """ - A high-powered version of warnings.catch_warnings to use for testing - and to make sure that there is no dependence on the order in which - the tests are run. - - This completely blitzes any memory of any warnings that have - appeared before so that all warnings will be caught and displayed. - - ``*args`` is a set of warning classes to collect. If no arguments are - provided, all warnings are collected. - - Use as follows:: - - with catch_warnings(MyCustomWarning) as w: - do.something.bad() - assert len(w) > 0 - """ - - def __init__(self, *classes): - super().__init__(record=True) - self.classes = classes - - def __enter__(self): - warning_list = super().__enter__() - treat_deprecations_as_exceptions() - if len(self.classes) == 0: - warnings.simplefilter('always') - else: - warnings.simplefilter('ignore') - for cls in self.classes: - warnings.simplefilter('always', cls) - return warning_list - - def __exit__(self, type, value, traceback): - treat_deprecations_as_exceptions() diff --git a/erfa/tests/test_erfa.py b/erfa/tests/test_erfa.py index 7e4d9b3..6fd4a32 100644 --- a/erfa/tests/test_erfa.py +++ b/erfa/tests/test_erfa.py @@ -6,7 +6,6 @@ from numpy.testing import assert_array_equal, assert_array_almost_equal, assert_allclose import erfa -from erfa.tests.helper import catch_warnings try: from astropy.time import Time @@ -172,18 +171,14 @@ def test_errwarn_reporting(): erfa.dat(1990, 1, 1, 0.5) # check warning is raised for a scalar - with catch_warnings() as w: + with pytest.warns(erfa.ErfaWarning, match=r'1 of "dubious year \(Note 1\)"') as w: erfa.dat(100, 1, 1, 0.5) assert len(w) == 1 - assert w[0].category == erfa.ErfaWarning - assert '1 of "dubious year (Note 1)"' in str(w[0].message) # and that the count is right for a vector. - with catch_warnings() as w: + with pytest.warns(erfa.ErfaWarning, match=r'2 of "dubious year \(Note 1\)"') as w: erfa.dat([100, 200, 1990], 1, 1, 0.5) assert len(w) == 1 - assert w[0].category == erfa.ErfaWarning - assert '2 of "dubious year (Note 1)"' in str(w[0].message) try: erfa.dat(1990, [1, 34, 2], [1, 1, 43], 0.5) diff --git a/liberfa/erfa b/liberfa/erfa index 9915ba3..eb4c95d 160000 --- a/liberfa/erfa +++ b/liberfa/erfa @@ -1 +1 @@ -Subproject commit 9915ba38c9365f8b0738269b8c2ac1fdd5f8dee3 +Subproject commit eb4c95dfc128fc893987330b5bf3c6413065eb53