From 04ec4263980f4377467bdee3950dfe654c4e1345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Robert?= Date: Fri, 5 May 2023 23:29:46 +0200 Subject: [PATCH 1/5] DEPR: deprecate yt.testing.assert_true and yt.testing.assert_less_equal --- yt/data_objects/tests/test_chunking.py | 18 +++++++++--------- yt/geometry/tests/test_particle_octree.py | 4 ++-- yt/testing.py | 17 +++++++++++++++-- yt/utilities/lib/tests/test_alt_ray_tracers.py | 16 ++++++++-------- yt/visualization/tests/test_plotwindow.py | 13 ++++++------- 5 files changed, 40 insertions(+), 28 deletions(-) diff --git a/yt/data_objects/tests/test_chunking.py b/yt/data_objects/tests/test_chunking.py index 415811a0ce0..67f4c2e8f93 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 yt.testing import assert_true, fake_random_ds +from yt.testing import fake_random_ds from yt.units._numpy_wrapper_functions import uconcatenate @@ -46,15 +46,15 @@ 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) + # dd.ds is a weakref, so can't use "is" + assert dd.ds.__hash__() == ds1.__hash__() + + assert dd.index is ds1.index assert_equal(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 dd.ds.__hash__() == ds2.__hash__() + assert 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 dd.ds.__hash__() == ds1.__hash__() + assert dd.index is ds1.index assert_equal(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..6599c8ebe25 100644 --- a/yt/utilities/lib/tests/test_alt_ray_tracers.py +++ b/yt/utilities/lib/tests/test_alt_ray_tracers.py @@ -2,7 +2,7 @@ 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 +51,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,12 +69,12 @@ 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 0.0 <= s[0] + assert s[-1] <= pathlen assert_equal(npoints, len(s)) assert_equal((npoints, 3), rztheta.shape) 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): From 39babc716ddc2477da590f9fbf86327d2daeb2cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Robert?= Date: Sat, 6 May 2023 11:33:50 +0200 Subject: [PATCH 2/5] DEPR: deprecate yt.testing.expand_keyword --- yt/testing.py | 4 + .../tests/test_offaxisprojection.py | 109 +++++++++++++++++- 2 files changed, 112 insertions(+), 1 deletion(-) diff --git a/yt/testing.py b/yt/testing.py index a00deec6540..ed61bc199a2 100644 --- a/yt/testing.py +++ b/yt/testing.py @@ -840,6 +840,10 @@ def expand_keywords(keywords, full=False): ... write_projection(*args, **kwargs) """ + issue_deprecation_warning( + "yt.testing.expand_keywords is deprecated", since="4.2", stacklevel=2 + ) + # if we want every possible combination of keywords, use iter magic if full: keys = sorted(keywords) diff --git a/yt/visualization/tests/test_offaxisprojection.py b/yt/visualization/tests/test_offaxisprojection.py index 3a6c662597f..d932f93c3aa 100644 --- a/yt/visualization/tests/test_offaxisprojection.py +++ b/yt/visualization/tests/test_offaxisprojection.py @@ -1,3 +1,4 @@ +import itertools as it import os import shutil import tempfile @@ -9,7 +10,6 @@ from yt.testing import ( assert_fname, assert_rel_equal, - expand_keywords, fake_octree_ds, fake_random_ds, ) @@ -18,6 +18,113 @@ from yt.visualization.volume_rendering.api import off_axis_projection +# TODO: replace this with pytest.mark.parametrize +def expand_keywords(keywords, full=False): + """ + expand_keywords is a means for testing all possible keyword + arguments in the nosetests. Simply pass it a dictionary of all the + keyword arguments and all of the values for these arguments that you + want to test. + + It will return a list of kwargs dicts containing combinations of + the various kwarg values you passed it. These can then be passed + to the appropriate function in nosetests. + + If full=True, then every possible combination of keywords is produced, + otherwise, every keyword option is included at least once in the output + list. Be careful, by using full=True, you may be in for an exponentially + larger number of tests! + + Parameters + ---------- + + keywords : dict + a dictionary where the keys are the keywords for the function, + and the values of each key are the possible values that this key + can take in the function + + full : bool + if set to True, every possible combination of given keywords is + returned + + Returns + ------- + + array of dicts + An array of dictionaries to be individually passed to the appropriate + function matching these kwargs. + + Examples + -------- + + >>> keywords = {} + >>> keywords["dpi"] = (50, 100, 200) + >>> keywords["cmap"] = ("cmyt.arbre", "cmyt.kelp") + >>> list_of_kwargs = expand_keywords(keywords) + >>> print(list_of_kwargs) + + array([{'cmap': 'cmyt.arbre', 'dpi': 50}, + {'cmap': 'cmyt.kelp', 'dpi': 100}, + {'cmap': 'cmyt.arbre', 'dpi': 200}], dtype=object) + + >>> list_of_kwargs = expand_keywords(keywords, full=True) + >>> print(list_of_kwargs) + + array([{'cmap': 'cmyt.arbre', 'dpi': 50}, + {'cmap': 'cmyt.arbre', 'dpi': 100}, + {'cmap': 'cmyt.arbre', 'dpi': 200}, + {'cmap': 'cmyt.kelp', 'dpi': 50}, + {'cmap': 'cmyt.kelp', 'dpi': 100}, + {'cmap': 'cmyt.kelp', 'dpi': 200}], dtype=object) + + >>> for kwargs in list_of_kwargs: + ... write_projection(*args, **kwargs) + """ + # if we want every possible combination of keywords, use iter magic + if full: + keys = sorted(keywords) + list_of_kwarg_dicts = np.array( + [ + dict(zip(keys, prod)) + for prod in it.product(*(keywords[key] for key in keys)) + ] + ) + + # if we just want to probe each keyword, but not necessarily every + # combination + else: + # Determine the maximum number of values any of the keywords has + num_lists = 0 + for val in keywords.values(): + if isinstance(val, str): + num_lists = max(1.0, num_lists) + else: + num_lists = max(len(val), num_lists) + + # Construct array of kwargs dicts, each element of the list is a different + # **kwargs dict. each kwargs dict gives a different combination of + # the possible values of the kwargs + + # initialize array + list_of_kwarg_dicts = np.array([dict() for x in range(num_lists)]) + + # fill in array + for i in np.arange(num_lists): + list_of_kwarg_dicts[i] = {} + for key in keywords.keys(): + # if it's a string, use it (there's only one) + if isinstance(keywords[key], str): + list_of_kwarg_dicts[i][key] = keywords[key] + # if there are more options, use the i'th val + elif i < len(keywords[key]): + list_of_kwarg_dicts[i][key] = keywords[key][i] + # if there are not more options, use the 0'th val + else: + list_of_kwarg_dicts[i][key] = keywords[key][0] + + return list_of_kwarg_dicts + + class TestOffAxisProjection(unittest.TestCase): @classmethod def setUpClass(cls): From b7c66c10d25691e9d63819926ed2db154c6ad4de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Robert?= Date: Sat, 6 May 2023 11:36:00 +0200 Subject: [PATCH 3/5] DOC: update documentation for the yt.testing module --- doc/source/reference/api/api.rst | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/doc/source/reference/api/api.rst b/doc/source/reference/api/api.rst index 47e67d5706b..61b63f2c15f 100644 --- a/doc/source/reference/api/api.rst +++ b/doc/source/reference/api/api.rst @@ -824,7 +824,10 @@ Cosmology Calculator Testing Infrastructure ---------------------- -The first set of functions are all provided by NumPy. +The core set of testing functions are re-exported from NumPy, +and are deprecated (prefer using +`numpy.testing `_ +directly). .. autosummary:: @@ -839,14 +842,28 @@ The first set of functions are all provided by NumPy. ~yt.testing.assert_allclose ~yt.testing.assert_raises -These are yt-provided functions: +`unyt.testing `_ +also provides some specialized functions for comparing arrays in a units-aware +fashion. + +Finally, yt provides the following functions: .. autosummary:: ~yt.testing.assert_rel_equal ~yt.testing.amrspace - ~yt.testing.fake_random_ds ~yt.testing.expand_keywords + ~yt.testing.fake_random_ds + ~yt.testing.fake_amr_ds + ~yt.testing.fake_particle_ds + ~yt.testing.fake_tetrahedral_ds + ~yt.testing.fake_hexahedral_ds + ~yt.testing.small_fake_hexahedral_ds + ~yt.testing.fake_stretched_ds + ~yt.testing.fake_vr_orientation_test_ds + ~yt.testing.fake_sph_orientation_ds + ~yt.testing.fake_sph_grid_ds + ~yt.testing.fake_octree_ds These are for the pytest infrastructure: From 74fcf7e419b598586246f7875724fcb5c477c504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Robert?= Date: Sat, 6 May 2023 12:54:06 +0200 Subject: [PATCH 4/5] TST: cleanup calls to deprecated test functions --- yt/data_objects/tests/test_sph_data_objects.py | 9 ++------- yt/frontends/cholla/tests/test_outputs.py | 4 +++- yt/frontends/chombo/tests/test_outputs.py | 9 +++------ yt/frontends/enzo/tests/test_outputs.py | 4 +--- yt/frontends/enzo_e/tests/test_outputs.py | 3 ++- yt/frontends/exodus_ii/tests/test_outputs.py | 4 +++- yt/frontends/fits/tests/test_outputs.py | 9 +++------ yt/frontends/flash/tests/test_outputs.py | 3 +-- yt/frontends/gadget_fof/tests/test_outputs.py | 9 ++------- yt/frontends/gamer/tests/test_outputs.py | 9 +++------ yt/frontends/gdf/tests/test_outputs_nose.py | 9 +++------ yt/frontends/halo_catalog/tests/test_outputs.py | 9 ++------- yt/frontends/moab/tests/test_c5.py | 9 ++------- yt/frontends/nc4_cm1/tests/test_outputs.py | 4 +++- yt/frontends/open_pmd/tests/test_outputs.py | 9 ++------- yt/frontends/owls_subfind/tests/test_outputs.py | 4 +++- yt/frontends/ramses/tests/test_outputs.py | 9 ++------- yt/frontends/rockstar/tests/test_outputs.py | 4 +++- yt/frontends/swift/tests/test_outputs.py | 8 ++------ yt/frontends/ytdata/tests/test_unit.py | 2 +- .../coordinates/tests/test_spherical_coordinates.py | 3 ++- yt/tests/test_funcs.py | 3 ++- yt/utilities/answer_testing/framework.py | 3 +-- yt/utilities/answer_testing/level_sets_tests.py | 2 +- yt/utilities/lib/cykdtree/tests/test_utils.py | 2 +- yt/utilities/tests/test_cosmology.py | 9 ++------- yt/visualization/tests/test_color_maps.py | 3 ++- 27 files changed, 57 insertions(+), 98 deletions(-) diff --git a/yt/data_objects/tests/test_sph_data_objects.py b/yt/data_objects/tests/test_sph_data_objects.py index e29b5338ce0..6d6cd0ab4d6 100644 --- a/yt/data_objects/tests/test_sph_data_objects.py +++ b/yt/data_objects/tests/test_sph_data_objects.py @@ -1,14 +1,9 @@ import numpy as np -from numpy.testing import assert_equal +from numpy.testing import assert_almost_equal, assert_equal from yt import SlicePlot, add_particle_filter from yt.loaders import load -from yt.testing import ( - assert_almost_equal, - fake_sph_grid_ds, - fake_sph_orientation_ds, - requires_file, -) +from yt.testing import fake_sph_grid_ds, fake_sph_orientation_ds, requires_file def test_point(): diff --git a/yt/frontends/cholla/tests/test_outputs.py b/yt/frontends/cholla/tests/test_outputs.py index 9d81a70baa9..2e77fa2f4f5 100644 --- a/yt/frontends/cholla/tests/test_outputs.py +++ b/yt/frontends/cholla/tests/test_outputs.py @@ -1,6 +1,8 @@ +from numpy.testing import assert_equal + import yt from yt.frontends.cholla.api import ChollaDataset -from yt.testing import assert_equal, requires_file, requires_module +from yt.testing import requires_file, requires_module from yt.utilities.answer_testing.framework import ( data_dir_load, requires_ds, diff --git a/yt/frontends/chombo/tests/test_outputs.py b/yt/frontends/chombo/tests/test_outputs.py index 65ee0ed23bd..782f5fe975a 100644 --- a/yt/frontends/chombo/tests/test_outputs.py +++ b/yt/frontends/chombo/tests/test_outputs.py @@ -1,10 +1,7 @@ +from numpy.testing import assert_equal + from yt.frontends.chombo.api import ChomboDataset, Orion2Dataset, PlutoDataset -from yt.testing import ( - assert_equal, - requires_file, - requires_module, - units_override_check, -) +from yt.testing import requires_file, requires_module, units_override_check from yt.utilities.answer_testing.framework import ( data_dir_load, requires_ds, diff --git a/yt/frontends/enzo/tests/test_outputs.py b/yt/frontends/enzo/tests/test_outputs.py index 88479636416..353fac14d1e 100644 --- a/yt/frontends/enzo/tests/test_outputs.py +++ b/yt/frontends/enzo/tests/test_outputs.py @@ -1,12 +1,10 @@ import numpy as np +from numpy.testing import assert_almost_equal, assert_array_equal, assert_equal from yt.frontends.enzo.api import EnzoDataset from yt.frontends.enzo.fields import NODAL_FLAGS from yt.testing import ( assert_allclose_units, - assert_almost_equal, - assert_array_equal, - assert_equal, requires_file, requires_module, units_override_check, diff --git a/yt/frontends/enzo_e/tests/test_outputs.py b/yt/frontends/enzo_e/tests/test_outputs.py index a127dae310e..edc89f4e6d9 100644 --- a/yt/frontends/enzo_e/tests/test_outputs.py +++ b/yt/frontends/enzo_e/tests/test_outputs.py @@ -1,8 +1,9 @@ import numpy as np +from numpy.testing import assert_array_equal, assert_equal from yt.frontends.enzo_e.api import EnzoEDataset from yt.frontends.enzo_e.fields import NODAL_FLAGS -from yt.testing import assert_array_equal, assert_equal, requires_file, requires_module +from yt.testing import requires_file, requires_module from yt.utilities.answer_testing.framework import ( FieldValuesTest, PixelizedProjectionValuesTest, diff --git a/yt/frontends/exodus_ii/tests/test_outputs.py b/yt/frontends/exodus_ii/tests/test_outputs.py index fde20bad9eb..55b7714ffe3 100644 --- a/yt/frontends/exodus_ii/tests/test_outputs.py +++ b/yt/frontends/exodus_ii/tests/test_outputs.py @@ -1,4 +1,6 @@ -from yt.testing import assert_array_equal, assert_equal, requires_file +from numpy.testing import assert_array_equal, assert_equal + +from yt.testing import requires_file from yt.utilities.answer_testing.framework import ( GenericArrayTest, data_dir_load, diff --git a/yt/frontends/fits/tests/test_outputs.py b/yt/frontends/fits/tests/test_outputs.py index e7b8a1f42f7..1b1eb73ffb8 100644 --- a/yt/frontends/fits/tests/test_outputs.py +++ b/yt/frontends/fits/tests/test_outputs.py @@ -1,9 +1,6 @@ -from yt.testing import ( - assert_equal, - requires_file, - requires_module, - units_override_check, -) +from numpy.testing import assert_equal + +from yt.testing import requires_file, requires_module, units_override_check from yt.utilities.answer_testing.framework import ( data_dir_load, requires_ds, diff --git a/yt/frontends/flash/tests/test_outputs.py b/yt/frontends/flash/tests/test_outputs.py index 661b63a7d85..120eb471d98 100644 --- a/yt/frontends/flash/tests/test_outputs.py +++ b/yt/frontends/flash/tests/test_outputs.py @@ -1,13 +1,12 @@ from collections import OrderedDict import numpy as np +from numpy.testing import assert_allclose, assert_equal from yt.frontends.flash.api import FLASHDataset, FLASHParticleDataset from yt.loaders import load from yt.testing import ( ParticleSelectionComparison, - assert_allclose, - assert_equal, disable_dataset_cache, requires_file, requires_module, diff --git a/yt/frontends/gadget_fof/tests/test_outputs.py b/yt/frontends/gadget_fof/tests/test_outputs.py index 7647d122e32..6b90a89f33d 100644 --- a/yt/frontends/gadget_fof/tests/test_outputs.py +++ b/yt/frontends/gadget_fof/tests/test_outputs.py @@ -1,13 +1,8 @@ import numpy as np +from numpy.testing import assert_array_equal, assert_equal from yt.frontends.gadget_fof.api import GadgetFOFDataset -from yt.testing import ( - ParticleSelectionComparison, - assert_array_equal, - assert_equal, - requires_file, - requires_module, -) +from yt.testing import ParticleSelectionComparison, requires_file, requires_module from yt.utilities.answer_testing.framework import ( FieldValuesTest, data_dir_load, diff --git a/yt/frontends/gamer/tests/test_outputs.py b/yt/frontends/gamer/tests/test_outputs.py index f832ced7129..c7aae4a8ac9 100644 --- a/yt/frontends/gamer/tests/test_outputs.py +++ b/yt/frontends/gamer/tests/test_outputs.py @@ -1,10 +1,7 @@ +from numpy.testing import assert_array_almost_equal, assert_equal + from yt.frontends.gamer.api import GAMERDataset -from yt.testing import ( - assert_array_almost_equal, - assert_equal, - requires_file, - units_override_check, -) +from yt.testing import requires_file, units_override_check from yt.utilities.answer_testing.framework import ( data_dir_load, requires_ds, diff --git a/yt/frontends/gdf/tests/test_outputs_nose.py b/yt/frontends/gdf/tests/test_outputs_nose.py index 936ce308d92..d650202ec15 100644 --- a/yt/frontends/gdf/tests/test_outputs_nose.py +++ b/yt/frontends/gdf/tests/test_outputs_nose.py @@ -1,10 +1,7 @@ +from numpy.testing import assert_equal + from yt.frontends.gdf.api import GDFDataset -from yt.testing import ( - assert_equal, - requires_file, - requires_module, - units_override_check, -) +from yt.testing import requires_file, requires_module, units_override_check from yt.utilities.answer_testing.framework import ( data_dir_load, requires_ds, diff --git a/yt/frontends/halo_catalog/tests/test_outputs.py b/yt/frontends/halo_catalog/tests/test_outputs.py index 2c12b58f3b6..ce595fdccbc 100644 --- a/yt/frontends/halo_catalog/tests/test_outputs.py +++ b/yt/frontends/halo_catalog/tests/test_outputs.py @@ -1,15 +1,10 @@ import numpy as np +from numpy.testing import assert_array_equal, assert_equal from yt.frontends.halo_catalog.data_structures import YTHaloCatalogDataset from yt.frontends.ytdata.utilities import save_as_dataset from yt.loaders import load as yt_load -from yt.testing import ( - TempDirTest, - assert_array_equal, - assert_equal, - requires_file, - requires_module, -) +from yt.testing import TempDirTest, requires_file, requires_module from yt.units.yt_array import YTArray, YTQuantity from yt.utilities.answer_testing.framework import data_dir_load diff --git a/yt/frontends/moab/tests/test_c5.py b/yt/frontends/moab/tests/test_c5.py index 54b3daf81a4..aba980abae8 100644 --- a/yt/frontends/moab/tests/test_c5.py +++ b/yt/frontends/moab/tests/test_c5.py @@ -1,13 +1,8 @@ import numpy as np +from numpy.testing import assert_almost_equal, assert_equal from yt.frontends.moab.api import MoabHex8Dataset -from yt.testing import ( - assert_almost_equal, - assert_equal, - requires_file, - requires_module, - units_override_check, -) +from yt.testing import requires_file, requires_module, units_override_check from yt.utilities.answer_testing.framework import ( FieldValuesTest, data_dir_load, diff --git a/yt/frontends/nc4_cm1/tests/test_outputs.py b/yt/frontends/nc4_cm1/tests/test_outputs.py index 5ee37e85f20..f28bcb0a6b7 100644 --- a/yt/frontends/nc4_cm1/tests/test_outputs.py +++ b/yt/frontends/nc4_cm1/tests/test_outputs.py @@ -1,5 +1,7 @@ +from numpy.testing import assert_equal + from yt.frontends.nc4_cm1.api import CM1Dataset -from yt.testing import assert_equal, requires_file, units_override_check +from yt.testing import requires_file, units_override_check from yt.utilities.answer_testing.framework import ( FieldValuesTest, GridValuesTest, diff --git a/yt/frontends/open_pmd/tests/test_outputs.py b/yt/frontends/open_pmd/tests/test_outputs.py index bded8359d2c..61c55b4dfb0 100644 --- a/yt/frontends/open_pmd/tests/test_outputs.py +++ b/yt/frontends/open_pmd/tests/test_outputs.py @@ -1,16 +1,11 @@ from itertools import product import numpy as np +from numpy.testing import assert_almost_equal, assert_array_equal, assert_equal from yt.frontends.open_pmd.data_structures import OpenPMDDataset from yt.loaders import load -from yt.testing import ( - assert_almost_equal, - assert_array_equal, - assert_equal, - requires_file, - requires_module, -) +from yt.testing import requires_file, requires_module from yt.utilities.answer_testing.framework import data_dir_load twoD = "example-2d/hdf5/data00000100.h5" diff --git a/yt/frontends/owls_subfind/tests/test_outputs.py b/yt/frontends/owls_subfind/tests/test_outputs.py index e52df2596d1..df5b0f99c33 100644 --- a/yt/frontends/owls_subfind/tests/test_outputs.py +++ b/yt/frontends/owls_subfind/tests/test_outputs.py @@ -1,6 +1,8 @@ import os.path -from yt.testing import assert_equal, requires_module +from numpy.testing import assert_equal + +from yt.testing import requires_module from yt.utilities.answer_testing.framework import ( FieldValuesTest, data_dir_load, diff --git a/yt/frontends/ramses/tests/test_outputs.py b/yt/frontends/ramses/tests/test_outputs.py index 29c46fb40f8..4fad40ef0c4 100644 --- a/yt/frontends/ramses/tests/test_outputs.py +++ b/yt/frontends/ramses/tests/test_outputs.py @@ -1,19 +1,14 @@ import os import numpy as np +from numpy.testing import assert_equal, assert_raises import yt from yt.config import ytcfg from yt.fields.field_detector import FieldDetector from yt.frontends.ramses.api import RAMSESDataset from yt.frontends.ramses.field_handlers import DETECTED_FIELDS, HydroFieldFileHandler -from yt.testing import ( - assert_equal, - assert_raises, - requires_file, - requires_module, - units_override_check, -) +from yt.testing import requires_file, requires_module, units_override_check from yt.utilities.answer_testing.framework import ( FieldValuesTest, PixelizedProjectionValuesTest, diff --git a/yt/frontends/rockstar/tests/test_outputs.py b/yt/frontends/rockstar/tests/test_outputs.py index 8039fe3ff03..920881ec1cc 100644 --- a/yt/frontends/rockstar/tests/test_outputs.py +++ b/yt/frontends/rockstar/tests/test_outputs.py @@ -1,7 +1,9 @@ import os.path +from numpy.testing import assert_equal + from yt.frontends.rockstar.api import RockstarDataset -from yt.testing import ParticleSelectionComparison, assert_equal, requires_file +from yt.testing import ParticleSelectionComparison, requires_file from yt.utilities.answer_testing.framework import ( FieldValuesTest, data_dir_load, diff --git a/yt/frontends/swift/tests/test_outputs.py b/yt/frontends/swift/tests/test_outputs.py index f44f24725d9..7ced79ca1ba 100644 --- a/yt/frontends/swift/tests/test_outputs.py +++ b/yt/frontends/swift/tests/test_outputs.py @@ -1,13 +1,9 @@ import numpy as np +from numpy.testing import assert_almost_equal from yt import load from yt.frontends.swift.api import SwiftDataset -from yt.testing import ( - ParticleSelectionComparison, - assert_almost_equal, - requires_file, - requires_module, -) +from yt.testing import ParticleSelectionComparison, requires_file, requires_module from yt.utilities.on_demand_imports import _h5py as h5py keplerian_ring = "KeplerianRing/keplerian_ring_0020.hdf5" diff --git a/yt/frontends/ytdata/tests/test_unit.py b/yt/frontends/ytdata/tests/test_unit.py index 26c3c98b0ee..30b89dcd204 100644 --- a/yt/frontends/ytdata/tests/test_unit.py +++ b/yt/frontends/ytdata/tests/test_unit.py @@ -3,10 +3,10 @@ import tempfile import numpy as np +from numpy.testing import assert_array_equal from yt.loaders import load, load_uniform_grid from yt.testing import ( - assert_array_equal, assert_fname, fake_random_ds, requires_file, diff --git a/yt/geometry/coordinates/tests/test_spherical_coordinates.py b/yt/geometry/coordinates/tests/test_spherical_coordinates.py index 5cac7ce4b12..3568bbfc6ee 100644 --- a/yt/geometry/coordinates/tests/test_spherical_coordinates.py +++ b/yt/geometry/coordinates/tests/test_spherical_coordinates.py @@ -1,8 +1,9 @@ # Some tests for the Spherical coordinates handler import numpy as np +from numpy.testing import assert_almost_equal, assert_equal -from yt.testing import assert_almost_equal, assert_equal, fake_amr_ds +from yt.testing import fake_amr_ds # Our canonical tests are that we can access all of our fields and we can # compute our volume correctly. diff --git a/yt/tests/test_funcs.py b/yt/tests/test_funcs.py index 9d3504106ea..21ed8b8ca6d 100644 --- a/yt/tests/test_funcs.py +++ b/yt/tests/test_funcs.py @@ -1,7 +1,8 @@ from nose.tools import assert_raises +from numpy.testing import assert_equal from yt.funcs import just_one, levenshtein_distance, validate_axis, validate_center -from yt.testing import assert_equal, fake_amr_ds +from yt.testing import fake_amr_ds from yt.units import YTArray, YTQuantity diff --git a/yt/utilities/answer_testing/framework.py b/yt/utilities/answer_testing/framework.py index 1f53c528e30..088377c31b5 100644 --- a/yt/utilities/answer_testing/framework.py +++ b/yt/utilities/answer_testing/framework.py @@ -21,6 +21,7 @@ from matplotlib import image as mpimg from matplotlib.testing.compare import compare_images from nose.plugins import Plugin +from numpy.testing import assert_almost_equal, assert_equal from yt.config import ytcfg from yt.data_objects.static_output import Dataset @@ -28,8 +29,6 @@ from yt.loaders import load, load_simulation from yt.testing import ( assert_allclose_units, - assert_almost_equal, - assert_equal, assert_rel_equal, skipif, ) diff --git a/yt/utilities/answer_testing/level_sets_tests.py b/yt/utilities/answer_testing/level_sets_tests.py index b4313e37702..bc4a3170e2b 100644 --- a/yt/utilities/answer_testing/level_sets_tests.py +++ b/yt/utilities/answer_testing/level_sets_tests.py @@ -1,6 +1,6 @@ import numpy as np +from numpy.testing import assert_equal -from yt.testing import assert_equal from yt.utilities.answer_testing.framework import AnswerTestingTest diff --git a/yt/utilities/lib/cykdtree/tests/test_utils.py b/yt/utilities/lib/cykdtree/tests/test_utils.py index f3341f09b5c..ab8a6396ba0 100644 --- a/yt/utilities/lib/cykdtree/tests/test_utils.py +++ b/yt/utilities/lib/cykdtree/tests/test_utils.py @@ -1,5 +1,5 @@ import numpy as np -from nose.tools import assert_equal +from numpy.testing import assert_equal from yt.utilities.lib.cykdtree import utils # type: ignore from yt.utilities.lib.cykdtree.tests import assert_less_equal, parametrize diff --git a/yt/utilities/tests/test_cosmology.py b/yt/utilities/tests/test_cosmology.py index 1dcfb633808..e44842045ae 100644 --- a/yt/utilities/tests/test_cosmology.py +++ b/yt/utilities/tests/test_cosmology.py @@ -1,14 +1,9 @@ import os import numpy as np +from numpy.testing import assert_almost_equal, assert_equal -from yt.testing import ( - assert_almost_equal, - assert_equal, - assert_rel_equal, - requires_file, - requires_module, -) +from yt.testing import assert_rel_equal, requires_file, requires_module from yt.units.yt_array import YTArray, YTQuantity from yt.utilities.answer_testing.framework import data_dir_load from yt.utilities.cosmology import Cosmology diff --git a/yt/visualization/tests/test_color_maps.py b/yt/visualization/tests/test_color_maps.py index 9b98c424762..6c99d9e8e7a 100644 --- a/yt/visualization/tests/test_color_maps.py +++ b/yt/visualization/tests/test_color_maps.py @@ -6,9 +6,10 @@ import matplotlib.pyplot as plt import numpy as np from nose.tools import assert_raises +from numpy.testing import assert_almost_equal, assert_equal from yt import make_colormap, show_colormaps -from yt.testing import assert_almost_equal, assert_equal, requires_backend +from yt.testing import requires_backend class TestColorMaps(unittest.TestCase): From d5c760f7675d2a7312a7c4e339806b21fa91bdff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Robert?= Date: Sat, 13 May 2023 14:43:49 +0200 Subject: [PATCH 5/5] DOC: avoid deprecated indirection --- doc/source/analyzing/filtering.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/analyzing/filtering.rst b/doc/source/analyzing/filtering.rst index 59111f5e619..3e5ded476cd 100644 --- a/doc/source/analyzing/filtering.rst +++ b/doc/source/analyzing/filtering.rst @@ -265,7 +265,7 @@ union into a single ``darkmatter`` field. The ``all`` particle type is a special case of this. To create a particle union, you need to import the ``ParticleUnion`` class from -``yt.data_objects.particle_unions``, which you then create and pass into +``yt.data_objects.unions``, which you then create and pass into ``add_particle_union`` on a dataset object. Here is an example, where we union the ``halo`` and ``disk`` particle types