[Numpy-discussion] numpy and unittests
robert.kern at gmail.com
Mon Aug 7 13:04:24 CDT 2006
Christian Meesters wrote:
> I used to work with some unittest scripts for a bigger project of mine. Now
> that I started the project again the tests don't work anymore, using numpy
> version '0.9.5.2100' .
> The errors I get look are like this:
> ERROR: _normalize() should return dataset scaled between 0 and 1
> Traceback (most recent call last):
> File "testingSAXS.py", line 265, in testNormalization
> File "/usr/lib64/python2.4/unittest.py", line 332, in failUnlessEqual
> if not first == second:
> line 174, in __eq__
> if self.intensity == other.intensity:
> ValueError: The truth value of an array with more than one element is
> ambiguous. Use a.any() or a.all()
> The 'self.intensity' objects are 1D-arrays containing integers <= 1E6.
> The unittest script looks like:
> if __name__=='__main__':
> from Data import *
> from Utils import *
> import unittest
> def test__eq__(self):
> """__eq__ should return True with identical array data"""
> self.assert_(self.test1 == self.test2)
> suite = unittest.TestSuite()
> Any ideas what I have to change? (Possibly trivial, but I have no clue.)
self.assert_((self.test1 == self.test2).all())
I'm afraid that your test was always broken. Numeric used the convention that if
*any* value in a boolean array was True, then the array would evaluate to True
when used as a truth value in an if: clause. However, you almost certainly
wanted to test that *all* of the values were True. This is why we now raise an
exception; lots of people got tripped up over that.
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Numpy-discussion