Skip to content

Regression testing

becot85 edited this page Aug 5, 2016 · 16 revisions

NuGridPy Test Platform

NuGridPy uses python's unittest framework to do most of its regression testing. Jupyter notebooks provide additional testing, and the execution of these unit tests and notebooks is done through Travis CI. For information on NuGrid's regression testing platform in general, see the NuGridDoc regression testing page.

unittest

Python's unittest package is a modular testing framework which allows python scripts to be aggregated together into test cases (unittest.TestCase) and ultimately a test suite. The documentation for the unittest module is available here. A general outline of how to build a unit test for NuGridPy is as follows:

  1. Make a new python script, e.g. tests.py, and import unittest.
  2. Define a test class and pass it the TestCase object, e.g. class TestPlots(unittest.TestCase)
  3. Within this class, define any number of test functions the same as you would define a regular python function, e.g. def test_abu_chart(<args>):
  4. At the end of the python script, outside the class definition, add the following.
    if \_\_name\_\_=='\_\_main\_\_':
        unittest.main()

And you're done! A test script can contain any number of test classes, and a test class can contain any number of test functions. The tests themselves live in their own directory within the NuGridPy repository.

Other tests

Other python test packages such as nosetest are being investigated and may be implemented in the future. Jupyter (ipython) notebooks can also be useful for testing and are implemented into the test suite with Travis CI using nbconvert and executed independently of the unit tests.

Running the tests

The test suite will run automatically through Travis CI with each commit or pull request to the NuGridPy repository. Which tests are run can be customized by editing the .travis.yml script. If you'd like to run the tests manually, take the following steps:

  1. Ensure your PYTHONPATH is pointing to the NuGridPy parent directory
  2. Ensure your current local directory location is not within the NuGridPy directory.
  3. Issue the command python -m NuGridPy.regression_tests.test where test is the .py test script that you'd like to execute.

Clone this wiki locally