unyt.testing module¶
Utilities for writing tests
-
unyt.testing.
assert_allclose_units
(actual, desired, rtol=1e-07, atol=0, **kwargs)[source]¶ Raise an error if two objects are not equal up to desired tolerance
This is a wrapper for
numpy.testing.assert_allclose()
that also verifies unit consistencyParameters: - actual (array-like) – Array obtained (possibly with attached units)
- desired (array-like) – Array to compare with (possibly with attached units)
- rtol (float, optional) – Relative tolerance, defaults to 1e-7
- atol (float or quantity, optional) – Absolute tolerance. If units are attached, they must be consistent
with the units of
actual
anddesired
. If no units are attached, assumes the same units asdesired
. Defaults to zero.
See also
Notes
Also accepts additional keyword arguments accepted by
numpy.testing.assert_allclose()
, see the documentation of that function for details.Examples
>>> import unyt as u >>> actual = [1e-5, 1e-3, 1e-1]*u.m >>> desired = actual.to("cm") >>> assert_allclose_units(actual, desired)
-
unyt.testing.
assert_array_equal_units
(x, y, **kwargs)[source]¶ A thin wrapper around
numpy.testing.assert_array_equal()
that also verifies unit consistency Arrays without units are considered dimensionless.Parameters: - x (array_like) – The actual object to check.
- y (array_like) – The desired, expected object.
See also
numpy.testing.assert_array_equal()
Notes
Also accepts additional keyword arguments accepted by
numpy.testing.assert_array_equel()
, see the documentation of that function for details.