Skip to content

Commit

Permalink
DEPR: deprecate yt.testing.assert_true and yt.testing.assert_less_equal
Browse files Browse the repository at this point in the history
  • Loading branch information
neutrinoceros committed May 5, 2023
1 parent 8c91939 commit 7866b06
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 40 deletions.
34 changes: 17 additions & 17 deletions yt/data_objects/tests/test_chunking.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from numpy.testing import assert_equal
from numpy.testing import assert_array_equal

from yt.testing import assert_true, fake_random_ds
from yt.testing import fake_random_ds
from yt.units._numpy_wrapper_functions import uconcatenate


Expand Down Expand Up @@ -36,25 +36,25 @@ def test_chunking():
coords["i"][t] = uconcatenate(coords["i"][t])
coords["f"][t].sort()
coords["i"][t].sort()
assert_equal(coords["f"]["io"], coords["f"]["all"])
assert_equal(coords["f"]["io"], coords["f"]["spatial"])
assert_equal(coords["i"]["io"], coords["i"]["all"])
assert_equal(coords["i"]["io"], coords["i"]["spatial"])
assert_array_equal(coords["f"]["io"], coords["f"]["all"])
assert_array_equal(coords["f"]["io"], coords["f"]["spatial"])
assert_array_equal(coords["i"]["io"], coords["i"]["all"])
assert_array_equal(coords["i"]["io"], coords["i"]["spatial"])


def test_ds_hold():
ds1 = fake_random_ds(64)
ds2 = fake_random_ds(128)
dd = ds1.all_data()
assert_true(
dd.ds.__hash__() == ds1.__hash__()
) # dd.ds is a weakref, so can't use "is"
assert_true(dd.index is ds1.index)
assert_equal(dd[("index", "ones")].size, 64**3)

# dd.ds is a weakref, so can't use "is"
assert dd.ds.__hash__() == ds1.__hash__()
assert dd.index is ds1.index
assert dd[("index", "ones")].size == 64**3
with dd._ds_hold(ds2):
assert_true(dd.ds.__hash__() == ds2.__hash__())
assert_true(dd.index is ds2.index)
assert_equal(dd[("index", "ones")].size, 128**3)
assert_true(dd.ds.__hash__() == ds1.__hash__())
assert_true(dd.index is ds1.index)
assert_equal(dd[("index", "ones")].size, 64**3)
assert dd.ds.__hash__() == ds2.__hash__()
assert dd.index is ds2.index
assert dd[("index", "ones")].size, 128**3
assert dd.ds.__hash__() == ds1.__hash__()
assert dd.index is ds1.index
assert dd[("index", "ones")].size == 64**3
4 changes: 2 additions & 2 deletions yt/geometry/tests/test_particle_octree.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from yt.geometry.oct_container import _ORDER_MAX
from yt.geometry.particle_oct_container import ParticleBitmap, ParticleOctreeContainer
from yt.geometry.selection_routines import RegionSelector
from yt.testing import assert_true, requires_module
from yt.testing import requires_module
from yt.units.unit_registry import UnitRegistry
from yt.units.yt_array import YTArray
from yt.utilities.lib.geometry_utils import (
Expand Down Expand Up @@ -302,7 +302,7 @@ def test_bitmap_save_load():
left_edge, right_edge, periodicity, file_hash, nfiles, order1, order2
)
reg1.load_bitmasks(fname)
assert_true(reg0.iseq_bitmask(reg1))
assert reg0.iseq_bitmask(reg1)
# Remove file
os.remove(fname)

Expand Down
17 changes: 15 additions & 2 deletions yt/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,28 @@
# Expose assert_true and assert_less_equal from unittest.TestCase
# this is adopted from nose. Doing this here allows us to avoid importing
# nose at the top level.
def _deprecated_assert_func(func):
@wraps(func)
def retf(*args, **kwargs):
issue_deprecation_warning(
f"yt.testing.{func.__name__} is deprecated",
since="4.2",
stacklevel=3,
)
return func(*args, **kwargs)

return retf


class _Dummy(unittest.TestCase):
def nop(self):
pass


_t = _Dummy("nop")

assert_true = _t.assertTrue
assert_less_equal = _t.assertLessEqual
assert_true = _deprecated_assert_func(_t.assertTrue)
assert_less_equal = _deprecated_assert_func(_t.assertLessEqual)


