Beispiel #1
0
  def _update_run_calls_state(self,
                              run_call_count,
                              fetches,
                              feed_dict,
                              is_callable_runner=False):
    """Update the internal state with regard to run() call history.

    Args:
      run_call_count: (int) Number of run() calls that have occurred.
      fetches: a node/tensor or a list of node/tensor that are the fetches of
        the run() call. This is the same as the fetches argument to the run()
        call.
      feed_dict: None of a dict. This is the feed_dict argument to the run()
        call.
      is_callable_runner: (bool) whether a runner returned by
        Session.make_callable is being run.
    """

    self._run_call_count = run_call_count
    self._feed_dict = feed_dict
    self._run_description = cli_shared.get_run_short_description(
        run_call_count,
        fetches,
        feed_dict,
        is_callable_runner=is_callable_runner)
    self._run_through_times -= 1

    self._run_info = cli_shared.get_run_start_intro(
        run_call_count,
        fetches,
        feed_dict,
        self._tensor_filters,
        is_callable_runner=is_callable_runner)
  def testSingleFetchNoFeeds(self):
    run_start_intro = cli_shared.get_run_start_intro(12, self.const_a, None, {})

    # Verify line about run() call number.
    self.assertEqual("About to enter Session run() call #12:",
                     run_start_intro.lines[1])

    # Verify line about fetch.
    const_a_name_line = run_start_intro.lines[4]
    self.assertEqual(self.const_a.name, const_a_name_line.strip())

    # Verify line about feeds.
    feeds_line = run_start_intro.lines[7]
    self.assertEqual("(Empty)", feeds_line.strip())

    # Verify lines about possible commands and their font attributes.
    self.assertEqual("run:", run_start_intro.lines[11][2:])
    self.assertEqual([(2, 5, "bold")], run_start_intro.font_attr_segs[11])
    self.assertEqual("run -n:", run_start_intro.lines[13][2:])
    self.assertEqual([(2, 8, "bold")], run_start_intro.font_attr_segs[13])
    self.assertEqual("run -f <filter_name>:", run_start_intro.lines[15][2:])
    self.assertEqual([(2, 22, "bold")], run_start_intro.font_attr_segs[15])

    # Verify short description.
    description = cli_shared.get_run_short_description(12, self.const_a, None)
    self.assertEqual("run #12: 1 fetch (a:0); 0 feeds", description)
