tf.test.TestCase

TensorFlow 1 version View source on GitHub

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 source

Assert that elements in a Tensor are all in a given range.

Args
target The numpy ndarray, or anything that can be converted into a numpy ndarray (including Tensor).
lower_bound lower bound of the range
upper_bound upper bound of the range
open_lower_bound (bool) whether the lower bound is open (i.e., > rather than the default >=)
open_upper_bound (bool) whether the upper bound is open (i.e., < rather than the default <=)

Raises
AssertionError if the value tensor does not have an ordered numeric type (float* or int*), or if there are nan values, or if any of the elements do not fall in the specified range.

assertAllInSet

View source

Assert that elements of a Tensor are all in a given closed set.

Args
target The numpy ndarray, or anything that can be converted into a numpy ndarray (including Tensor).
expected_set (list, tuple or set) The closed set that the elements of the value of target are expected to fall into.

Raises
AssertionError if any of the elements do not fall into expected_set.

assertAllLess

View source

Assert element values are all less 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.

assertAllLessEqual

View source

Assert element values are all less 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.

assertAlmostEqual

Fail if the two objects are unequal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing that the difference between the two objects is more than the given delta.

Note that decimal places (from zero) are usually not the same as significant digits (measured from the most significant digit).

If the two objects compare equal then they will automatically compare almost equal.

assertAlmostEquals

assertArrayNear

View source

Asserts that two float arrays are near each other.

Checks that for all elements of farray1 and farray2 |f1 - f2| < err. Asserts a test failure if not.

Args
farray1 a list of float values.
farray2 a list of float values.
err a float value.
msg Optional message to report on failure.

assertBetween

Asserts that value is between minv and maxv (inclusive).

assertCommandFails

Asserts a shell command fails and the error matches a regex in a list.

Args
command List or string representing the command to run.
regexes the list of regular expression strings.
env Dictionary of environment variable settings. If None, no environment variables will be set for the child process. This is to make tests more hermetic. NOTE: this behavior is different than the standard subprocess module.
close_fds Whether or not to close all open fd's in the child after forking.
msg Optional message to report on failure.

assertCommandSucceeds

Asserts that a shell command succeeds (i.e. exits with code 0).

Args
command List or string representing the command to run.
regexes List of regular expression byte strings that match success.
env Dictionary of environment variable settings. If None, no environment variables will be set for the child process. This is to make tests more hermetic. NOTE: this behavior is different than the standard subprocess module.
close_fds Whether or not to close all open fd's in the child after forking.
msg Optional message to report on failure.