diff options
author | 2018-07-17 05:09:36 -0700 | |
---|---|---|
committer | 2018-07-17 05:12:40 -0700 | |
commit | 2bdc5f12a1e66fd851e2621889c743c3b8da65e5 (patch) | |
tree | 59fd4aee15f52c4ae9f15c79daec1bfc15e55f02 | |
parent | c091185930eee5a3f87cfbe5e367a3cfc8b717e8 (diff) |
Fix file patterns checked during stack traversal to be os-independent.
PiperOrigin-RevId: 204895256
-rw-r--r-- | tensorflow/python/framework/error_interpolation.py | 6 | ||||
-rw-r--r-- | tensorflow/python/framework/error_interpolation_test.py | 17 |
2 files changed, 16 insertions, 7 deletions
diff --git a/tensorflow/python/framework/error_interpolation.py b/tensorflow/python/framework/error_interpolation.py index 519e0fda0a..72d5dc99a8 100644 --- a/tensorflow/python/framework/error_interpolation.py +++ b/tensorflow/python/framework/error_interpolation.py @@ -24,6 +24,7 @@ from __future__ import print_function import collections import itertools +import os import re import string @@ -41,7 +42,10 @@ _INTERPOLATION_PATTERN = re.compile(_INTERPOLATION_REGEX) _ParseTag = collections.namedtuple("_ParseTag", ["type", "name", "format"]) -_BAD_FILE_SUBSTRINGS = ["tensorflow/python", "<embedded"] +_BAD_FILE_SUBSTRINGS = [ + os.path.join("tensorflow", "python"), + "<embedded", +] def _parse_message(message): diff --git a/tensorflow/python/framework/error_interpolation_test.py b/tensorflow/python/framework/error_interpolation_test.py index 6d19f75586..b6615317d1 100644 --- a/tensorflow/python/framework/error_interpolation_test.py +++ b/tensorflow/python/framework/error_interpolation_test.py @@ -18,6 +18,8 @@ from __future__ import absolute_import from __future__ import division from __future__ import print_function +import os + from tensorflow.python.framework import constant_op from tensorflow.python.framework import error_interpolation from tensorflow.python.platform import test @@ -35,7 +37,7 @@ def _modify_op_stack_with_filenames(op, num_user_frames, user_filename, num_inner_tf_frames): """Replace op._traceback with a new traceback using special filenames.""" tf_filename = "%d" + error_interpolation._BAD_FILE_SUBSTRINGS[0] - user_filename = "%d/my_favorite_file.py" + user_filename = os.path.join("%d", "my_favorite_file.py") num_requested_frames = num_user_frames + num_inner_tf_frames num_actual_frames = len(op._traceback) @@ -65,7 +67,10 @@ class InterpolateTest(test.TestCase): # Change the list of bad file substrings so that constant_op.py is chosen # as the defining stack frame for constant_op.constant ops. self.old_bad_strings = error_interpolation._BAD_FILE_SUBSTRINGS - error_interpolation._BAD_FILE_SUBSTRINGS = ["/ops.py", "/util"] + error_interpolation._BAD_FILE_SUBSTRINGS = [ + "%sops.py" % os.sep, + "%sutil" % os.sep, + ] def tearDown(self): error_interpolation._BAD_FILE_SUBSTRINGS = self.old_bad_strings @@ -105,8 +110,8 @@ class InterpolateTest(test.TestCase): one_tag_string = "^^node:Two:${file}^^" interpolated_string = error_interpolation.interpolate(one_tag_string, self.graph) - self.assertTrue(interpolated_string.endswith("op.py"), - "interpolated_string '%s' did not end with op.py" + self.assertTrue(interpolated_string.endswith("constant_op.py"), + "interpolated_string '%s' did not end with constant_op.py" % interpolated_string) def testOneTagWithAFakeNameResultsInPlaceholders(self): @@ -119,13 +124,13 @@ class InterpolateTest(test.TestCase): two_tags_no_seps = "^^node:One:${file}^^^^node:Three:${line}^^" interpolated_string = error_interpolation.interpolate(two_tags_no_seps, self.graph) - self.assertRegexpMatches(interpolated_string, "op.py[0-9]+") + self.assertRegexpMatches(interpolated_string, "constant_op.py[0-9]+") def testTwoTagsWithSeps(self): two_tags_with_seps = ";;;^^node:Two:${file}^^,,,^^node:Three:${line}^^;;;" interpolated_string = error_interpolation.interpolate(two_tags_with_seps, self.graph) - expected_regex = "^;;;.*op.py,,,[0-9]*;;;$" + expected_regex = "^;;;.*constant_op.py,,,[0-9]*;;;$" self.assertRegexpMatches(interpolated_string, expected_regex) |