Testing

class baseclasses.BaseRegTest(ref_file, train=False, comm=None)[source]

The class for handling regression tests.

Parameters
ref_filestr

The name of the reference file, containing its full path.

trainbool, optional

Whether to train the reference values, or test against existing reference values, by default False

commMPI communicator, optional

The MPI comm if testing in parallel, by default None

check_archbool, optional

Whether to check and set the appropriate PETSc arch prior to running tests, by default False. Note this option does not currently work.

add_metadata(metadata)[source]

Add a metadata entry to the reference file, which is not used when checking reference values.

Parameters
metadatadict

The dictionary of metadata to add

assert_allclose(actual, reference, name, rtol, atol, full_name=None)[source]

This is basically a wrapper on numpy.testing.assert_allclose with a generated error message

get_metadata()[source]

Returns the metadata

Returns
dict

The metadata stored in the reference file

par_add_norm(name, values, **kwargs)[source]

Add the norm across values from all processors.

Parameters
namestr

The name of the value

valuesndarray

The array to be added. This must be a numpy array distributed over self.comm

**kwargs

See getTol on how to specif tolerances.

par_add_sum(name, values, **kwargs)[source]

Add the sum of sum of the values from all processors.

Parameters
namestr

The name of the value

valuesndarray

The array to be added. This must be a numpy array distributed over self.comm

**kwargs

See getTol on how to specif tolerances.

par_add_val(name, values, **kwargs)[source]

Add value(values) from parallel process in sorted order

Parameters
namestr

The name of the value

valuesndarray

The array to be added. This must be a numpy array distributed over self.comm

**kwargs

See getTol on how to specif tolerances.

readRef()[source]

Read in the reference file on the root proc, then broadcast to all procs

root_add_dict(name, d, **kwargs)[source]

Only write from the root proc

Parameters
namestr

The name of the dictionary

ddict

The dictionary to add

**kwargs

See getTol on how to specif tolerances.

root_add_val(name, values, **kwargs)[source]

Add values but only on the root proc

Parameters
namestr

the name of the value

values[type]

[description]

root_print(s)[source]

Print a message on the root proc

Parameters
sstr

The message to print

writeRef()[source]

Write the reference file from the root proc

baseclasses.testing.getTol(**kwargs)[source]

Returns the tolerances based on kwargs. There are two ways of specifying tolerance:

  1. pass in tol which will set atol = rtol = tol

  2. individually set atol and rtol

If any values are unspecified, the default value will be used.

Parameters
atolfloat

absolute tolerance, default: 1E-12

rtolfloat

relative tolerance, default: 1E-12

tolfloat

tolerance. If specified, atol and rtol values are ignored and both set to this value

Returns
rtolfloat

relative tolerance

atolfloat

absolute tolerance

baseclasses.testing.require_mpi(func)[source]

A decorator to skip tests unless mpi4py is available

Examples

@require_mpi
def test_mpi4py(self):
    print(self.comm.rank)