[SciPy-Dev] Generator tests

Ralf Gommers ralf.gommers@googlemail....
Sat Jul 14 09:17:58 CDT 2012


On Fri, Jul 13, 2012 at 11:57 AM, Pauli Virtanen <pav@iki.fi> wrote:

> Ralf Gommers <ralf.gommers <at> googlemail.com> writes:
> [clip]
> > in the test or code. Plus, it once again shows how
> > annoying generator tests are; can't see which method is
> > failing.
>
> Here's a recommendation for generator test:
>
> - No computation related to the features tested should be
>   done in the test_* generator function, but delegated to
>   a corresponding _check_* function (can be inside the
>   generator, to share namespace).
>
> - The generators should be used *solely* for loops over parameters.
>
> - These parameters should *not* be arrays.
>
>   If a parameter is "complicated", as in the case of ARPACK
>   tests, wrap it into a class with a descriptive __repr__ method.
>
> Like so:
>
> def test_foo():
>     x = [1, 2, 3]
>     z = 9
>
>     def check(a, b):
>         x = a + b + z
>         y = a - b + z
>         assert x == y + 2*b
>
>     for a in [1, 2, 3]:
>         for b in [4, 5, 6]:
>             yield check, a, b


That's good advice. The ARPACK tests are a lot easier to deal with due to
doing it like this. We should also add the above to
https://github.com/numpy/numpy/blob/master/doc/TESTS.rst.txt

Ralf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-dev/attachments/20120714/a7c6e243/attachment.html 


More information about the SciPy-Dev mailing list