[NumPy-Tickets] [NumPy] #1959: assert_equal should test for equality, not for inequality

NumPy Trac numpy-tickets@scipy....
Fri Oct 7 03:45:24 CDT 2011


#1959: assert_equal should test for equality, not for inequality
---------------------+------------------------------------------------------
 Reporter:  ezander  |       Owner:  somebody   
     Type:  defect   |      Status:  new        
 Priority:  normal   |   Milestone:  Unscheduled
Component:  Other    |     Version:  1.6.0      
 Keywords:           |  
---------------------+------------------------------------------------------
 I just had the strange indicent that I had two objects, call them a and b,
 that compared fine when I used {{{self.assertEqual(a, b)}}} in a
 {{{unittest.TestCase}}} derived class, but failed when I used
 {{{assert_equal(a, b)}}} from {{{numpy.testing}}}. The reason for this
 strange behaviour was that {{{assertEqual}}} uses something like
 {{{not(a==b)}}}  in its test, while {{{numpy.assert_equal}}} uses
 {{{a!=b}}}. Therefore, the standard unittest uses {{{__eq__}}} to compare
 the objects, while numpy uses {{{__ne__}}}, which I hadn't overwritten.
 Sure, it was partly my fault here, because I had forgotten to overwrite
 {{{__ne__}}} appropriately, but there can also be cases, where this is on
 purpose that e.g. both return True (just consider NaN). So, the question
 is which of both test is more appropriate for {{{assert_equal}}}. I think,
 {{{not(a==b)}}} would be the right one, as I am asking for the objects to
 be equal, and not for them to be not unequal (then the function should be
 called something like {{{assert_not_unequal}}} or
 {{{assert_not_not_equal}}}).

-- 
Ticket URL: <http://projects.scipy.org/numpy/ticket/1959>
NumPy <http://projects.scipy.org/numpy>
My example project


More information about the NumPy-Tickets mailing list