[SciPy-Dev] new tests in sparse

Pauli Virtanen pav@iki...
Mon Jun 3 14:28:12 CDT 2013

Blake Griffith <blake.a.griffith <at> gmail.com> writes:
> I think rewriting this test suite, with paramterized
> dtypes and data would be worth the effort I have a week
> before I start the next part of my GSoC timeline which
> I think is enough time. It also will make my life easier
> for the rest of the summer.
> Does this sound too ambitious to do in a week?

Extending the dtypes covered is certainly doable in a week, 
the test_base.py file is not that large --- depending on
how you approach the problem.

Of course, if you include the time it takes to fix the bugs
uncovered, that may take longer :)

It may be easiest to *not* try to do anything very ambitious,
but instead refactor it test-by-test in those cases where
multiple-dtype testing makes sense. The point here being that
I think we shouldn't spend more time on cleaning the tests
up than necessary, so the simplest solution that gets the
test coverage extended is probably the best one.

I'd do the dtype extension like this:

    def test_something(self):
        mat = np.array([[1,2],[3,4]], dtype=dtype)
        spmat = self.spmatrix(mat)
        assert_array_equal(spmat.todense(), mat)


    def test_something(self):
        def check(dtype):
            mat = np.array([[1,2],[3,4]], dtype=dtype)
            spmat = self.spmatrix(mat)
            assert_array_equal(spmat.todense(), mat)

        for dtype in SUPPORTED_DTYPES:
            yield check, dtype

where SUPPORTED_DTYPES is defined somewhere above, as a global
or as a class attribute.

Plus: ensure that the test class doesn't inherit from TestCase;
the inheritance needs to be removed from the class factory
function `sparse_test_class`.

I'd avoid refactoring test matrices to class-level ones, and
would just cast the test matrices in the tests to an appropriate
dtype in the check() method.

The above is of course an opinion done without starting to
it myself (I refactored the file already once, though, but
different aspect).

Pauli Virtanen

More information about the SciPy-Dev mailing list