21. Unit test support

sasmodels.model_test

Run model unit tests.

Usage:

python -m sasmodels.model_test [opencl|dll|opencl_and_dll] model1 model2 ...

if model1 is 'all', then all except the remaining models will be tested

Each model is tested using the default parameters at q=0.1, (qx, qy)=(0.1, 0.1), and the ER and VR are computed. The return values at these points are not considered. The test is only to verify that the models run to completion, and do not produce inf or NaN.

Tests are defined with the tests attribute in the model.py file. tests is a list of individual tests to run, where each test consists of the parameter values for the test, the q-values and the expected results. For the effective radius test, the q-value should be ‘ER’. For the VR test, the q-value should be ‘VR’. For 1-D tests, either specify the q value or a list of q-values, and the corresponding I(q) value, or list of I(q) values.

That is:

tests = [
    [ {parameters}, q, I(q)],
    [ {parameters}, [q], [I(q)] ],
    [ {parameters}, [q1, q2, ...], [I(q1), I(q2), ...]],

    [ {parameters}, (qx, qy), I(qx, Iqy)],
    [ {parameters}, [(qx1, qy1), (qx2, qy2), ...],
                    [I(qx1, qy1), I(qx2, qy2), ...]],

    [ {parameters}, 'ER', ER(pars) ],
    [ {parameters}, 'VR', VR(pars) ],
    ...
]

Parameters are key:value pairs, where key is one of the parameters of the model and value is the value to use for the test. Any parameters not given in the parameter list will take on the default parameter value.

Precision defaults to 5 digits (relative).

sasmodels.model_test.invalid_pars(partable, pars)

Return a list of parameter names that are not part of the model.

sasmodels.model_test.is_near(target, actual, digits=5)

Returns true if actual is within digits significant digits of target.

sasmodels.model_test.main(*models)

Run tests given is models.

Returns 0 if success or 1 if any tests fail.

sasmodels.model_test.make_suite(loaders, models)

Construct the pyunit test suite.

loaders is the list of kernel drivers to use, which is one of [“dll”, “opencl”], [“dll”] or [“opencl”]. For python models, the python driver is always used.

models is the list of models to test, or [“all”] to test all models.

sasmodels.model_test.model_tests()

Test runner visible to nosetests.

Run “nosetests sasmodels” on the command line to invoke it.

sasmodels.model_test.run_one(model)

Run the tests for a single model, printing the results to stdout.

model can by a python file, which is handy for checking user defined plugin models.