Skip to content

Commit

Permalink
teardown registered in tests
Browse files Browse the repository at this point in the history
Signed-off-by: Nathaniel Starkman (@nstarman) <nstarkman@protonmail.com>
  • Loading branch information
nstarman committed Jul 21, 2021
1 parent 8aadf49 commit 5e58feb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion astropy/units/quantity_helper/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def register_ufunc(ufunc, inunits, ounits, *, assume_correct_units=False):
if the python function works only on scalars, but we want to be able to
pass in arrays. ``c2f`` will work on arrays, but pretending it didn't...
>>> ufunc = np.frompyfunc(c2f, 1, 1); ufunc
>>> ufunc = np.frompyfunc(c2f, 1, 1); ufunc # doctest: +SKIP
<ufunc 'c2f (vectorized)'>
One of the limitations of a `numpy.ufunc` is that it cannot work with
Expand Down
15 changes: 15 additions & 0 deletions astropy/units/tests/test_quantity_ufuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# returns quantities with the right units, or raises exceptions.

import concurrent.futures
import copy
import inspect
import warnings
from collections import namedtuple
Expand Down Expand Up @@ -1397,6 +1398,9 @@ def funcobj_2_2(x: "km", y: "km") -> (object, object):
class TestRegisterUfunc:

def setup_class(self):
# start by saving a copy of REGISTERED_NARG_UFUNCS
self.REGISTERED_NARG_UFUNCS = copy.deepcopy(qh.REGISTERED_NARG_UFUNCS)

# registry of normal ufuncs
self.ufunc_registry = {
func: np.frompyfunc(func, *map(int, func.__name__.split("_")[1:]))
Expand All @@ -1422,6 +1426,10 @@ def setup_class(self):
ounits=[u.km] * ufunc.nout,
assume_correct_units=True)

def teardown_class(self):
# restore REGISTERED_NARG_UFUNCS
qh.REGISTERED_NARG_UFUNCS = self.REGISTERED_NARG_UFUNCS

# -------------------
# variety of funcs

Expand Down Expand Up @@ -1505,6 +1513,9 @@ class TestQuantityFromPyFunc:
"""Test `astropy.units.utils.frompyfunc`."""

def setup_class(self):
# start by saving a copy of REGISTERED_NARG_UFUNCS
self.REGISTERED_NARG_UFUNCS = copy.deepcopy(qh.REGISTERED_NARG_UFUNCS)

# registry of ufuncs
self.ufunc_registry = {}
self.ufunc_assume_registry = {}
Expand All @@ -1524,6 +1535,10 @@ def setup_class(self):
self.ufunc_introspect_assume_registry[func] = frompyfunc(
func, nin, nout, assume_correct_units=True)

def teardown_class(self):
# restore REGISTERED_NARG_UFUNCS
qh.REGISTERED_NARG_UFUNCS = self.REGISTERED_NARG_UFUNCS

# -------------------
# variety of funcs

Expand Down
2 changes: 1 addition & 1 deletion astropy/units/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def frompyfunc(func, nin, nout, inunits=None, ounits=None,
>>> ufunc = frompyfunc(c2f, nin=1, nout=1,
... inunits=u.Celsius, ounits=Fahrenheit)
>>> ufunc
>>> ufunc # doctest: +SKIP
<ufunc 'c2f (vectorized)'>
>>> ufunc(36 * u.Celsius)
Expand Down

0 comments on commit 5e58feb

Please sign in to comment.