Beispiel #3
0
    def testSingleFetchNoFeeds(self):
        run_start_intro = cli_shared.get_run_start_intro(
            12, self.const_a, None, {})

        # Verify line about run() call number.
        self.assertTrue(run_start_intro.lines[1].endswith("run() call #12:"))

        # Verify line about fetch.
        const_a_name_line = run_start_intro.lines[4]
        self.assertEqual(self.const_a.name, const_a_name_line.strip())

        # Verify line about feeds.
        feeds_line = run_start_intro.lines[7]
        self.assertEqual("(Empty)", feeds_line.strip())

        # Verify lines about possible commands and their font attributes.
        self.assertEqual("run:", run_start_intro.lines[11][2:])
        self.assertEqual([(2, 5, "bold")], run_start_intro.font_attr_segs[11])
        self.assertEqual("run -n:", run_start_intro.lines[13][2:])
        self.assertEqual([(2, 8, "bold")], run_start_intro.font_attr_segs[13])
        self.assertEqual("run -t <T>:", run_start_intro.lines[15][2:])
        self.assertEqual([(2, 12, "bold")], run_start_intro.font_attr_segs[15])
        self.assertEqual("run -f <filter_name>:",
                         run_start_intro.lines[17][2:])
        self.assertEqual([(2, 22, "bold")], run_start_intro.font_attr_segs[17])

        # Verify short description.
        description = cli_shared.get_run_short_description(
            12, self.const_a, None)
        self.assertEqual("run #12: 1 fetch (a:0); 0 feeds", description)
  def testTensorFilters(self):
    feed_dict = {self.const_a: 10.0}
    tensor_filters = {
        "filter_a": lambda x: True,
        "filter_b": lambda x: False,
    }

    run_start_intro = cli_shared.get_run_start_intro(1, self.const_c, feed_dict,
                                                     tensor_filters)

    # Verify the listed names of the tensor filters.
    filter_names = set()
    filter_names.add(run_start_intro.lines[20].split(" ")[-1])
    filter_names.add(run_start_intro.lines[21].split(" ")[-1])

    self.assertEqual({"filter_a", "filter_b"}, filter_names)

    # Verify short description.
    description = cli_shared.get_run_short_description(1, self.const_c,
                                                       feed_dict)
    self.assertEqual("run #1: 1 fetch (c:0); 1 feed (a:0)", description)

    # Verify the command links for the two filters.
    command_set = set()
    annot = run_start_intro.font_attr_segs[20][0]
    command_set.add(annot[2].content)
    annot = run_start_intro.font_attr_segs[21][0]
    command_set.add(annot[2].content)
    self.assertEqual({"run -f filter_a", "run -f filter_b"}, command_set)
  def _update_run_calls_state(self,
                              run_call_count,
                              fetches,
                              feed_dict,
                              is_callable_runner=False):
    """Update the internal state with regard to run() call history.

    Args:
      run_call_count: (int) Number of run() calls that have occurred.
      fetches: a node/tensor or a list of node/tensor that are the fetches of
        the run() call. This is the same as the fetches argument to the run()
        call.
      feed_dict: None of a dict. This is the feed_dict argument to the run()
        call.
      is_callable_runner: (bool) whether a runner returned by
        Session.make_callable is being run.
    """

    self._run_call_count = run_call_count
    self._feed_dict = feed_dict
    self._run_description = cli_shared.get_run_short_description(
        run_call_count,
        fetches,
        feed_dict,
        is_callable_runner=is_callable_runner)
    self._run_through_times -= 1

    self._run_info = cli_shared.get_run_start_intro(
        run_call_count,
        fetches,
        feed_dict,
        self._tensor_filters,
        is_callable_runner=is_callable_runner)
