Sunday, June 8, 2008

Avoiding __test__ usage

I ran across some existing tests in NumPy today that made me realize there's no particular reason that classes like LinalgTestCase need to be derived from unittest.TestCase. Not sure why that didn't occur to me earlier. Anyway, if the classes with type-specific test methods don't derive from TestCase, nose won't try to run them. I think that this:
class LinalgTestCase:
def test_single(self):
a = array([[1.,2.], [3.,4.]], dtype=single)
b = array([2., 1.], dtype=single), b)

class test_inv(LinalgTestCase, TestCase):
def do(self, a, b):
a_inv = linalg.inv(a)
assert_almost_equal(dot(a, a_inv), identity(a.shape[0]))

is much cleaner-looking than the __test__ solution from June 2nd.