Type TestCase
Namespace tensorflow.test
Parent PythonObjectContainer
Interfaces ITestCase
Base class for tests that need to test TensorFlow.
Methods
- assertAllClose
- assertAllClose_dyn
- assertAllCloseAccordingToType
- assertAllCloseAccordingToType
- assertAllCloseAccordingToType
- assertAllCloseAccordingToType
- assertAllCloseAccordingToType
- assertAllCloseAccordingToType
- assertAllCloseAccordingToType
- assertAllCloseAccordingToType
- assertAllCloseAccordingToType
- assertAllCloseAccordingToType_dyn
- assertAllEqual
- assertAllEqual
- assertAllEqual
- assertAllEqual
- assertAllEqual
- assertAllEqual
- assertAllEqual
- assertAllEqual
- assertAllEqual
- assertAllEqual_dyn
- assertAllGreater
- assertAllGreater
- assertAllGreater
- assertAllGreater_dyn
- assertAllGreaterEqual
- assertAllGreaterEqual
- assertAllGreaterEqual
- assertAllGreaterEqual_dyn
- assertAllInRange
- assertAllInRange
- assertAllInRange
- assertAllInRange_dyn
- assertAllInSet
- assertAllInSet
- assertAllInSet
- assertAllInSet_dyn
- assertAllLess
- assertAllLess
- assertAllLess
- assertAllLess_dyn
- assertAllLessEqual
- assertAllLessEqual
- assertAllLessEqual
- assertAllLessEqual_dyn
- assertArrayNear_dyn
- assertDeviceEqual
- assertDeviceEqual_dyn
- assertDTypeEqual
- assertDTypeEqual
- assertDTypeEqual
- assertDTypeEqual_dyn
- assertNDArrayNear_dyn
- assertNear_dyn
- assertNotAllClose
- assertNotAllClose_dyn
- assertNotAllEqual
- assertNotAllEqual_dyn
- assertProtoEquals
- assertProtoEquals_dyn
- assertProtoEqualsVersion
- assertProtoEqualsVersion_dyn
- assertRaisesOpError
- assertRaisesOpError
- assertRaisesOpError_dyn
- assertRaisesWithPredicateMatch
- assertRaisesWithPredicateMatch
- assertRaisesWithPredicateMatch
- assertRaisesWithPredicateMatch
- assertRaisesWithPredicateMatch_dyn
- assertShapeEqual
- assertShapeEqual
- assertShapeEqual
- assertShapeEqual
- assertShapeEqual
- assertShapeEqual
- assertShapeEqual
- assertShapeEqual
- assertShapeEqual
- assertShapeEqual
- assertShapeEqual
- assertShapeEqual
- assertShapeEqual
- assertShapeEqual
- assertShapeEqual
- assertShapeEqual
- assertShapeEqual_dyn
- assertStartsWith
- assertStartsWith
- assertStartsWith_dyn
- cached_session
- cached_session_dyn
- captureWritesToStream
- captureWritesToStream_dyn
- checkedThread
- checkedThread_dyn
- evaluate
- get_temp_dir
- get_temp_dir_dyn
- session
- session_dyn
- test_session
- test_session_dyn
Properties
Public instance methods
object assertAllClose(object a, object b, double rtol, double atol, object msg)
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`.
Parameters
-
objecta - The expected numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor), or any arbitrarily nested of structure of these.
-
objectb - The actual numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor), or any arbitrarily nested of structure of these.
-
doublertol - relative tolerance.
-
doubleatol - absolute tolerance.
-
objectmsg - Optional message to report on failure.
object assertAllClose_dyn(object a, object b, ImplicitContainer<T> rtol, ImplicitContainer<T> atol, object msg)
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`.
Parameters
-
objecta - The expected numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor), or any arbitrarily nested of structure of these.
-
objectb - The actual numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor), or any arbitrarily nested of structure of these.
-
ImplicitContainer<T>rtol - relative tolerance.
-
ImplicitContainer<T>atol - absolute tolerance.
-
objectmsg - Optional message to report on failure.
object assertAllCloseAccordingToType(IEnumerable<object> a, IGraphNodeBase b, double rtol, double atol, double float_rtol, double float_atol, double half_rtol, double half_atol, double bfloat16_rtol, double bfloat16_atol, object msg)
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.
Parameters
-
IEnumerable<object>a - the expected numpy ndarray or anything can be converted to one.
-
IGraphNodeBaseb - the actual numpy ndarray or anything can be converted to one.
-
doublertol - relative tolerance.
-
doubleatol - absolute tolerance.
-
doublefloat_rtol - relative tolerance for float32.
-
doublefloat_atol - absolute tolerance for float32.
-
doublehalf_rtol - relative tolerance for float16.
-
doublehalf_atol - absolute tolerance for float16.
-
doublebfloat16_rtol - relative tolerance for bfloat16.
-
doublebfloat16_atol - absolute tolerance for bfloat16.
-
objectmsg - Optional message to report on failure.
object assertAllCloseAccordingToType(IGraphNodeBase a, IEnumerable<object> b, double rtol, double atol, double float_rtol, double float_atol, double half_rtol, double half_atol, double bfloat16_rtol, double bfloat16_atol, object msg)
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.
Parameters
-
IGraphNodeBasea - the expected numpy ndarray or anything can be converted to one.
-
IEnumerable<object>b - the actual numpy ndarray or anything can be converted to one.
-
doublertol - relative tolerance.
-
doubleatol - absolute tolerance.
-
doublefloat_rtol - relative tolerance for float32.
-
doublefloat_atol - absolute tolerance for float32.
-
doublehalf_rtol - relative tolerance for float16.
-
doublehalf_atol - absolute tolerance for float16.
-
doublebfloat16_rtol - relative tolerance for bfloat16.
-
doublebfloat16_atol - absolute tolerance for bfloat16.
-
objectmsg - Optional message to report on failure.
object assertAllCloseAccordingToType(IGraphNodeBase a, ndarray b, double rtol, double atol, double float_rtol, double float_atol, double half_rtol, double half_atol, double bfloat16_rtol, double bfloat16_atol, object msg)
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.
Parameters
-
IGraphNodeBasea - the expected numpy ndarray or anything can be converted to one.
-
ndarrayb - the actual numpy ndarray or anything can be converted to one.
-
doublertol - relative tolerance.
-
doubleatol - absolute tolerance.
-
doublefloat_rtol - relative tolerance for float32.
-
doublefloat_atol - absolute tolerance for float32.
-
doublehalf_rtol - relative tolerance for float16.
-
doublehalf_atol - absolute tolerance for float16.
-
doublebfloat16_rtol - relative tolerance for bfloat16.
-
doublebfloat16_atol - absolute tolerance for bfloat16.
-
objectmsg - Optional message to report on failure.
object assertAllCloseAccordingToType(IEnumerable<object> a, IEnumerable<object> b, double rtol, double atol, double float_rtol, double float_atol, double half_rtol, double half_atol, double bfloat16_rtol, double bfloat16_atol, object msg)
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.
Parameters
-
IEnumerable<object>a - the expected numpy ndarray or anything can be converted to one.
-
IEnumerable<object>b - the actual numpy ndarray or anything can be converted to one.
-
doublertol - relative tolerance.
-
doubleatol - absolute tolerance.
-
doublefloat_rtol - relative tolerance for float32.
-
doublefloat_atol - absolute tolerance for float32.
-
doublehalf_rtol - relative tolerance for float16.
-
doublehalf_atol - absolute tolerance for float16.
-
doublebfloat16_rtol - relative tolerance for bfloat16.
-
doublebfloat16_atol - absolute tolerance for bfloat16.
-
objectmsg - Optional message to report on failure.
object assertAllCloseAccordingToType(IEnumerable<object> a, ndarray b, double rtol, double atol, double float_rtol, double float_atol, double half_rtol, double half_atol, double bfloat16_rtol, double bfloat16_atol, object msg)
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.
Parameters
-
IEnumerable<object>a - the expected numpy ndarray or anything can be converted to one.
-
ndarrayb - the actual numpy ndarray or anything can be converted to one.
-
doublertol - relative tolerance.
-
doubleatol - absolute tolerance.
-
doublefloat_rtol - relative tolerance for float32.
-
doublefloat_atol - absolute tolerance for float32.
-
doublehalf_rtol - relative tolerance for float16.
-
doublehalf_atol - absolute tolerance for float16.
-
doublebfloat16_rtol - relative tolerance for bfloat16.
-
doublebfloat16_atol - absolute tolerance for bfloat16.
-
objectmsg - Optional message to report on failure.
object assertAllCloseAccordingToType(ndarray a, IGraphNodeBase b, double rtol, double atol, double float_rtol, double float_atol, double half_rtol, double half_atol, double bfloat16_rtol, double bfloat16_atol, object msg)
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.
Parameters
-
ndarraya - the expected numpy ndarray or anything can be converted to one.
-
IGraphNodeBaseb - the actual numpy ndarray or anything can be converted to one.
-
doublertol - relative tolerance.
-
doubleatol - absolute tolerance.
-
doublefloat_rtol - relative tolerance for float32.
-
doublefloat_atol - absolute tolerance for float32.
-
doublehalf_rtol - relative tolerance for float16.
-
doublehalf_atol - absolute tolerance for float16.
-
doublebfloat16_rtol - relative tolerance for bfloat16.
-
doublebfloat16_atol - absolute tolerance for bfloat16.
-
objectmsg - Optional message to report on failure.
object assertAllCloseAccordingToType(ndarray a, IEnumerable<object> b, double rtol, double atol, double float_rtol, double float_atol, double half_rtol, double half_atol, double bfloat16_rtol, double bfloat16_atol, object msg)
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.
Parameters
-
ndarraya - the expected numpy ndarray or anything can be converted to one.
-
IEnumerable<object>b - the actual numpy ndarray or anything can be converted to one.
-
doublertol - relative tolerance.
-
doubleatol - absolute tolerance.
-
doublefloat_rtol - relative tolerance for float32.
-
doublefloat_atol - absolute tolerance for float32.
-
doublehalf_rtol - relative tolerance for float16.
-
doublehalf_atol - absolute tolerance for float16.
-
doublebfloat16_rtol - relative tolerance for bfloat16.
-
doublebfloat16_atol - absolute tolerance for bfloat16.
-
objectmsg - Optional message to report on failure.
object assertAllCloseAccordingToType(ndarray a, ndarray b, double rtol, double atol, double float_rtol, double float_atol, double half_rtol, double half_atol, double bfloat16_rtol, double bfloat16_atol, object msg)
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.
Parameters
-
ndarraya - the expected numpy ndarray or anything can be converted to one.
-
ndarrayb - the actual numpy ndarray or anything can be converted to one.
-
doublertol - relative tolerance.
-
doubleatol - absolute tolerance.
-
doublefloat_rtol - relative tolerance for float32.
-
doublefloat_atol - absolute tolerance for float32.
-
doublehalf_rtol - relative tolerance for float16.
-
doublehalf_atol - absolute tolerance for float16.
-
doublebfloat16_rtol - relative tolerance for bfloat16.
-
doublebfloat16_atol - absolute tolerance for bfloat16.
-
objectmsg - Optional message to report on failure.
object assertAllCloseAccordingToType(IGraphNodeBase a, IGraphNodeBase b, double rtol, double atol, double float_rtol, double float_atol, double half_rtol, double half_atol, double bfloat16_rtol, double bfloat16_atol, object msg)
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.
Parameters
-
IGraphNodeBasea - the expected numpy ndarray or anything can be converted to one.
-
IGraphNodeBaseb - the actual numpy ndarray or anything can be converted to one.
-
doublertol - relative tolerance.
-
doubleatol - absolute tolerance.
-
doublefloat_rtol - relative tolerance for float32.
-
doublefloat_atol - absolute tolerance for float32.
-
doublehalf_rtol - relative tolerance for float16.
-
doublehalf_atol - absolute tolerance for float16.
-
doublebfloat16_rtol - relative tolerance for bfloat16.
-
doublebfloat16_atol - absolute tolerance for bfloat16.
-
objectmsg - Optional message to report on failure.
object assertAllCloseAccordingToType_dyn(object a, object b, ImplicitContainer<T> rtol, ImplicitContainer<T> atol, ImplicitContainer<T> float_rtol, ImplicitContainer<T> float_atol, ImplicitContainer<T> half_rtol, ImplicitContainer<T> half_atol, ImplicitContainer<T> bfloat16_rtol, ImplicitContainer<T> bfloat16_atol, object msg)
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.
Parameters
-
objecta - the expected numpy ndarray or anything can be converted to one.
-
objectb - the actual numpy ndarray or anything can be converted to one.
-
ImplicitContainer<T>rtol - relative tolerance.
-
ImplicitContainer<T>atol - absolute tolerance.
-
ImplicitContainer<T>float_rtol - relative tolerance for float32.
-
ImplicitContainer<T>float_atol - absolute tolerance for float32.
-
ImplicitContainer<T>half_rtol - relative tolerance for float16.
-
ImplicitContainer<T>half_atol - absolute tolerance for float16.
-
ImplicitContainer<T>bfloat16_rtol - relative tolerance for bfloat16.
-
ImplicitContainer<T>bfloat16_atol - absolute tolerance for bfloat16.
-
objectmsg - Optional message to report on failure.
object assertAllEqual(IGraphNodeBase a, IEnumerable<object> b, string msg)
Asserts that two numpy arrays or Tensors have the same values.
Parameters
-
IGraphNodeBasea - the expected numpy ndarray or anything can be converted to one.
-
IEnumerable<object>b - the actual numpy ndarray or anything can be converted to one.
-
stringmsg - Optional message to report on failure.
object assertAllEqual(IGraphNodeBase a, IGraphNodeBase b, string msg)
Asserts that two numpy arrays or Tensors have the same values.
Parameters
-
IGraphNodeBasea - the expected numpy ndarray or anything can be converted to one.
-
IGraphNodeBaseb - the actual numpy ndarray or anything can be converted to one.
-
stringmsg - Optional message to report on failure.
object assertAllEqual(IEnumerable<object> a, IGraphNodeBase b, string msg)
Asserts that two numpy arrays or Tensors have the same values.
Parameters
-
IEnumerable<object>a - the expected numpy ndarray or anything can be converted to one.
-
IGraphNodeBaseb - the actual numpy ndarray or anything can be converted to one.
-
stringmsg - Optional message to report on failure.
object assertAllEqual(IEnumerable<object> a, IEnumerable<object> b, string msg)
Asserts that two numpy arrays or Tensors have the same values.
Parameters
-
IEnumerable<object>a - the expected numpy ndarray or anything can be converted to one.
-
IEnumerable<object>b - the actual numpy ndarray or anything can be converted to one.
-
stringmsg - Optional message to report on failure.
object assertAllEqual(ndarray a, IEnumerable<object> b, string msg)
Asserts that two numpy arrays or Tensors have the same values.
Parameters
-
ndarraya - the expected numpy ndarray or anything can be converted to one.
-
IEnumerable<object>b - the actual numpy ndarray or anything can be converted to one.
-
stringmsg - Optional message to report on failure.
object assertAllEqual(ndarray a, IGraphNodeBase b, string msg)
Asserts that two numpy arrays or Tensors have the same values.
Parameters
-
ndarraya - the expected numpy ndarray or anything can be converted to one.
-
IGraphNodeBaseb - the actual numpy ndarray or anything can be converted to one.
-
stringmsg - Optional message to report on failure.
object assertAllEqual(IEnumerable<object> a, ndarray b, string msg)
Asserts that two numpy arrays or Tensors have the same values.
Parameters
-
IEnumerable<object>a - the expected numpy ndarray or anything can be converted to one.
-
ndarrayb - the actual numpy ndarray or anything can be converted to one.
-
stringmsg - Optional message to report on failure.
object assertAllEqual(IGraphNodeBase a, ndarray b, string msg)
Asserts that two numpy arrays or Tensors have the same values.
Parameters
-
IGraphNodeBasea - the expected numpy ndarray or anything can be converted to one.
-
ndarrayb - the actual numpy ndarray or anything can be converted to one.
-
stringmsg - Optional message to report on failure.
object assertAllEqual_dyn(object a, object b, object msg)
Asserts that two numpy arrays or Tensors have the same values.
Parameters
-
objecta - the expected numpy ndarray or anything can be converted to one.
-
objectb - the actual numpy ndarray or anything can be converted to one.
-
objectmsg - Optional message to report on failure.
object assertAllGreater(ndarray a, object comparison_target)
Assert element values are all greater than a target value.
Parameters
-
ndarraya - The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor).
-
objectcomparison_target - The target value of comparison.
object assertAllGreater(IEnumerable<object> a, object comparison_target)
Assert element values are all greater than a target value.
Parameters
-
IEnumerable<object>a - The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor).
-
objectcomparison_target - The target value of comparison.
object assertAllGreater(IGraphNodeBase a, object comparison_target)
Assert element values are all greater than a target value.
Parameters
-
IGraphNodeBasea - The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor).
-
objectcomparison_target - The target value of comparison.
object assertAllGreater_dyn(object a, object comparison_target)
Assert element values are all greater than a target value.
Parameters
-
objecta - The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor).
-
objectcomparison_target - The target value of comparison.
object assertAllGreaterEqual(IGraphNodeBase a, object comparison_target)
Assert element values are all greater than or equal to a target value.
Parameters
-
IGraphNodeBasea - The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor).
-
objectcomparison_target - The target value of comparison.
object assertAllGreaterEqual(ndarray a, object comparison_target)
Assert element values are all greater than or equal to a target value.
Parameters
-
ndarraya - The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor).
-
objectcomparison_target - The target value of comparison.
object assertAllGreaterEqual(IEnumerable<object> a, object comparison_target)
Assert element values are all greater than or equal to a target value.
Parameters
-
IEnumerable<object>a - The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor).
-
objectcomparison_target - The target value of comparison.
object assertAllGreaterEqual_dyn(object a, object comparison_target)
Assert element values are all greater than or equal to a target value.
Parameters
-
objecta - The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor).
-
objectcomparison_target - The target value of comparison.
object assertAllInRange(ndarray target, object lower_bound, object upper_bound, bool open_lower_bound, bool open_upper_bound)
Assert that elements in a Tensor are all in a given range.
Parameters
-
ndarraytarget - The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor).
-
objectlower_bound - lower bound of the range
-
objectupper_bound - upper bound of the range
-
boolopen_lower_bound - (`bool`) whether the lower bound is open (i.e., > rather than the default >=)
-
boolopen_upper_bound - (`bool`) whether the upper bound is open (i.e., < rather than the default <=)
object assertAllInRange(IEnumerable<object> target, object lower_bound, object upper_bound, bool open_lower_bound, bool open_upper_bound)
Assert that elements in a Tensor are all in a given range.
Parameters
-
IEnumerable<object>target - The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor).
-
objectlower_bound - lower bound of the range
-
objectupper_bound - upper bound of the range
-
boolopen_lower_bound - (`bool`) whether the lower bound is open (i.e., > rather than the default >=)
-
boolopen_upper_bound - (`bool`) whether the upper bound is open (i.e., < rather than the default <=)
object assertAllInRange(IGraphNodeBase target, object lower_bound, object upper_bound, bool open_lower_bound, bool open_upper_bound)
Assert that elements in a Tensor are all in a given range.
Parameters
-
IGraphNodeBasetarget - The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor).
-
objectlower_bound - lower bound of the range
-
objectupper_bound - upper bound of the range
-
boolopen_lower_bound - (`bool`) whether the lower bound is open (i.e., > rather than the default >=)
-
boolopen_upper_bound - (`bool`) whether the upper bound is open (i.e., < rather than the default <=)
object assertAllInRange_dyn(object target, object lower_bound, object upper_bound, ImplicitContainer<T> open_lower_bound, ImplicitContainer<T> open_upper_bound)
Assert that elements in a Tensor are all in a given range.
Parameters
-
objecttarget - The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor).
-
objectlower_bound - lower bound of the range
-
objectupper_bound - upper bound of the range
-
ImplicitContainer<T>open_lower_bound - (`bool`) whether the lower bound is open (i.e., > rather than the default >=)
-
ImplicitContainer<T>open_upper_bound - (`bool`) whether the upper bound is open (i.e., < rather than the default <=)
object assertAllInSet(ndarray target, object expected_set)
Assert that elements of a Tensor are all in a given closed set.
Parameters
-
ndarraytarget - The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor).
-
objectexpected_set - (`list`, `tuple` or `set`) The closed set that the elements of the value of `target` are expected to fall into.
object assertAllInSet(IEnumerable<object> target, object expected_set)
Assert that elements of a Tensor are all in a given closed set.
Parameters
-
IEnumerable<object>target - The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor).
-
objectexpected_set - (`list`, `tuple` or `set`) The closed set that the elements of the value of `target` are expected to fall into.
object assertAllInSet(IGraphNodeBase target, object expected_set)
Assert that elements of a Tensor are all in a given closed set.
Parameters
-
IGraphNodeBasetarget - The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor).
-
objectexpected_set - (`list`, `tuple` or `set`) The closed set that the elements of the value of `target` are expected to fall into.
object assertAllInSet_dyn(object target, object expected_set)
Assert that elements of a Tensor are all in a given closed set.
Parameters
-
objecttarget - The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor).
-
objectexpected_set - (`list`, `tuple` or `set`) The closed set that the elements of the value of `target` are expected to fall into.
object assertAllLess(IGraphNodeBase a, object comparison_target)
Assert element values are all less than a target value.
Parameters
-
IGraphNodeBasea - The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor).
-
objectcomparison_target - The target value of comparison.
object assertAllLess(IEnumerable<object> a, object comparison_target)
Assert element values are all less than a target value.
Parameters
-
IEnumerable<object>a - The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor).
-
objectcomparison_target - The target value of comparison.
object assertAllLess(ndarray a, object comparison_target)
Assert element values are all less than a target value.
Parameters
-
ndarraya - The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor).
-
objectcomparison_target - The target value of comparison.
object assertAllLess_dyn(object a, object comparison_target)
Assert element values are all less than a target value.
Parameters
-
objecta - The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor).
-
objectcomparison_target - The target value of comparison.
object assertAllLessEqual(IGraphNodeBase a, object comparison_target)
Assert element values are all less than or equal to a target value.
Parameters
-
IGraphNodeBasea - The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor).
-
objectcomparison_target - The target value of comparison.
object assertAllLessEqual(IEnumerable<object> a, object comparison_target)
Assert element values are all less than or equal to a target value.
Parameters
-
IEnumerable<object>a - The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor).
-
objectcomparison_target - The target value of comparison.
object assertAllLessEqual(ndarray a, object comparison_target)
Assert element values are all less than or equal to a target value.
Parameters
-
ndarraya - The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor).
-
objectcomparison_target - The target value of comparison.
object assertAllLessEqual_dyn(object a, object comparison_target)
Assert element values are all less than or equal to a target value.
Parameters
-
objecta - The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor).
-
objectcomparison_target - The target value of comparison.
object assertArrayNear_dyn(object farray1, object farray2, object err, object msg)
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.
Parameters
-
objectfarray1 - a list of float values.
-
objectfarray2 - a list of float values.
-
objecterr - a float value.
-
objectmsg - Optional message to report on failure.
void assertDeviceEqual(string device1, string device2, object msg)
Asserts that the two given devices are the same.
Parameters
-
stringdevice1 - A string device name or TensorFlow `DeviceSpec` object.
-
stringdevice2 - A string device name or TensorFlow `DeviceSpec` object.
-
objectmsg - Optional message to report on failure.
object assertDeviceEqual_dyn(object device1, object device2, object msg)
Asserts that the two given devices are the same.
Parameters
-
objectdevice1 - A string device name or TensorFlow `DeviceSpec` object.
-
objectdevice2 - A string device name or TensorFlow `DeviceSpec` object.
-
objectmsg - Optional message to report on failure.
object assertDTypeEqual(IEnumerable<object> target, object expected_dtype)
Assert ndarray data type is equal to expected.
Parameters
-
IEnumerable<object>target - The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor).
-
objectexpected_dtype - Expected data type.
object assertDTypeEqual(IGraphNodeBase target, object expected_dtype)
Assert ndarray data type is equal to expected.
Parameters
-
IGraphNodeBasetarget - The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor).
-
objectexpected_dtype - Expected data type.
object assertDTypeEqual(ndarray target, object expected_dtype)
Assert ndarray data type is equal to expected.
Parameters
-
ndarraytarget - The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor).
-
objectexpected_dtype - Expected data type.
object assertDTypeEqual_dyn(object target, object expected_dtype)
Assert ndarray data type is equal to expected.
Parameters
-
objecttarget - The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor).
-
objectexpected_dtype - Expected data type.
object assertNDArrayNear_dyn(object ndarray1, object ndarray2, object err, object msg)
Asserts that two numpy arrays have near values.
Parameters
-
objectndarray1 - a numpy ndarray.
-
objectndarray2 - a numpy ndarray.
-
objecterr - a float. The maximum absolute difference allowed.
-
objectmsg - Optional message to report on failure.
object assertNear_dyn(object f1, object f2, object err, object msg)
Asserts that two floats are near each other. Checks that |f1 - f2| < err and asserts a test failure
if not.
Parameters
-
objectf1 - A float value.
-
objectf2 - A float value.
-
objecterr - A float value.
-
objectmsg - An optional string message to append to the failure message.
object assertNotAllClose(object a, object b, IDictionary<string, object> kwargs)
Assert that two numpy arrays, or Tensors, do not have near values.
Parameters
-
objecta - the first value to compare.
-
objectb - the second value to compare.
-
IDictionary<string, object>kwargs - additional keyword arguments to be passed to the underlying `assertAllClose` call.
object assertNotAllClose_dyn(object a, object b, IDictionary<string, object> kwargs)
Assert that two numpy arrays, or Tensors, do not have near values.
Parameters
-
objecta - the first value to compare.
-
objectb - the second value to compare.
-
IDictionary<string, object>kwargs - additional keyword arguments to be passed to the underlying `assertAllClose` call.
object assertNotAllEqual(object a, object b, object msg)
Asserts that two numpy arrays or Tensors do not have the same values.
Parameters
-
objecta - the expected numpy ndarray or anything can be converted to one.
-
objectb - the actual numpy ndarray or anything can be converted to one.
-
objectmsg - Optional message to report on failure.
object assertNotAllEqual_dyn(object a, object b, object msg)
Asserts that two numpy arrays or Tensors do not have the same values.
Parameters
-
objecta - the expected numpy ndarray or anything can be converted to one.
-
objectb - the actual numpy ndarray or anything can be converted to one.
-
objectmsg - Optional message to report on failure.
void assertProtoEquals(object expected_message_maybe_ascii, TreeEnsemble message, object msg)
Asserts that message is same as parsed expected_message_ascii. Creates another prototype of message, reads the ascii message into it and
then compares them using self._AssertProtoEqual().
Parameters
-
objectexpected_message_maybe_ascii - proto message in original or ascii form.
-
TreeEnsemblemessage - the message to validate.
-
objectmsg - Optional message to report on failure.
object assertProtoEquals_dyn(object expected_message_maybe_ascii, object message, object msg)
Asserts that message is same as parsed expected_message_ascii. Creates another prototype of message, reads the ascii message into it and
then compares them using self._AssertProtoEqual().
Parameters
-
objectexpected_message_maybe_ascii - proto message in original or ascii form.
-
objectmessage - the message to validate.
-
objectmsg - Optional message to report on failure.
void assertProtoEqualsVersion(string expected, object actual, ImplicitContainer<T> producer, ImplicitContainer<T> min_consumer, object msg)
object assertProtoEqualsVersion_dyn(object expected, object actual, ImplicitContainer<T> producer, ImplicitContainer<T> min_consumer, object msg)
object assertRaisesOpError(string expected_err_re_or_predicate)
object assertRaisesOpError(object expected_err_re_or_predicate)
object assertRaisesOpError_dyn(object expected_err_re_or_predicate)
IContextManager<T> assertRaisesWithPredicateMatch(object exception_type, object expected_err_re_or_predicate)
Returns a context manager to enclose code expected to raise an exception. If the exception is an OpError, the op stack is also included in the message
predicate search.
Parameters
-
objectexception_type - The expected type of exception that should be raised.
-
objectexpected_err_re_or_predicate - If this is callable, it should be a function of one argument that inspects the passed-in exception and returns True (success) or False (please fail the test). Otherwise, the error message is expected to match this regular expression partially.
Returns
-
IContextManager<T> - A context manager to surround code that is expected to raise an exception.
IContextManager<T> assertRaisesWithPredicateMatch(Exception exception_type, PythonFunctionContainer expected_err_re_or_predicate)
Returns a context manager to enclose code expected to raise an exception. If the exception is an OpError, the op stack is also included in the message
predicate search.
Parameters
-
Exceptionexception_type - The expected type of exception that should be raised.
-
PythonFunctionContainerexpected_err_re_or_predicate - If this is callable, it should be a function of one argument that inspects the passed-in exception and returns True (success) or False (please fail the test). Otherwise, the error message is expected to match this regular expression partially.
Returns
-
IContextManager<T> - A context manager to surround code that is expected to raise an exception.
IContextManager<T> assertRaisesWithPredicateMatch(object exception_type, PythonFunctionContainer expected_err_re_or_predicate)
Returns a context manager to enclose code expected to raise an exception. If the exception is an OpError, the op stack is also included in the message
predicate search.
Parameters
-
objectexception_type - The expected type of exception that should be raised.
-
PythonFunctionContainerexpected_err_re_or_predicate - If this is callable, it should be a function of one argument that inspects the passed-in exception and returns True (success) or False (please fail the test). Otherwise, the error message is expected to match this regular expression partially.
Returns
-
IContextManager<T> - A context manager to surround code that is expected to raise an exception.
IContextManager<T> assertRaisesWithPredicateMatch(Exception exception_type, object expected_err_re_or_predicate)
Returns a context manager to enclose code expected to raise an exception. If the exception is an OpError, the op stack is also included in the message
predicate search.
Parameters
-
Exceptionexception_type - The expected type of exception that should be raised.
-
objectexpected_err_re_or_predicate - If this is callable, it should be a function of one argument that inspects the passed-in exception and returns True (success) or False (please fail the test). Otherwise, the error message is expected to match this regular expression partially.
Returns
-
IContextManager<T> - A context manager to surround code that is expected to raise an exception.
object assertRaisesWithPredicateMatch_dyn(object exception_type, object expected_err_re_or_predicate)
Returns a context manager to enclose code expected to raise an exception. If the exception is an OpError, the op stack is also included in the message
predicate search.
Parameters
-
objectexception_type - The expected type of exception that should be raised.
-
objectexpected_err_re_or_predicate - If this is callable, it should be a function of one argument that inspects the passed-in exception and returns True (success) or False (please fail the test). Otherwise, the error message is expected to match this regular expression partially.
Returns
-
object - A context manager to surround code that is expected to raise an exception.
void assertShapeEqual(Complex np_array, IGraphNodeBase tf_tensor, object msg)
Asserts that a Numpy ndarray and a TensorFlow tensor have the same shape.
Parameters
-
Complexnp_array - A Numpy ndarray or Numpy scalar.
-
IGraphNodeBasetf_tensor - A Tensor.
-
objectmsg - Optional message to report on failure.
void assertShapeEqual(ndarray np_array, ValueTuple<PythonClassContainer, PythonClassContainer> tf_tensor, object msg)
Asserts that a Numpy ndarray and a TensorFlow tensor have the same shape.
Parameters
-
ndarraynp_array - A Numpy ndarray or Numpy scalar.
-
ValueTuple<PythonClassContainer, PythonClassContainer>tf_tensor - A Tensor.
-
objectmsg - Optional message to report on failure.
void assertShapeEqual(ndarray np_array, IEnumerable<object> tf_tensor, object msg)
Asserts that a Numpy ndarray and a TensorFlow tensor have the same shape.
Parameters
-
ndarraynp_array - A Numpy ndarray or Numpy scalar.
-
IEnumerable<object>tf_tensor - A Tensor.
-
objectmsg - Optional message to report on failure.
void assertShapeEqual(Complex np_array, IndexedSlices tf_tensor, object msg)
Asserts that a Numpy ndarray and a TensorFlow tensor have the same shape.
Parameters
-
Complexnp_array - A Numpy ndarray or Numpy scalar.
-
IndexedSlicestf_tensor - A Tensor.
-
objectmsg - Optional message to report on failure.
void assertShapeEqual(ndarray np_array, IGraphNodeBase tf_tensor, object msg)
Asserts that a Numpy ndarray and a TensorFlow tensor have the same shape.
Parameters
-
ndarraynp_array - A Numpy ndarray or Numpy scalar.
-
IGraphNodeBasetf_tensor - A Tensor.
-
objectmsg - Optional message to report on failure.
void assertShapeEqual(ndarray np_array, IndexedSlices tf_tensor, object msg)
Asserts that a Numpy ndarray and a TensorFlow tensor have the same shape.
Parameters
-
ndarraynp_array - A Numpy ndarray or Numpy scalar.
-
IndexedSlicestf_tensor - A Tensor.
-
objectmsg - Optional message to report on failure.
void assertShapeEqual(IEnumerable<ndarray> np_array, ValueTuple<PythonClassContainer, PythonClassContainer> tf_tensor, object msg)
Asserts that a Numpy ndarray and a TensorFlow tensor have the same shape.
Parameters
-
IEnumerable<ndarray>np_array - A Numpy ndarray or Numpy scalar.
-
ValueTuple<PythonClassContainer, PythonClassContainer>tf_tensor - A Tensor.
-
objectmsg - Optional message to report on failure.
void assertShapeEqual(IEnumerable<ndarray> np_array, IndexedSlices tf_tensor, object msg)
Asserts that a Numpy ndarray and a TensorFlow tensor have the same shape.
Parameters
-
IEnumerable<ndarray>np_array - A Numpy ndarray or Numpy scalar.
-
IndexedSlicestf_tensor - A Tensor.
-
objectmsg - Optional message to report on failure.
void assertShapeEqual(IEnumerable<ndarray> np_array, IGraphNodeBase tf_tensor, object msg)
Asserts that a Numpy ndarray and a TensorFlow tensor have the same shape.
Parameters
-
IEnumerable<ndarray>np_array - A Numpy ndarray or Numpy scalar.
-
IGraphNodeBasetf_tensor - A Tensor.
-
objectmsg - Optional message to report on failure.
void assertShapeEqual(Complex np_array, IEnumerable<object> tf_tensor, object msg)
Asserts that a Numpy ndarray and a TensorFlow tensor have the same shape.
Parameters
-
Complexnp_array - A Numpy ndarray or Numpy scalar.
-
IEnumerable<object>tf_tensor - A Tensor.
-
objectmsg - Optional message to report on failure.
void assertShapeEqual(Complex np_array, ValueTuple<PythonClassContainer, PythonClassContainer> tf_tensor, object msg)
Asserts that a Numpy ndarray and a TensorFlow tensor have the same shape.
Parameters
-
Complexnp_array - A Numpy ndarray or Numpy scalar.
-
ValueTuple<PythonClassContainer, PythonClassContainer>tf_tensor - A Tensor.
-
objectmsg - Optional message to report on failure.
void assertShapeEqual(object np_array, IGraphNodeBase tf_tensor, object msg)
Asserts that a Numpy ndarray and a TensorFlow tensor have the same shape.
Parameters
-
objectnp_array - A Numpy ndarray or Numpy scalar.
-
IGraphNodeBasetf_tensor - A Tensor.
-
objectmsg - Optional message to report on failure.
void assertShapeEqual(object np_array, IndexedSlices tf_tensor, object msg)
Asserts that a Numpy ndarray and a TensorFlow tensor have the same shape.
Parameters
-
objectnp_array - A Numpy ndarray or Numpy scalar.
-
IndexedSlicestf_tensor - A Tensor.
-
objectmsg - Optional message to report on failure.
void assertShapeEqual(object np_array, ValueTuple<PythonClassContainer, PythonClassContainer> tf_tensor, object msg)
Asserts that a Numpy ndarray and a TensorFlow tensor have the same shape.
Parameters
-
objectnp_array - A Numpy ndarray or Numpy scalar.
-
ValueTuple<PythonClassContainer, PythonClassContainer>tf_tensor - A Tensor.
-
objectmsg - Optional message to report on failure.
void assertShapeEqual(object np_array, IEnumerable<object> tf_tensor, object msg)
Asserts that a Numpy ndarray and a TensorFlow tensor have the same shape.
Parameters
-
objectnp_array - A Numpy ndarray or Numpy scalar.
-
IEnumerable<object>tf_tensor - A Tensor.
-
objectmsg - Optional message to report on failure.
void assertShapeEqual(IEnumerable<ndarray> np_array, IEnumerable<object> tf_tensor, object msg)
Asserts that a Numpy ndarray and a TensorFlow tensor have the same shape.
Parameters
-
IEnumerable<ndarray>np_array - A Numpy ndarray or Numpy scalar.
-
IEnumerable<object>tf_tensor - A Tensor.
-
objectmsg - Optional message to report on failure.
object assertShapeEqual_dyn(object np_array, object tf_tensor, object msg)
Asserts that a Numpy ndarray and a TensorFlow tensor have the same shape.
Parameters
-
objectnp_array - A Numpy ndarray or Numpy scalar.
-
objecttf_tensor - A Tensor.
-
objectmsg - Optional message to report on failure.
void assertStartsWith(string actual, string expected_start, object msg)
Assert that actual.startswith(expected_start) is True.
Parameters
-
stringactual - str
-
stringexpected_start - str
-
objectmsg - Optional message to report on failure.
void assertStartsWith(object actual, string expected_start, object msg)
Assert that actual.startswith(expected_start) is True.
Parameters
-
objectactual - str
-
stringexpected_start - str
-
objectmsg - Optional message to report on failure.
object assertStartsWith_dyn(object actual, object expected_start, object msg)
Assert that actual.startswith(expected_start) is True.
Parameters
-
objectactual - str
-
objectexpected_start - str
-
objectmsg - Optional message to report on failure.
IContextManager<T> cached_session(Graph graph, object config, bool use_gpu, bool force_gpu)
Returns a TensorFlow Session for use in executing tests. This method behaves differently than self.session(): for performance reasons
`cached_session` will by default reuse the same session within the same
test. The session returned by this function will only be closed at the end
of the test (in the TearDown function). Use the `use_gpu` and `force_gpu` options to control where ops are run. If
`force_gpu` is True, all ops are pinned to `/device:GPU:0`. Otherwise, if
`use_gpu` is True, TensorFlow tries to run as many ops on the GPU as
possible. If both `force_gpu and `use_gpu` are False, all ops are pinned to
the CPU. Example:
Parameters
-
Graphgraph - Optional graph to use during the returned session.
-
objectconfig - An optional config_pb2.ConfigProto to use to configure the session.
-
booluse_gpu - If True, attempt to run as many ops as possible on GPU.
-
boolforce_gpu - If True, pin all ops to `/device:GPU:0`.
Show Example
class MyOperatorTest(test_util.TensorFlowTestCase):
def testMyOperator(self):
with self.cached_session(use_gpu=True) as sess:
valid_input = [1.0, 2.0, 3.0, 4.0, 5.0]
result = MyOperator(valid_input).eval()
self.assertEqual(result, [1.0, 2.0, 3.0, 5.0, 8.0]
invalid_input = [-1.0, 2.0, 7.0]
with self.assertRaisesOpError("negative input not supported"):
MyOperator(invalid_input).eval()
object cached_session_dyn(object graph, object config, ImplicitContainer<T> use_gpu, ImplicitContainer<T> force_gpu)
Returns a TensorFlow Session for use in executing tests. This method behaves differently than self.session(): for performance reasons
`cached_session` will by default reuse the same session within the same
test. The session returned by this function will only be closed at the end
of the test (in the TearDown function). Use the `use_gpu` and `force_gpu` options to control where ops are run. If
`force_gpu` is True, all ops are pinned to `/device:GPU:0`. Otherwise, if
`use_gpu` is True, TensorFlow tries to run as many ops on the GPU as
possible. If both `force_gpu and `use_gpu` are False, all ops are pinned to
the CPU. Example:
Parameters
-
objectgraph - Optional graph to use during the returned session.
-
objectconfig - An optional config_pb2.ConfigProto to use to configure the session.
-
ImplicitContainer<T>use_gpu - If True, attempt to run as many ops as possible on GPU.
-
ImplicitContainer<T>force_gpu - If True, pin all ops to `/device:GPU:0`.
Show Example
class MyOperatorTest(test_util.TensorFlowTestCase):
def testMyOperator(self):
with self.cached_session(use_gpu=True) as sess:
valid_input = [1.0, 2.0, 3.0, 4.0, 5.0]
result = MyOperator(valid_input).eval()
self.assertEqual(result, [1.0, 2.0, 3.0, 5.0, 8.0]
invalid_input = [-1.0, 2.0, 7.0]
with self.assertRaisesOpError("negative input not supported"):
MyOperator(invalid_input).eval()
IContextManager<T> captureWritesToStream(PythonClassContainer stream)
A context manager that captures the writes to a given stream. This context manager captures all writes to a given stream inside of a
`CapturedWrites` object. When this context manager is created, it yields
the `CapturedWrites` object. The captured contents can be accessed by
calling `.contents()` on the `CapturedWrites`. For this function to work, the stream must have a file descriptor that
can be modified using `os.dup` and `os.dup2`, and the stream must support
a `.flush()` method. The default python sys.stdout and sys.stderr are
examples of this. Note that this does not work in Colab or Jupyter
notebooks, because those use alternate stdout streams. Example:
Parameters
-
PythonClassContainerstream - The stream whose writes should be captured. This stream must have a file descriptor, support writing via using that file descriptor, and must have a `.flush()` method.
Show Example
class MyOperatorTest(test_util.TensorFlowTestCase):
def testMyOperator(self):
input = [1.0, 2.0, 3.0, 4.0, 5.0]
with self.captureWritesToStream(sys.stdout) as captured:
result = MyOperator(input).eval()
self.assertStartsWith(captured.contents(), "This was printed.")
object captureWritesToStream_dyn(object stream)
A context manager that captures the writes to a given stream. This context manager captures all writes to a given stream inside of a
`CapturedWrites` object. When this context manager is created, it yields
the `CapturedWrites` object. The captured contents can be accessed by
calling `.contents()` on the `CapturedWrites`. For this function to work, the stream must have a file descriptor that
can be modified using `os.dup` and `os.dup2`, and the stream must support
a `.flush()` method. The default python sys.stdout and sys.stderr are
examples of this. Note that this does not work in Colab or Jupyter
notebooks, because those use alternate stdout streams. Example:
Parameters
-
objectstream - The stream whose writes should be captured. This stream must have a file descriptor, support writing via using that file descriptor, and must have a `.flush()` method.
Show Example
class MyOperatorTest(test_util.TensorFlowTestCase):
def testMyOperator(self):
input = [1.0, 2.0, 3.0, 4.0, 5.0]
with self.captureWritesToStream(sys.stdout) as captured:
result = MyOperator(input).eval()
self.assertStartsWith(captured.contents(), "This was printed.")
TestCase._CheckedThread checkedThread(PythonFunctionContainer target, Nullable<ValueTuple<object, Session>> args, IDictionary<string, object> kwargs)
Returns a Thread wrapper that asserts 'target' completes successfully. This method should be used to create all threads in test cases, as
otherwise there is a risk that a thread will silently fail, and/or
assertions made in the thread will not be respected.
Parameters
-
PythonFunctionContainertarget - A callable object to be executed in the thread.
-
Nullable<ValueTuple<object, Session>>args - The argument tuple for the target invocation. Defaults to ().
-
IDictionary<string, object>kwargs - A dictionary of keyword arguments for the target invocation. Defaults to {}.
Returns
-
TestCase._CheckedThread - A wrapper for threading.Thread that supports start() and join() methods.
object checkedThread_dyn(object target, object args, object kwargs)
Returns a Thread wrapper that asserts 'target' completes successfully. This method should be used to create all threads in test cases, as
otherwise there is a risk that a thread will silently fail, and/or
assertions made in the thread will not be respected.
Parameters
-
objecttarget - A callable object to be executed in the thread.
-
objectargs - The argument tuple for the target invocation. Defaults to ().
-
objectkwargs - A dictionary of keyword arguments for the target invocation. Defaults to {}.
Returns
-
object - A wrapper for threading.Thread that supports start() and join() methods.
object evaluate(PythonFunctionContainer tensors)
Evaluates tensors and returns numpy values.
Parameters
-
PythonFunctionContainertensors - A Tensor or a nested list/tuple of Tensors.
Returns
-
object - tensors numpy values.
string get_temp_dir()
Returns a unique temporary directory for the test to use. If you call this method multiple times during in a test, it will return the
same folder. However, across different runs the directories will be
different. This will ensure that across different runs tests will not be
able to pollute each others environment.
If you need multiple unique directories within a single test, you should
use tempfile.mkdtemp as follows:
tempfile.mkdtemp(dir=self.get_temp_dir()):
Returns
-
string - string, the path to the unique temporary directory created for this test.
object get_temp_dir_dyn()
Returns a unique temporary directory for the test to use. If you call this method multiple times during in a test, it will return the
same folder. However, across different runs the directories will be
different. This will ensure that across different runs tests will not be
able to pollute each others environment.
If you need multiple unique directories within a single test, you should
use tempfile.mkdtemp as follows:
tempfile.mkdtemp(dir=self.get_temp_dir()):
Returns
-
object - string, the path to the unique temporary directory created for this test.
IContextManager<T> session(Graph graph, object config, bool use_gpu, bool force_gpu)
Returns a TensorFlow Session for use in executing tests. Note that this will set this session and the graph as global defaults. Use the `use_gpu` and `force_gpu` options to control where ops are run. If
`force_gpu` is True, all ops are pinned to `/device:GPU:0`. Otherwise, if
`use_gpu` is True, TensorFlow tries to run as many ops on the GPU as
possible. If both `force_gpu and `use_gpu` are False, all ops are pinned to
the CPU. Example:
Parameters
-
Graphgraph - Optional graph to use during the returned session.
-
objectconfig - An optional config_pb2.ConfigProto to use to configure the session.
-
booluse_gpu - If True, attempt to run as many ops as possible on GPU.
-
boolforce_gpu - If True, pin all ops to `/device:GPU:0`.
Show Example
class MyOperatorTest(test_util.TensorFlowTestCase):
def testMyOperator(self):
with self.session(use_gpu=True):
valid_input = [1.0, 2.0, 3.0, 4.0, 5.0]
result = MyOperator(valid_input).eval()
self.assertEqual(result, [1.0, 2.0, 3.0, 5.0, 8.0]
invalid_input = [-1.0, 2.0, 7.0]
with self.assertRaisesOpError("negative input not supported"):
MyOperator(invalid_input).eval()
object session_dyn(object graph, object config, ImplicitContainer<T> use_gpu, ImplicitContainer<T> force_gpu)
Returns a TensorFlow Session for use in executing tests. Note that this will set this session and the graph as global defaults. Use the `use_gpu` and `force_gpu` options to control where ops are run. If
`force_gpu` is True, all ops are pinned to `/device:GPU:0`. Otherwise, if
`use_gpu` is True, TensorFlow tries to run as many ops on the GPU as
possible. If both `force_gpu and `use_gpu` are False, all ops are pinned to
the CPU. Example:
Parameters
-
objectgraph - Optional graph to use during the returned session.
-
objectconfig - An optional config_pb2.ConfigProto to use to configure the session.
-
ImplicitContainer<T>use_gpu - If True, attempt to run as many ops as possible on GPU.
-
ImplicitContainer<T>force_gpu - If True, pin all ops to `/device:GPU:0`.
Show Example
class MyOperatorTest(test_util.TensorFlowTestCase):
def testMyOperator(self):
with self.session(use_gpu=True):
valid_input = [1.0, 2.0, 3.0, 4.0, 5.0]
result = MyOperator(valid_input).eval()
self.assertEqual(result, [1.0, 2.0, 3.0, 5.0, 8.0]
invalid_input = [-1.0, 2.0, 7.0]
with self.assertRaisesOpError("negative input not supported"):
MyOperator(invalid_input).eval()
IContextManager<T> test_session(Graph graph, object config, bool use_gpu, bool force_gpu)
Use cached_session instead. (deprecated) Warning: THIS FUNCTION IS DEPRECATED. It will be removed in a future version.
Instructions for updating:
Use `self.session()` or `self.cached_session()` instead.
object test_session_dyn(object graph, object config, ImplicitContainer<T> use_gpu, ImplicitContainer<T> force_gpu)
Use cached_session instead. (deprecated) Warning: THIS FUNCTION IS DEPRECATED. It will be removed in a future version.
Instructions for updating:
Use `self.session()` or `self.cached_session()` instead.
Public properties
object assertItemsEqual get; set;
An unordered sequence comparison asserting that the same elements,
regardless of order. If the same element occurs more than once,
it verifies that the elements occur the same number of times. self.assertEqual(Counter(list(first)),
Counter(list(second))) Example:
- [0, 1, 1] and [1, 0, 1] compare equal.
- [0, 0, 1] and [0, 1] compare unequal.
object assertItemsEqual_dyn get; set;
An unordered sequence comparison asserting that the same elements,
regardless of order. If the same element occurs more than once,
it verifies that the elements occur the same number of times. self.assertEqual(Counter(list(first)),
Counter(list(second))) Example:
- [0, 1, 1] and [1, 0, 1] compare equal.
- [0, 0, 1] and [0, 1] compare unequal.
object assertRaisesRegexp_dyn get; set;
Asserts that the message in a raised exception matches a regex.