From bb97495f7700b1d87fede5f35489628cba327660 Mon Sep 17 00:00:00 2001 From: Martin Wicke Date: Fri, 20 Mar 2020 08:59:37 -0700 Subject: [PATCH] Adding test for BaseResourceVariable.__repr__ *ding ding* shame shame shame *ding ding* PiperOrigin-RevId: 302037315 Change-Id: Ifddf2475af96487b522d6b89ae307bf9bf46d5a9 --- .../resource_variable_ops_test.py | 20 +++++++++++++++++++ .../python/ops/resource_variable_ops.py | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/tensorflow/python/kernel_tests/resource_variable_ops_test.py b/tensorflow/python/kernel_tests/resource_variable_ops_test.py index cbd8f6a2ebe..41ce9eb8a57 100644 --- a/tensorflow/python/kernel_tests/resource_variable_ops_test.py +++ b/tensorflow/python/kernel_tests/resource_variable_ops_test.py @@ -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( + "", 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(">", text) + def testUnprintableHandle(self): with context.eager_mode(): handle = resource_variable_ops.var_handle_op( diff --git a/tensorflow/python/ops/resource_variable_ops.py b/tensorflow/python/ops/resource_variable_ops.py index 591e0f5786b..f99f886f210 100644 --- a/tensorflow/python/ops/resource_variable_ops.py +++ b/tensorflow/python/ops/resource_variable_ops.py @@ -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.