Adding test for BaseResourceVariable.__repr__
*ding ding* shame shame shame *ding ding* PiperOrigin-RevId: 302037315 Change-Id: Ifddf2475af96487b522d6b89ae307bf9bf46d5a9
This commit is contained in:
parent
b7855c7098
commit
bb97495f77
@ -208,6 +208,26 @@ class ResourceVariableOpsTest(test_util.TensorFlowTestCase,
|
||||
resource_variable_ops.assign_variable_op(
|
||||
handle, constant_op.constant([1.], dtype=dtypes.float32))
|
||||
|
||||
def testRepr(self):
|
||||
with context.eager_mode():
|
||||
v = resource_variable_ops.ResourceVariable(1)
|
||||
text = "%r" % v
|
||||
self.assertEqual(
|
||||
"<tf.Variable 'Variable:0' shape=() dtype=int32, numpy=1>", text)
|
||||
|
||||
def testReprUnavailable(self):
|
||||
with context.eager_mode():
|
||||
v = resource_variable_ops.ResourceVariable(1)
|
||||
|
||||
# Monkey-patch this variable to not have an available value
|
||||
def broken_read():
|
||||
raise ValueError("This doesn't work")
|
||||
|
||||
v.read_value = broken_read
|
||||
text = "%r" % v
|
||||
self.assertEqual("<tf.Variable 'Variable:0' shape=() dtype=int32,"
|
||||
" numpy=<unavailable>>", text)
|
||||
|
||||
def testUnprintableHandle(self):
|
||||
with context.eager_mode():
|
||||
handle = resource_variable_ops.var_handle_op(
|
||||
|
@ -1355,7 +1355,7 @@ class ResourceVariable(BaseResourceVariable):
|
||||
which is the initial value for the Variable. Can also be a
|
||||
callable with no argument that returns the initial value when called.
|
||||
(Note that initializer functions from init_ops.py must first be bound
|
||||
to a shape before being used here.)
|
||||
to a shape before being used here.)
|
||||
trainable: If `True`, the default, also adds the variable to the graph
|
||||
collection `GraphKeys.TRAINABLE_VARIABLES`. This collection is used as
|
||||
the default list of variables to use by the `Optimizer` classes.
|
||||
|
Loading…
x
Reference in New Issue
Block a user