![]() |
![]() |
Base class for tests that need to test TensorFlow.
tf.test.TestCase(
methodName='runTest'
)
Child Classes
Methods
addCleanup
addCleanup(
*args, **kwargs
)
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
addTypeEqualityFunc(
typeobj, function
)
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
assertAllClose(
a, b, rtol=1e-06, atol=1e-06, msg=None
)
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
assertAllCloseAccordingToType(
a, b, rtol=1e-06, atol=1e-06, float_rtol=1e-06, float_atol=1e-06,
half_rtol=0.001, half_atol=0.001, bfloat16_rtol=0.01, bfloat16_atol=0.01,
msg=None
)
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
assertAllEqual(
a, b, msg=None
)
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
assertAllGreater(
a, comparison_target
)
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
assertAllGreaterEqual(
a, comparison_target
)
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
assertAllInRange(
target, lower_bound, upper_bound, open_lower_bound=False, open_upper_bound=False
)
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
assertAllInSet(
target, expected_set
)
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
assertAllLess(
a, comparison_target
)
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
assertAllLessEqual(
a, comparison_target
)
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
assertAlmostEqual(
first, second, places=None, msg=None, delta=None
)
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
assertAlmostEquals(
*args, **kwargs
)
assertArrayNear
assertArrayNear(
farray1, farray2, err, msg=None
)
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
assertBetween(
value, minv, maxv, msg=None
)
Asserts that value is between minv and maxv (inclusive).
assertCommandFails
assertCommandFails(
command, regexes, env=None, close_fds=True, msg=None
)
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
assertCommandSucceeds(
command, regexes=(b'',), env=None, close_fds=True, msg=None
)
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. |
assertContainsExactSubsequence
assertContainsExactSubsequence(
container, subsequence, msg=None
)
Asserts that "container" contains "subsequence" as an exact subsequence.
Asserts that "container" contains all the elements of "subsequence", in order, and without other elements interspersed. For example, [1, 2, 3] is an exact subsequence of [0, 0, 1, 2, 3, 0] but not of [0, 0, 1, 2, 0, 3, 0].
Args | |
---|---|
container
|
the list we're testing for subsequence inclusion. |
subsequence
|
the list we hope will be an exact subsequence of container. |
msg
|
Optional message to report on failure. |
assertContainsInOrder
assertContainsInOrder(
strings, target, msg=None
)
Asserts that the strings provided are found in the target in order.
This may be useful for checking HTML output.