tf.test.TestCase

Base class for tests that need to test TensorFlow.

Child Classes

class failureException

Methods

addCleanup

Add a function, with arguments, to be called when the test is completed. Functions added are called on a LIFO basis and are called after tearDown on test failure or success.

Cleanup items are called even if setUp fails (unlike tearDown).

addTypeEqualityFunc

Add a type specific assertEqual style function to compare a type.

This method is for use by TestCase subclasses that need to register their own type equality functions to provide nicer error messages.

Args
typeobj The data type to call this function on when both values are of the same type in assertEqual().
function The callable taking two arguments and an optional msg= argument that raises self.failureException with a useful error message when the two arguments are not equal.

assertAllClose

View source

Asserts that two structures of numpy arrays or Tensors, have near values.

a and b can be arbitrarily nested structures. A layer of a nested structure can be a dict, namedtuple, tuple or list.

Args
a The expected numpy ndarray, or anything that can be converted into a numpy ndarray (including Tensor), or any arbitrarily nested of structure of these.
b The actual numpy ndarray, or anything that can be converted into a numpy ndarray (including Tensor), or any arbitrarily nested of structure of these.
rtol relative tolerance.
atol absolute tolerance.
msg Optional message to report on failure.

Raises
ValueError if only one of a[p] and b[p] is a dict or a[p] and b[p] have different length, where [p] denotes a path to the nested structure, e.g. given a = [(1, 1), {'d': (6, 7)}] and [p] = [1]['d'], then a[p] = (6, 7).

assertAllCloseAccordingToType

View source

Like assertAllClose, but also suitable for comparing fp16 arrays.

In particular, the tolerance is reduced to 1e-3 if at least one of the arguments is of type float16.

Args
a the expected numpy ndarray or anything can be converted to one.
b the actual numpy ndarray or anything can be converted to one.
rtol relative tolerance.
atol absolute tolerance.
float_rtol relative tolerance for float32.
float_atol absolute tolerance for float32.
half_rtol relative tolerance for float16.
half_atol absolute tolerance for float16.
bfloat16_rtol relative tolerance for bfloat16.
bfloat16_atol absolute tolerance for bfloat16.
msg Optional message to report on failure.

assertAllEqual

View source

Asserts that two numpy arrays or Tensors have the same values.

Args
a the expected numpy ndarray or anything can be converted to one.
b the actual numpy ndarray or anything can be converted to one.
msg Optional message to report on failure.

assertAllGreater

View source

Assert element values are all greater than a target value.

Args
a The numpy ndarray, or anything that can be converted into a numpy ndarray (including Tensor).
comparison_target The target value of comparison.

assertAllGreaterEqual

View source

Assert element values are all greater than or equal to a target value.

Args
a The numpy ndarray, or anything that can be converted into a numpy ndarray (including Tensor).
comparison_target The target value of comparison.

assertAllInRange

View