[tfdbg2] Fix bug in which enable_check_numerics() errors due to empty file path

The helper function `guess_is_tensorflow_py_library`() throws errors for file
paths that do not have expected extensions for Python source files. This is why
it errors out when the file path is an empty string, which has been observed
to happen by users.

This CL makes the helper function not throw errors and return False for such
malformed file paths instead.

PiperOrigin-RevId: 315276482
Change-Id: Ib19750d502cd55fcfbef6f95a2064adc2e0816e9
This commit is contained in:
Shanqing Cai 2020-06-08 08:08:07 -07:00 committed by TensorFlower Gardener
parent 74fb47ccd2
commit 319df5224c
2 changed files with 13 additions and 12 deletions

View File

@ -69,18 +69,13 @@ def guess_is_tensorflow_py_library(py_file_path):
py_file_path: full path of the Python source file in question.
Returns:
(`bool`) Whether the file is a part of the tensorflow library.
Raises:
ValueError: if the extension name of py_file_path does not indicate a Python
source file (compiled or uncompiled).
(`bool`) Whether the file is inferred to be a part of the tensorflow
library.
"""
if (not is_extension_uncompiled_python_source(py_file_path) and
not is_extension_compiled_python_source(py_file_path)):
raise ValueError(
"Input file path (%s) is not a Python source file." % py_file_path)
return False
py_file_path = _norm_abs_path(py_file_path)
return ((py_file_path.startswith(_TENSORFLOW_BASEDIR) or
py_file_path.startswith(_ABSL_BASEDIR)) and
not py_file_path.endswith("_test.py") and

View File

@ -126,10 +126,16 @@ class GuessIsTensorFlowLibraryTest(test_util.TensorFlowTestCase):
source_utils.guess_is_tensorflow_py_library(os.path.normpath(
"site-packages/tensorflow/python/debug/examples/v3/example_v3.py")))
def testNonPythonFileRaisesException(self):
with self.assertRaisesRegexp(ValueError, r"is not a Python source file"):
def testReturnsFalseForNonPythonFile(self):
self.assertFalse(
source_utils.guess_is_tensorflow_py_library(
os.path.join(os.path.dirname(self.curr_file_path), "foo.cc"))
os.path.join(os.path.dirname(self.curr_file_path), "foo.cc")))
def testReturnsFalseForStdin(self):
self.assertFalse(source_utils.guess_is_tensorflow_py_library("<stdin>"))
def testReturnsFalseForEmptyFileName(self):
self.assertFalse(source_utils.guess_is_tensorflow_py_library(""))
class SourceHelperTest(test_util.TensorFlowTestCase):