assert_utils.py

Functions for making assertions about OpenMDAO Systems.

class openmdao.utils.assert_utils.SkipParameterized[source]

Bases: object

Replaces the parameterized class, skipping decorated test cases.

classmethod expand(input, name_func=None, doc_func=None, skip_on_empty=False, **legacy)[source]

Decorate a test so that it raises a SkipTest.

Parameters
inputiterable

Not used (part of parameterized API).

name_funcfunction

Not used (part of parameterized API).

doc_funcfunction

Not used (part of parameterized API).

skip_on_emptybool

Not used (part of parameterized API).

**legacydict

Not used (part of parameterized API).

Returns
function

The wrapper function.

openmdao.utils.assert_utils.assert_check_partials(data, atol=1e-06, rtol=1e-06)[source]

Raise assertion if any entry from the return from check_partials is above a tolerance.

Parameters
datadict of dicts of dicts
First key:

is the component name;

Second key:

is the (output, input) tuple of strings;

Third key:

is one of [‘rel error’, ‘abs error’, ‘magnitude’, ‘J_fd’, ‘J_fwd’, ‘J_rev’];

For ‘rel error’, ‘abs error’, ‘magnitude’ the value is: A tuple containing norms for

forward - fd, adjoint - fd, forward - adjoint.

For ‘J_fd’, ‘J_fwd’, ‘J_rev’ the value is: A numpy array representing the computed

Jacobian for the three different methods of computation.

atolfloat

absolute error. Default is 1e-6.

rtolfloat

relative error. Default is 1e-6.

openmdao.utils.assert_utils.assert_equal_arrays(a1, a2)[source]

Check that two arrays are equal.

This is a simplified method useful when the arrays to be compared may not be numeric. It simply compares the shapes of the two arrays and then does a value by value comparison.

Parameters
a1array

The first array to compare.

a2array

The second array to compare.

openmdao.utils.assert_utils.assert_near_equal(actual, desired, tolerance=1e-15)[source]

Check relative error.

Determine that the relative error between actual and desired is within tolerance. If desired is zero, then use absolute error.

Parameters
actualfloat, array-like, dict

The value from the test.

desiredfloat, array-like, dict

The value expected.

tolerancefloat

Maximum relative error (actual - desired) / desired.

Returns
float

The error.

openmdao.utils.assert_utils.assert_no_approx_partials(system, include_self=True, recurse=True)[source]

Raise assertion error if any component within system is using approximated partials.

Parameters
systemSystem

The system under which to search for approximated partials.

include_selfbool

If True, include this system in the iteration.

recursebool

If True, iterate over the whole tree under this system.

Raises
AssertionError

If a subsystem of group is found to be using approximated partials.

openmdao.utils.assert_utils.assert_no_dict_jacobians(system, include_self=True, recurse=True)[source]

Raise an assertion error if any Group within system is found to be using dictionary jacobians.

Parameters
systemSystem

The system under which to search for approximated partials.

include_selfbool

If True, include this system in the iteration.

recursebool

If True, iterate over the whole tree under this system.

Raises
AssertionError

If a subsystem of group is found to be using approximated partials.

openmdao.utils.assert_utils.assert_no_warning(category, msg=None)[source]

Context manager asserting that a warning is not issued.

Parameters
categoryclass

The class of the warning.

msgstr or None

The text of the warning. If None then only the warning class will be checked.

Raises
AssertionError

If the warning is raised.

openmdao.utils.assert_utils.assert_rel_error(test_case, actual, desired, tolerance=1e-15)[source]

Check relative error.

Determine that the relative error between actual and desired is within tolerance. If desired is zero, then use absolute error.

Parameters
test_caseunittest.TestCase

TestCase instance used for assertions.

actualfloat, array-like, dict

The value from the test.

desiredfloat, array-like, dict

The value expected.

tolerancefloat

Maximum relative error (actual - desired) / desired.

Returns
float

The error.

openmdao.utils.assert_utils.assert_warning(category, msg)[source]

Context manager asserting that a warning is issued.

Parameters
categoryclass

The class of the expected warning.

msgstr

The text of the expected warning.

Raises
AssertionError

If the expected warning is not raised.

openmdao.utils.assert_utils.assert_warnings(expected_warnings)[source]

Context manager asserting that expected warnings are issued.

Parameters
expected_warningsiterable of (class, str)

The category and text of the expected warnings.

Raises
AssertionError

If all the expected warnings are not raised.

openmdao.utils.assert_utils.skip_helper(msg)[source]

Raise a SkipTest.

Parameters
msgstr

The skip messaage.

Raises
SkipTest