[pystatsmodels] numpy.testing and unittest

415 views
Skip to first unread message

Vincent Davis

unread,
Apr 30, 2010, 11:50:02 AM4/30/10
to pystat...@googlegroups.com
I'll admit this is a beginner question which is my current state of knowledge about unit testing.

I see that numpy.testing is being used, is there a sort answer/reason as to why it is being used rather that the built in python testing?

What is the chain of events (in brief) when "$ python setup.py test" is run from the command line?

I was testing the SimpleTables using __main__  and a simple print(a==b) statement. I would like to test the output from SimpleTables to be sure that asI muck with it I don't break it. Also I think there is some value in making sure that the results from a model continue to provide the same summary output.

Should I be using numpy.testing or the python unit testing?


josef...@gmail.com

unread,
Apr 30, 2010, 12:05:36 PM4/30/10
to pystat...@googlegroups.com
On Fri, Apr 30, 2010 at 11:50 AM, Vincent Davis <vin...@vincentdavis.net> wrote:
I'll admit this is a beginner question which is my current state of knowledge about unit testing.

I see that numpy.testing is being used, is there a sort answer/reason as to why it is being used rather that the built in python testing?

What is the chain of events (in brief) when "$ python setup.py test" is run from the command line?

I was testing the SimpleTables using __main__  and a simple print(a==b) statement. I would like to test the output from SimpleTables to be sure that asI muck with it I don't break it. Also I think there is some value in making sure that the results from a model continue to provide the same summary output.

Should I be using numpy.testing or the python unit testing?


numpy.testing and statsmodels are using nose as the underlying testing library (easy_install nose)

test are much easier to write with nose than with python's unit testing (although that might change in future)

there is a brief testing description on the scipy trac wiki

for us the main advantage of numpy.testing is also that it provides several asserts (e.g. assert_almost_equal) that work with arrays.

For string the best might be assert_ , which is like the regular assert but it is a function (there are some problems with assert statements in regular code)

e.g.
from numpy.testing import assert_

def test_SimpleTable_1():
    desired = '......'
    parameters = (...)
    actual = SimpleTable(parameters)
    assert_(desired, actual, err_msg='this is a test for SimpleTable with parameters ....')

When you write many test, then test generators are very convenient to write a large number of similar tests with different parameters.

I hope that helps, I don't think we have any tests yet that check string output

Josef



 

Vincent Davis

unread,
Apr 30, 2010, 12:19:59 PM4/30/10
to pystat...@googlegroups.com
Thanks that just what I needed. I see this option assert_string_equal

Is there an reason, to or not to done be able to call the test directly on the module, ie regression.test()

Reference Link

Each NumPy module exposes test in its namespace to run all tests for it. For example, to run all tests for numpy.lib:

>>> np.lib.test()

Examples

>>> result = np.lib.test()
Running unit tests for numpy.lib
...
Ran 976 tests in 3.933s




josef...@gmail.com

unread,
Apr 30, 2010, 12:48:32 PM4/30/10
to pystat...@googlegroups.com
On Fri, Apr 30, 2010 at 12:19 PM, Vincent Davis <vin...@vincentdavis.net> wrote:
Thanks that just what I needed. I see this option assert_string_equal

Is there an reason, to or not to done be able to call the test directly on the module, ie regression.test()

Reference Link

Each NumPy module exposes test in its namespace to run all tests for it. For example, to run all tests for numpy.lib:

>>> np.lib.test()

Examples

>>> result = np.lib.test()
Running unit tests for numpy.lib
...
Ran 976 tests in 3.933s

You can use nosetests directly on the commandline to run just specific tests or testfiles
>nosetests path/to/testfile.py     #alll tests in this file
>nosetests path/to/testfile.py:test_ST2      # specific test, not sure anymore about syntax

the test() function
scikits.statsmodesls.test()
can only be done that explicitely has the test function defined, which for statsmodels is currently only the statsmodels.__init__.py

Since statsmodels is not so large, and nosetests can be used directly, we didn't add it to the __init__.py of any other directory.

Josef

 
Reply all
Reply to author
Forward
0 new messages