[Numpy-discussion] using assertEqual in unittest to test two np.ndarray?

Grissiom chaos.proton@gmail....
Fri Mar 20 19:31:02 CDT 2009


On Sat, Mar 21, 2009 at 05:03, <josef.pktd@gmail.com> wrote:

> for testing purposes it is available in numpy testing:
> from numpy.testing import assert_equal,  assert_almost_equal,
> assert_array_equal
> >>> a = np.array([  1.,   2.,  np.NaN,   4.])
> >>> assert_array_equal(a,a)
>
> does not raise AssertionError
>
> >>> assert_array_equal(a,a+1)
> Traceback (most recent call last):
>   File "<pyshell#6>", line 1, in <module>
>    assert_array_equal(a,a+1)
>  File "C:\Programs\Python25\lib\site-packages\numpy\testing\utils.py",
> line 303, in assert_array_equal
>    verbose=verbose, header='Arrays are not equal')
>  File "C:\Programs\Python25\lib\site-packages\numpy\testing\utils.py",
> line 295, in assert_array_compare
>    raise AssertionError(msg)
> AssertionError:
> Arrays are not equal
>
> (mismatch 100.0%)
>  x: array([  1.,   2.,  NaN,   4.])
>  y: array([  2.,   3.,  NaN,   5.])
>

Great! Thanks! In my case, a NaN is indicating something goes wrong and I
want testing fail on it. So it meet my demand.

One thing more, when I help(np.testing) I only got this:
=============================================
Help on package numpy.testing in numpy:

NAME
    numpy.testing - Common test support for all numpy test scripts.

FILE
    /usr/lib/python2.5/site-packages/numpy/testing/__init__.py

DESCRIPTION
    This single module should provide all the common functionality for numpy
tests
    in a single location, so that test scripts can just import it and work
right
    away.

PACKAGE CONTENTS
    decorators
    noseclasses
    nosetester
    nulltester
    numpytest
    parametric
    setup
    setupscons
    utils

DATA
    verbose = 0
================================================

So I have to dir it to see is there any other useful functions. It will be
perfect to document package method like assert_equal here.

Thanks very much~;)

-- 
Cheers,
Grissiom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090321/5bdc687f/attachment-0001.html 


More information about the Numpy-discussion mailing list