tfdbg CLI: fix a bug RichTextLines.prepend that caused font_attr_segs to be None

Change: 146260296
This commit is contained in:
Shanqing Cai 2017-02-01 10:32:53 -08:00 committed by TensorFlower Gardener
parent eef537ce8d
commit 43af740fcb
2 changed files with 19 additions and 1 deletions

View File

@ -247,7 +247,9 @@ class RichTextLines(object):
line.
"""
other = RichTextLines(line, font_attr_segs={0: font_attr_segs})
other = RichTextLines(line)
if font_attr_segs:
other.font_attr_segs[0] = font_attr_segs
self._extend_before(other)
def write_to_file(self, file_path):

View File

@ -606,6 +606,22 @@ class RegexFindTest(test_util.TensorFlowTestCase):
with self.assertRaisesRegexp(ValueError, "Invalid regular expression"):
debugger_cli_common.regex_find(self._orig_screen_output, "[", "yellow")
def testRegexFindOnPrependedLinesWorks(self):
rich_lines = debugger_cli_common.RichTextLines(["Violets are blue"])
rich_lines.prepend(["Roses are red"])
searched_rich_lines = debugger_cli_common.regex_find(
rich_lines, "red", "bold")
self.assertEqual(
{0: [(10, 13, "bold")]}, searched_rich_lines.font_attr_segs)
rich_lines = debugger_cli_common.RichTextLines(["Violets are blue"])
rich_lines.prepend(["A poem"], font_attr_segs=[(0, 1, "underline")])
searched_rich_lines = debugger_cli_common.regex_find(
rich_lines, "poem", "italic")
self.assertEqual(
{0: [(0, 1, "underline"), (2, 6, "italic")]},
searched_rich_lines.font_attr_segs)
class WrapScreenOutputTest(test_util.TensorFlowTestCase):