Beispiel #6
0
    def testTensorFilters(self):
        feed_dict = {self.const_a: 10.0}
        tensor_filters = {
            "filter_a": lambda x: True,
            "filter_b": lambda x: False,
        }

        run_start_intro = cli_shared.get_run_start_intro(
            1, self.const_c, feed_dict, tensor_filters)

        # Verify the listed names of the tensor filters.
        filter_names = set()
        filter_names.add(run_start_intro.lines[20].split(" ")[-1])
        filter_names.add(run_start_intro.lines[21].split(" ")[-1])

        self.assertEqual({"filter_a", "filter_b"}, filter_names)

        # Verify short description.
        description = cli_shared.get_run_short_description(
            1, self.const_c, feed_dict)
        self.assertEqual("run #1: 1 fetch (c:0); 1 feed (a:0)", description)

        # Verify the command links for the two filters.
        command_set = set()
        annot = run_start_intro.font_attr_segs[20][0]
        command_set.add(annot[2].content)
        annot = run_start_intro.font_attr_segs[21][0]
        command_set.add(annot[2].content)
        self.assertEqual({"run -f filter_a", "run -f filter_b"}, command_set)
  def testSparseTensorAsFeedShouldHandleNoNameAttribute(self):
    sparse_feed_val = ([[0, 0], [1, 1]], [10.0, 20.0])
    run_start_intro = cli_shared.get_run_start_intro(
        1, self.sparse_d, {self.sparse_d: sparse_feed_val}, {})
    self.assertEqual(str(self.sparse_d), run_start_intro.lines[7].strip())

    short_description = cli_shared.get_run_short_description(
        1, self.sparse_d, {self.sparse_d: sparse_feed_val})
    self.assertEqual(
        "run #1: 1 fetch; 1 feed (%s)" % self.sparse_d, short_description) id:3148 gh:3149
  def testSparseTensorAsFeedShouldHandleNoNameAttribute(self):
    sparse_feed_val = ([[0, 0], [1, 1]], [10.0, 20.0])
    run_start_intro = cli_shared.get_run_start_intro(
        1, self.sparse_d, {self.sparse_d: sparse_feed_val}, {})
    self.assertEqual(str(self.sparse_d), run_start_intro.lines[7].strip())

    short_description = cli_shared.get_run_short_description(
        1, self.sparse_d, {self.sparse_d: sparse_feed_val})
    self.assertEqual(
        "run #1: 1 fetch; 1 feed (%s)" % self.sparse_d, short_description)
    def on_run_start(self, request):
        """Overrides on-run-start callback.

    Invoke the CLI to let user choose what action to take:
      run / run --no_debug / step.

    Args:
      request: An instance of OnSessionInitRequest.

    Returns:
      An instance of OnSessionInitResponse.

    Raises:
      RuntimeError: If user chooses to prematurely exit the debugger.
    """

        self._update_run_calls_state(request.run_call_count, request.fetches, request.feed_dict)

        if self._run_till_filter_pass:
            # If we are running till a filter passes, we just need to keep running
            # with the DEBUG_RUN option.
            return framework.OnRunStartResponse(framework.OnRunStartAction.DEBUG_RUN, self._get_run_debug_urls())

        run_start_cli = curses_ui.CursesUI()

        run_start_cli.register_command_handler(
            "run", self._on_run_start_run_handler, self._on_run_start_parsers["run"].format_help(), prefix_aliases=["r"]
        )
        run_start_cli.register_command_handler(
            "invoke_stepper",
            self._on_run_start_step_handler,
            self._on_run_start_parsers["invoke_stepper"].format_help(),
            prefix_aliases=["s"],
        )

        if self._tensor_filters:
            # Register tab completion for the filter names.
            run_start_cli.register_tab_comp_context(["run", "r"], list(self._tensor_filters.keys()))

        run_start_cli.set_help_intro(
            cli_shared.get_run_start_intro(
                request.run_call_count, request.fetches, request.feed_dict, self._tensor_filters
            )
        )

        # Create initial screen output detailing the run.
        title = "run-start: " + self._run_description
        response = run_start_cli.run_ui(init_command="help", title=title, title_color="blue_on_white")
        if response == debugger_cli_common.EXPLICIT_USER_EXIT:
            # Explicit user "exit" command leads to sys.exit(1).
            print("Note: user exited from debugger CLI: Calling sys.exit(1).", file=sys.stderr)
            sys.exit(1)

        return response
Beispiel #10
0
  def testNestedListAsFetches(self):
    fetches = [self.const_c, [self.const_a, self.const_b]]
    run_start_intro = cli_shared.get_run_start_intro(1, fetches, None, {})

    # Verify lines about the fetches.
    self.assertEqual(self.const_c.name, run_start_intro.lines[4].strip())
    self.assertEqual(self.const_a.name, run_start_intro.lines[5].strip())
    self.assertEqual(self.const_b.name, run_start_intro.lines[6].strip())

    # Verify short description.
    description = cli_shared.get_run_short_description(1, fetches, None)
    self.assertEqual("run #1: 3 fetches; 0 feeds", description)
Beispiel #11
0
    def testNestedListAsFetches(self):
        fetches = [self.const_c, [self.const_a, self.const_b]]
        run_start_intro = cli_shared.get_run_start_intro(1, fetches, None, {})

        # Verify lines about the fetches.
        self.assertEqual(self.const_c.name, run_start_intro.lines[4].strip())
        self.assertEqual(self.const_a.name, run_start_intro.lines[5].strip())
        self.assertEqual(self.const_b.name, run_start_intro.lines[6].strip())

        # Verify short description.
        description = cli_shared.get_run_short_description(1, fetches, None)
        self.assertEqual("run #1: 3 fetches; 0 feeds", description)
