From the unittest document, assertAlmostEqual (a, b) is equivalent by default round(a-b, 7) == 0. so in your case you have:
In [8]: np.log(0) - np.log(0)
Out[8]: nan
In [9]: round(np.log(0) - np.log(0), 7)
Out[9]: nan
In [11]: np.nan == 0
Out[11]: False
This explains why your test fails.
To use it, use unittest2 :
import unittest2
import numpy as np
class Test_Assertions(unittest2.TestCase):
def test_float_inf(self):
self.assertAlmostEqual(float('inf'), float('inf'))
def test_numpy_inf(self):
self.assertAlmostEqual(np.log(0),np.log(0))
unittest2.main()
Conclusion:
..
----------------------------------------------------------------------
Ran 2 tests in 0.000s
OK
N.B: unittest2 assertAlmostEqual() , , , ( ), . python (2.7), unittest2 ( , python 2.7 > ).
, :)