def assert_rel_equal(a1, a2, decimals, err_msg="", verbose=True):
Expand Down
23 changes: 11 additions & 12 deletions yt/utilities/lib/tests/test_alt_ray_tracers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"""Tests for non-cartesian ray tracers."""
import numpy as np
from numpy.testing import assert_equal

from yt.testing import amrspace, assert_less_equal, assert_true
from yt.testing import amrspace
from yt.utilities.lib.alt_ray_tracers import _cyl2cart, cylindrical_ray_trace

left_grid = right_grid = amr_levels = center_grid = data = None
Expand Down Expand Up @@ -51,12 +50,12 @@ def setup():


def check_monotonic_inc(arr):
assert_true(np.all(0.0 <= (arr[1:] - arr[:-1])))
assert np.all(0.0 <= (arr[1:] - arr[:-1]))


def check_bounds(arr, blower, bupper):
assert_true(np.all(blower <= arr))
assert_true(np.all(bupper >= arr))
assert np.all(blower <= arr)
assert np.all(bupper >= arr)


def test_cylindrical_ray_trace():
Expand All @@ -69,19 +68,19 @@ def test_cylindrical_ray_trace():
npoints = len(t)

check_monotonic_inc(t)
assert_less_equal(0.0, t[0])
assert_less_equal(t[-1], 1.0)
assert 0.0 <= t[0]
assert t[-1] <= 1.0

check_monotonic_inc(s)
assert_less_equal(0.0, s[0])
assert_less_equal(s[-1], pathlen)
assert_equal(npoints, len(s))
assert 0.0 <= s[0]
assert s[-1] <= pathlen
assert npoints == len(s)

assert_equal((npoints, 3), rztheta.shape)
assert (npoints, 3) == rztheta.shape
check_bounds(rztheta[:, 0], 0.0, 1.0)
check_bounds(rztheta[:, 1], -1.0, 1.0)
check_bounds(rztheta[:, 2], 0.0, 2 * np.pi)
check_monotonic_inc(rztheta[:, 2])

assert_equal(npoints, len(inds))
assert npoints == len(inds)
check_bounds(inds, 0, len(left_grid) - 1)
13 changes: 6 additions & 7 deletions yt/visualization/tests/test_plotwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
assert_allclose_units,
assert_fname,
assert_rel_equal,
assert_true,
fake_amr_ds,
fake_random_ds,
requires_file,
Expand Down Expand Up @@ -275,7 +274,7 @@ def test_set_width_one(self):
[self.slc.xlim, self.slc.ylim, self.slc.width],
[(0.0, 1.0), (0.0, 1.0), (1.0, 1.0)],
)
assert_true(self.slc._axes_unit_names is None)
assert self.slc._axes_unit_names is None

def test_set_width_nonequal(self):
self.slc.set_width((0.5, 0.8))
Expand All @@ -284,22 +283,22 @@ def test_set_width_nonequal(self):
[(0.25, 0.75), (0.1, 0.9), (0.5, 0.8)],
15,
)
assert_true(self.slc._axes_unit_names is None)
assert self.slc._axes_unit_names is None

def test_twoargs_eq(self):
self.slc.set_width(0.5, "cm")
self._assert_05cm()
assert_true(self.slc._axes_unit_names == ("cm", "cm"))
assert self.slc._axes_unit_names == ("cm", "cm")

def test_tuple_eq(self):
self.slc.set_width((0.5, "cm"))
self._assert_05cm()
assert_true(self.slc._axes_unit_names == ("cm", "cm"))
assert self.slc._axes_unit_names == ("cm", "cm")

def test_tuple_of_tuples_neq(self):
self.slc.set_width(((0.5, "cm"), (0.75, "cm")))
self._assert_05_075cm()
assert_true(self.slc._axes_unit_names == ("cm", "cm"))
assert self.slc._axes_unit_names == ("cm", "cm")


class TestPlotWindowSave(unittest.TestCase):
Expand Down Expand Up @@ -390,7 +389,7 @@ def test_creation_with_width(self):
[assert_array_almost_equal(px, x, 14) for px, x in zip(plot.xlim, xlim)]
[assert_array_almost_equal(py, y, 14) for py, y in zip(plot.ylim, ylim)]
[assert_array_almost_equal(pw, w, 14) for pw, w in zip(plot.width, pwidth)]
assert_true(aun == plot._axes_unit_names)
assert aun == plot._axes_unit_names


class TestPerFieldConfig(unittest.TestCase):
Expand Down

0 comments on commit 7866b06

Please sign in to comment.