Beispiel #12
0
    def testSingleFetchNoFeeds(self):
        run_start_intro = cli_shared.get_run_start_intro(
            12, self.const_a, None, {})

        # Verify line about run() call number.
        self.assertTrue(run_start_intro.lines[1].endswith("run() call #12:"))

        # Verify line about fetch.
        const_a_name_line = run_start_intro.lines[4]
        self.assertEqual(self.const_a.name, const_a_name_line.strip())

        # Verify line about feeds.
        feeds_line = run_start_intro.lines[7]
        self.assertEqual("(Empty)", feeds_line.strip())

        # Verify lines about possible commands and their font attributes.
        self.assertEqual("run:", run_start_intro.lines[11][2:])
        annot = run_start_intro.font_attr_segs[11][0]
        self.assertEqual(2, annot[0])
        self.assertEqual(5, annot[1])
        self.assertEqual("run", annot[2][0].content)
        self.assertEqual("bold", annot[2][1])
        annot = run_start_intro.font_attr_segs[13][0]
        self.assertEqual(2, annot[0])
        self.assertEqual(8, annot[1])
        self.assertEqual("run -n", annot[2][0].content)
        self.assertEqual("bold", annot[2][1])
        self.assertEqual("run -t <T>:", run_start_intro.lines[15][2:])
        self.assertEqual([(2, 12, "bold")], run_start_intro.font_attr_segs[15])
        self.assertEqual("run -f <filter_name>:",
                         run_start_intro.lines[17][2:])
        self.assertEqual([(2, 22, "bold")], run_start_intro.font_attr_segs[17])
        annot = run_start_intro.font_attr_segs[21][0]
        self.assertEqual(2, annot[0])
        self.assertEqual(16, annot[1])
        self.assertEqual("invoke_stepper", annot[2][0].content)

        # Verify short description.
        description = cli_shared.get_run_short_description(
            12, self.const_a, None)
        self.assertEqual("run #12: 1 fetch (a:0); 0 feeds", description)

        # Verify the main menu associated with the run_start_intro.
        self.assertIn(debugger_cli_common.MAIN_MENU_KEY,
                      run_start_intro.annotations)
        menu = run_start_intro.annotations[debugger_cli_common.MAIN_MENU_KEY]
        self.assertEqual("run", menu.caption_to_item("run").content)
        self.assertEqual("invoke_stepper",
                         menu.caption_to_item("invoke_stepper").content)
        self.assertEqual("exit", menu.caption_to_item("exit").content)
Beispiel #13
0
    def testTwoFetchesAsTupleNoFeeds(self):
        fetches = (self.const_a, self.const_b)
        run_start_intro = cli_shared.get_run_start_intro(1, fetches, None, {})

        const_a_name_line = run_start_intro.lines[4]
        const_b_name_line = run_start_intro.lines[5]
        self.assertEqual(self.const_a.name, const_a_name_line.strip())
        self.assertEqual(self.const_b.name, const_b_name_line.strip())

        feeds_line = run_start_intro.lines[8]
        self.assertEqual("(Empty)", feeds_line.strip())

        # Verify short description.
        description = cli_shared.get_run_short_description(1, fetches, None)
        self.assertEqual("run #1: 2 fetches; 0 feeds", description)
Beispiel #14
0
  def testTwoFetchesListNoFeeds(self):
    fetches = [self.const_a, self.const_b]
    run_start_intro = cli_shared.get_run_start_intro(1, fetches, None, {})

    const_a_name_line = run_start_intro.lines[4]
    const_b_name_line = run_start_intro.lines[5]
    self.assertEqual(self.const_a.name, const_a_name_line.strip())
    self.assertEqual(self.const_b.name, const_b_name_line.strip())

    feeds_line = run_start_intro.lines[8]
    self.assertEqual("(Empty)", feeds_line.strip())

    # Verify short description.
    description = cli_shared.get_run_short_description(1, fetches, None)
    self.assertEqual("run #1: 2 fetches; 0 feeds", description)
  def testTwoFetchesAsNamedTupleNoFeeds(self):
    fetches_namedtuple = namedtuple("fetches", "x y")
    fetches = fetches_namedtuple(self.const_b, self.const_c)
    run_start_intro = cli_shared.get_run_start_intro(1, fetches, None, {})

    const_b_name_line = run_start_intro.lines[4]
    const_c_name_line = run_start_intro.lines[5]
    self.assertEqual(self.const_b.name, const_b_name_line.strip())
    self.assertEqual(self.const_c.name, const_c_name_line.strip())

    feeds_line = run_start_intro.lines[8]
    self.assertEqual("(Empty)", feeds_line.strip())

    # Verify short description.
    description = cli_shared.get_run_short_description(1, fetches, None)
    self.assertEqual("run #1: 2 fetches; 0 feeds", description) id:3151 gh:3152
  def testNestedDictAsFetches(self):
    fetches = {"c": self.const_c, "ab": {"a": self.const_a, "b": self.const_b}}
    run_start_intro = cli_shared.get_run_start_intro(1, fetches, None, {})

    # Verify lines about the fetches. The ordering of the dict keys is
    # indeterminate.
    fetch_names = set()
    fetch_names.add(run_start_intro.lines[4].strip())
    fetch_names.add(run_start_intro.lines[5].strip())
    fetch_names.add(run_start_intro.lines[6].strip())

    self.assertEqual({"a:0", "b:0", "c:0"}, fetch_names)

    # Verify short description.
    description = cli_shared.get_run_short_description(1, fetches, None)
    self.assertEqual("run #1: 3 fetches; 0 feeds", description) id:2221 gh:2222
    def testTensorFilters(self):
        feed_dict = {self.const_a: 10.0}
        tensor_filters = {"filter_a": lambda x: True, "filter_b": lambda x: False}

        run_start_intro = cli_shared.get_run_start_intro(1, self.const_c, feed_dict, tensor_filters)

        # Verify the listed names of the tensor filters.
        filter_names = set()
        filter_names.add(run_start_intro.lines[22].split(" ")[-1])
        filter_names.add(run_start_intro.lines[23].split(" ")[-1])

        self.assertEqual({"filter_a", "filter_b"}, filter_names)

        # Verify short description.
        description = cli_shared.get_run_short_description(1, self.const_c, feed_dict)
        self.assertEqual("run #1: 1 fetch (c:0); 1 feed (a:0)", description)
Beispiel #18
0
  def testTwoFetchesAsNamedTupleNoFeeds(self):
    fetches_namedtuple = namedtuple("fetches", "x y")
    fetches = fetches_namedtuple(self.const_b, self.const_c)
    run_start_intro = cli_shared.get_run_start_intro(1, fetches, None, {})

    const_b_name_line = run_start_intro.lines[4]
    const_c_name_line = run_start_intro.lines[5]
    self.assertEqual(self.const_b.name, const_b_name_line.strip())
    self.assertEqual(self.const_c.name, const_c_name_line.strip())

    feeds_line = run_start_intro.lines[8]
    self.assertEqual("(Empty)", feeds_line.strip())

    # Verify short description.
    description = cli_shared.get_run_short_description(1, fetches, None)
    self.assertEqual("run #1: 2 fetches; 0 feeds", description)
Beispiel #19
0
  def testNestedDictAsFetches(self):
    fetches = {"c": self.const_c, "ab": {"a": self.const_a, "b": self.const_b}}
    run_start_intro = cli_shared.get_run_start_intro(1, fetches, None, {})

    # Verify lines about the fetches. The ordering of the dict keys is
    # indeterminate.
    fetch_names = set()
    fetch_names.add(run_start_intro.lines[4].strip())
    fetch_names.add(run_start_intro.lines[5].strip())
    fetch_names.add(run_start_intro.lines[6].strip())

    self.assertEqual({"a:0", "b:0", "c:0"}, fetch_names)

    # Verify short description.
    description = cli_shared.get_run_short_description(1, fetches, None)
    self.assertEqual("run #1: 3 fetches; 0 feeds", description)
Beispiel #20
0
  def testSingleFetchNoFeeds(self):
    run_start_intro = cli_shared.get_run_start_intro(12, self.const_a, None, {})

    # Verify line about run() call number.
    self.assertTrue(run_start_intro.lines[1].endswith("run() call #12:"))

    # Verify line about fetch.
    const_a_name_line = run_start_intro.lines[4]
    self.assertEqual(self.const_a.name, const_a_name_line.strip())

    # Verify line about feeds.
    feeds_line = run_start_intro.lines[7]
    self.assertEqual("(Empty)", feeds_line.strip())

    # Verify lines about possible commands and their font attributes.
    self.assertEqual("run:", run_start_intro.lines[11][2:])
    annot = run_start_intro.font_attr_segs[11][0]
    self.assertEqual(2, annot[0])
    self.assertEqual(5, annot[1])
    self.assertEqual("run", annot[2][0].content)
    self.assertEqual("bold", annot[2][1])
    annot = run_start_intro.font_attr_segs[13][0]
    self.assertEqual(2, annot[0])
    self.assertEqual(8, annot[1])
    self.assertEqual("run -n", annot[2][0].content)
    self.assertEqual("bold", annot[2][1])
    self.assertEqual("run -t <T>:", run_start_intro.lines[15][2:])
    self.assertEqual([(2, 12, "bold")], run_start_intro.font_attr_segs[15])
    self.assertEqual("run -f <filter_name>:", run_start_intro.lines[17][2:])
    self.assertEqual([(2, 22, "bold")], run_start_intro.font_attr_segs[17])
    annot = run_start_intro.font_attr_segs[21][0]
    self.assertEqual(2, annot[0])
    self.assertEqual(16, annot[1])
    self.assertEqual("invoke_stepper", annot[2][0].content)

    # Verify short description.
    description = cli_shared.get_run_short_description(12, self.const_a, None)
    self.assertEqual("run #12: 1 fetch (a:0); 0 feeds", description)

    # Verify the main menu associated with the run_start_intro.
    self.assertIn(debugger_cli_common.MAIN_MENU_KEY,
                  run_start_intro.annotations)
    menu = run_start_intro.annotations[debugger_cli_common.MAIN_MENU_KEY]
    self.assertEqual("run", menu.caption_to_item("run").content)
    self.assertEqual("invoke_stepper",
                     menu.caption_to_item("invoke_stepper").content)
    self.assertEqual("exit", menu.caption_to_item("exit").content)
Beispiel #21
0
    def testWithFeedDict(self):
        feed_dict = {self.const_a: 10.0, self.const_b: 20.0}

        run_start_intro = cli_shared.get_run_start_intro(1, self.const_c, feed_dict, {})

        const_c_name_line = run_start_intro.lines[4]
        self.assertEqual(self.const_c.name, const_c_name_line.strip())

        # Verify lines about the feed dict.
        feed_a_line = run_start_intro.lines[7]
        feed_b_line = run_start_intro.lines[8]
        self.assertEqual(self.const_a.name, feed_a_line.strip())
        self.assertEqual(self.const_b.name, feed_b_line.strip())

        # Verify short description.
        description = cli_shared.get_run_short_description(1, self.const_c, feed_dict)
        self.assertEqual("run #1: 1 fetch (c:0); 2 feeds", description)
    def _update_run_calls_state(self, run_call_count, fetches, feed_dict):
        """Update the internal state with regard to run() call history.

    Args:
      run_call_count: (int) Number of run() calls that have occurred.
      fetches: a node/tensor or a list of node/tensor that are the fetches of
        the run() call. This is the same as the fetches argument to the run()
        call.
      feed_dict: None of a dict. This is the feed_dict argument to the run()
        call.
    """

        self._run_call_count = run_call_count
        self._run_description = cli_shared.get_run_short_description(
            run_call_count, fetches, feed_dict)
        self._run_through_times -= 1

        self._run_info = cli_shared.get_run_start_intro(
            run_call_count, fetches, feed_dict, self._tensor_filters)
Beispiel #23
0
    def testTensorFilters(self):
        feed_dict = {self.const_a: 10.0}
        tensor_filters = {
            "filter_a": lambda x: True,
            "filter_b": lambda x: False,
        }

        run_start_intro = cli_shared.get_run_start_intro(
            1, self.const_c, feed_dict, tensor_filters)

        # Verify the listed names of the tensor filters.
        filter_names = set()
        filter_names.add(run_start_intro.lines[22].split(" ")[-1])
        filter_names.add(run_start_intro.lines[23].split(" ")[-1])

        self.assertEqual({"filter_a", "filter_b"}, filter_names)

        # Verify short description.
        description = cli_shared.get_run_short_description(
            1, self.const_c, feed_dict)
        self.assertEqual("run #1: 1 fetch (c:0); 1 feed (a:0)", description)
  def _update_run_calls_state(self, run_call_count, fetches, feed_dict):
    """Update the internal state with regard to run() call history.

    Args:
      run_call_count: (int) Number of run() calls that have occurred.
      fetches: a node/tensor or a list of node/tensor that are the fetches of
        the run() call. This is the same as the fetches argument to the run()
        call.
      feed_dict: None of a dict. This is the feed_dict argument to the run()
        call.
    """

    self._run_call_count = run_call_count
    self._run_description = cli_shared.get_run_short_description(run_call_count,
                                                                 fetches,
                                                                 feed_dict)
    self._run_through_times -= 1

    self._run_info = cli_shared.get_run_start_intro(run_call_count,
                                                    fetches,
                                                    feed_dict,
                                                    self._tensor_filters)
Beispiel #25
0
    def testWithFeedDict(self):
        feed_dict = {
            self.const_a: 10.0,
            self.const_b: 20.0,
        }

        run_start_intro = cli_shared.get_run_start_intro(
            1, self.const_c, feed_dict, {})

        const_c_name_line = run_start_intro.lines[4]
        self.assertEqual(self.const_c.name, const_c_name_line.strip())

        # Verify lines about the feed dict.
        feed_a_line = run_start_intro.lines[7]
        feed_b_line = run_start_intro.lines[8]
        self.assertEqual(self.const_a.name, feed_a_line.strip())
        self.assertEqual(self.const_b.name, feed_b_line.strip())

        # Verify short description.
        description = cli_shared.get_run_short_description(
            1, self.const_c, feed_dict)
        self.assertEqual("run #1: 1 fetch (c:0); 2 feeds", description)
    def on_run_start(self, request):
        """Overrides on-run-start callback.

    Invoke the CLI to let user choose what action to take:
      run / run --no_debug / step.

    Args:
      request: An instance of OnSessionInitRequest.

    Returns:
      An instance of OnSessionInitResponse.

    Raises:
      RuntimeError: If user chooses to prematurely exit the debugger.
    """

        self._update_run_calls_state(request.run_call_count, request.fetches,
                                     request.feed_dict)

        if self._run_till_filter_pass:
            # If we are running till a filter passes, we just need to keep running
            # with the DEBUG_RUN option.
            return framework.OnRunStartResponse(
                framework.OnRunStartAction.DEBUG_RUN,
                self._get_run_debug_urls())

        run_start_cli = curses_ui.CursesUI()

        run_start_cli.register_command_handler(
            "run",
            self._on_run_start_run_handler,
            self._on_run_start_parsers["run"].format_help(),
            prefix_aliases=["r"])
        run_start_cli.register_command_handler(
            "invoke_stepper",
            self._on_run_start_step_handler,
            self._on_run_start_parsers["invoke_stepper"].format_help(),
            prefix_aliases=["s"])

        if self._tensor_filters:
            # Register tab completion for the filter names.
            run_start_cli.register_tab_comp_context(
                ["run", "r"], list(self._tensor_filters.keys()))

        run_start_cli.set_help_intro(
            cli_shared.get_run_start_intro(request.run_call_count,
                                           request.fetches, request.feed_dict,
                                           self._tensor_filters))

        # Create initial screen output detailing the run.
        title = "run-start: " + self._run_description
        response = run_start_cli.run_ui(init_command="help",
                                        title=title,
                                        title_color="blue_on_white")
        if response == debugger_cli_common.EXPLICIT_USER_EXIT:
            # Explicit user "exit" command leads to sys.exit(1).
            print("Note: user exited from debugger CLI: Calling sys.exit(1).",
                  file=sys.stderr)
            sys.exit(1)

        return response
Beispiel #27
0
 def testSparseTensorAsFetchShouldHandleNoNameAttribute(self):
   run_start_intro = cli_shared.get_run_start_intro(1, self.sparse_d, None, {})
   self.assertEqual(str(self.sparse_d), run_start_intro.lines[4].strip())
Beispiel #28
0
 def testSparseTensorAsFetchShouldHandleNoNameAttribute(self):
     run_start_intro = cli_shared.get_run_start_intro(
         1, self.sparse_d, None, {})
     self.assertEqual(str(self.sparse_d), run_start_intro.lines[4].strip())