diff --git a/yt/data_objects/tests/test_chunking.py b/yt/data_objects/tests/test_chunking.py index 415811a0ce0..8a5c5cffee9 100644 --- a/yt/data_objects/tests/test_chunking.py +++ b/yt/data_objects/tests/test_chunking.py @@ -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 @@ -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 diff --git a/yt/geometry/tests/test_particle_octree.py b/yt/geometry/tests/test_particle_octree.py index 1a9a88b339d..f5230596083 100644 --- a/yt/geometry/tests/test_particle_octree.py +++ b/yt/geometry/tests/test_particle_octree.py @@ -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 ( @@ -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) diff --git a/yt/testing.py b/yt/testing.py index 4e8fb9c756f..a00deec6540 100644 --- a/yt/testing.py +++ b/yt/testing.py @@ -30,6 +30,19 @@ # 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 @@ -37,8 +50,8 @@ def nop(self): _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): diff --git a/yt/utilities/lib/tests/test_alt_ray_tracers.py b/yt/utilities/lib/tests/test_alt_ray_tracers.py index e229c000afd..b4f8f9bdde3 100644 --- a/yt/utilities/lib/tests/test_alt_ray_tracers.py +++ b/yt/utilities/lib/tests/test_alt_ray_tracers.py @@ -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 @@ -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(): @@ -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) diff --git a/yt/visualization/tests/test_plotwindow.py b/yt/visualization/tests/test_plotwindow.py index 4c669bf6653..cbcd01d946b 100644 --- a/yt/visualization/tests/test_plotwindow.py +++ b/yt/visualization/tests/test_plotwindow.py @@ -19,7 +19,6 @@ assert_allclose_units, assert_fname, assert_rel_equal, - assert_true, fake_amr_ds, fake_random_ds, requires_file, @@ -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)) @@ -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): @@ -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):