datarray.testing package¶
Submodules¶
datarray.testing.testlib module¶
Module defining the main test entry point exposed at the top level.
-
datarray.testing.testlib.
test
(doctests=True, extra_argv=None, **kw)¶ Run the nitime test suite using nose.
- Parameters
doctests (bool, optional (default True)) – If true, also run the doctests in all docstrings.
kw (dict) – Any other keywords are passed directly to nose.TestProgram(), which itself is a subclass of unittest.TestProgram().
datarray.testing.utils module¶
datarray unit testing utilities
-
datarray.testing.utils.
assert_datarray_equal
(x, y, err_msg='', verbose=True)¶ Raise an AssertionError if two datarrays are not equal.
Given two datarrays, assert that the shapes are equal, axes are equal, and all elements of the datarrays are equal. Given two scalars assert equality. In contrast to the standard usage in numpy, NaNs are compared like numbers, no assertion is raised if both objects have NaNs in the same positions.
The usual caution for verifying equality with floating point numbers is advised.
- Parameters
x ({datarray, scalar}) – If you are testing a datarray method, for example, then this is the datarray (or scalar) returned by the method.
y ({datarray, scalar}) – This datarray represents the expected result. If x is not equal to y, then an AssertionError is raised.
err_msg (str) – If x is not equal to y, then the string err_msg will be added to the top of the AssertionError message.
verbose (bool) – If True, the conflicting values are appended to the error message.
- Returns
- Return type
None
- Raises
AssertionError – If actual and desired datarrays are not equal.
Examples
If the two datarrays are equal then None is returned:
>>> from datarray.testing import assert_datarray_equal >>> from datarray.datarray import DataArray >>> x = DataArray([1, 2]) >>> y = DataArray([1, 2]) >>> assert_datarray_equal(x, y)
If the two datarrays are not equal then an AssertionError is raised:
>>> x = DataArray([1, 2], ('time',)) >>> y = DataArray([1, 2], ('distance',)) >>> assert_datarray_equal(x, y) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "datarray/testing/utils.py", line 133, in assert_datarray_equal raise AssertionError, err_msg AssertionError: ---------- AXIS NAMES ---------- Items are not equal: item=0 ACTUAL: 'time' DESIRED: 'distance'