Print the right location where deprecated symbol is used.

PiperOrigin-RevId: 261592387
This commit is contained in:
Anna R 2019-08-04 15:42:44 -07:00 committed by TensorFlower Gardener
parent f605ea0a14
commit 1442bc2116
2 changed files with 9 additions and 8 deletions

View File

@ -39,9 +39,10 @@ def get_rename_v2(name):
def _call_location():
# We want to get stack frame 2 frames up from current frame,
# i.e. above _getattr__ and _call_location calls.
stack = tf_stack.extract_stack_file_and_line(max_length=3)
# We want to get stack frame 3 frames up from current frame,
# i.e. above __getattr__, _tfmw_add_deprecation_warning,
# and _call_location calls.
stack = tf_stack.extract_stack_file_and_line(max_length=4)
if not stack: # should never happen as we're in a function
return 'UNKNOWN'
frame = stack[0]

View File

@ -39,7 +39,7 @@ class DeprecationTest(test.TestCase):
tf.tables_initializer()
self.assertEqual(1, mock_warning.call_count)
self.assertRegexpMatches(mock_warning.call_args[0][1],
"module_wrapper.py:")
"deprecation_test.py:")
self.assertRegexpMatches(
mock_warning.call_args[0][2], r"tables_initializer")
self.assertRegexpMatches(
@ -60,7 +60,7 @@ class DeprecationTest(test.TestCase):
tf.ragged.RaggedTensorValue(value, row_splits)
self.assertEqual(1, mock_warning.call_count)
self.assertRegexpMatches(mock_warning.call_args[0][1],
"module_wrapper.py:")
"deprecation_test.py:")
self.assertRegexpMatches(
mock_warning.call_args[0][2], r"ragged.RaggedTensorValue")
self.assertRegexpMatches(
@ -83,7 +83,7 @@ class DeprecationTest(test.TestCase):
tf.sparse_mask(array, mask_indices)
self.assertEqual(1, mock_warning.call_count)
self.assertRegexpMatches(mock_warning.call_args[0][1],
"module_wrapper.py:")
"deprecation_test.py:")
self.assertRegexpMatches(
mock_warning.call_args[0][2], r"sparse_mask")
self.assertRegexpMatches(
@ -101,7 +101,7 @@ class DeprecationTest(test.TestCase):
tf.VarLenFeature(tf.dtypes.int32)
self.assertEqual(1, mock_warning.call_count)
self.assertRegexpMatches(mock_warning.call_args[0][1],
"module_wrapper.py:")
"deprecation_test.py:")
self.assertRegexpMatches(
mock_warning.call_args[0][2], r"VarLenFeature")
self.assertRegexpMatches(
@ -119,7 +119,7 @@ class DeprecationTest(test.TestCase):
tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY # pylint: disable=pointless-statement
self.assertEqual(1, mock_warning.call_count)
self.assertRegexpMatches(mock_warning.call_args[0][1],
"module_wrapper.py:")
"deprecation_test.py:")
self.assertRegexpMatches(
mock_warning.call_args[0][2],
r"saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY")