Exemplo n.º 1
0
 def testSummarizeFromConfig(self):
     config = cli_config.CLIConfig(config_file_path=self._tmp_config_path)
     output = config.summarize()
     self.assertEqual([
         "Command-line configuration:", "",
         "  graph_recursion_depth: %d" %
         config.get("graph_recursion_depth"),
         "  mouse_mode: %s" % config.get("mouse_mode")
     ], output.lines)
Exemplo n.º 2
0
    def __init__(self, on_ui_exit=None, command_sequence=None):
        readline_ui.ReadlineUI.__init__(
            self,
            on_ui_exit=on_ui_exit,
            config=cli_config.CLIConfig(config_file_path=tempfile.mktemp()))

        self._command_sequence = command_sequence
        self._command_counter = 0

        self.observers = {"screen_outputs": []}
Exemplo n.º 3
0
 def testSummarizeFromConfigWithHighlight(self):
   config = cli_config.CLIConfig(config_file_path=self._tmp_config_path)
   output = config.summarize(highlight="mouse_mode")
   self.assertEqual(
       ["Command-line configuration:",
        "",
        "  graph_recursion_depth: %d" % config.get("graph_recursion_depth"),
        "  mouse_mode: %s" % config.get("mouse_mode")], output.lines)
   self.assertEqual((2, 12, ["underline", "bold"]),
                    output.font_attr_segs[3][0])
   self.assertEqual((14, 18, "bold"), output.font_attr_segs[3][1])
Exemplo n.º 4
0
  def testSetCallback(self):
    config = cli_config.CLIConfig(config_file_path=self._tmp_config_path)

    test_value = {"graph_recursion_depth": -1}
    def callback(config):
      test_value["graph_recursion_depth"] = config.get("graph_recursion_depth")
    config.set_callback("graph_recursion_depth", callback)

    config.set("graph_recursion_depth", config.get("graph_recursion_depth") - 1)
    self.assertEqual(test_value["graph_recursion_depth"],
                     config.get("graph_recursion_depth"))
Exemplo n.º 5
0
    def __init__(self, on_ui_exit=None, config=None):
        """Constructor of the base class.

    Args:
      on_ui_exit: (`Callable`) the callback to be called when the UI exits.
      config: An instance of `cli_config.CLIConfig()` carrying user-facing
        configurations.
    """

        self._on_ui_exit = on_ui_exit

        self._command_handler_registry = (
            debugger_cli_common.CommandHandlerRegistry())

        self._tab_completion_registry = debugger_cli_common.TabCompletionRegistry(
        )

        # Create top-level tab-completion context and register the exit and help
        # commands.
        self._tab_completion_registry.register_tab_comp_context(
            [""], self.CLI_EXIT_COMMANDS +
            [debugger_cli_common.CommandHandlerRegistry.HELP_COMMAND] +
            debugger_cli_common.CommandHandlerRegistry.HELP_COMMAND_ALIASES)

        self._config = config or cli_config.CLIConfig()
        self._config_argparser = argparse.ArgumentParser(
            description="config command", usage=argparse.SUPPRESS)
        subparsers = self._config_argparser.add_subparsers()
        set_parser = subparsers.add_parser("set")
        set_parser.add_argument("property_name", type=str)
        set_parser.add_argument("property_value", type=str)
        set_parser = subparsers.add_parser("show")
        self.register_command_handler("config",
                                      self._config_command_handler,
                                      self._config_argparser.format_help(),
                                      prefix_aliases=["cfg"])
 def testUIFactoryRaisesExceptionOnInvalidUITypeGivenAvailable(self):
   with self.assertRaisesRegex(ValueError, "Invalid ui_type: 'readline'"):
     ui_factory.get_ui(
         "readline",
         available_ui_types=["curses"],
         config=cli_config.CLIConfig(config_file_path=self._tmp_config_path))
 def testUIFactoryRaisesExceptionOnInvalidUIType(self):
   with self.assertRaisesRegex(ValueError, "Invalid ui_type: 'foobar'"):
     ui_factory.get_ui(
         "foobar",
         config=cli_config.CLIConfig(config_file_path=self._tmp_config_path))
 def testUIFactoryCreatesReadlineUI(self):
   ui = ui_factory.get_ui(
       "readline",
       config=cli_config.CLIConfig(config_file_path=self._tmp_config_path))
   self.assertIsInstance(ui, readline_ui.ReadlineUI)
Exemplo n.º 9
0
 def testModifyConfigValueWithTypeCastingFailure(self):
     config = cli_config.CLIConfig(config_file_path=self._tmp_config_path)
     with self.assertRaises(ValueError):
         config.set("mouse_mode", "maybe")
Exemplo n.º 10
0
 def testModifyConfigValueWithTypeCasting(self):
     config = cli_config.CLIConfig(config_file_path=self._tmp_config_path)
     config.set("graph_recursion_depth", "18")
     config.set("mouse_mode", "false")
     self.assertEqual(18, config.get("graph_recursion_depth"))
     self.assertEqual(False, config.get("mouse_mode"))
Exemplo n.º 11
0
 def testModifyConfigValue(self):
     config = cli_config.CLIConfig(config_file_path=self._tmp_config_path)
     config.set("graph_recursion_depth", 9)
     config.set("mouse_mode", False)
     self.assertEqual(9, config.get("graph_recursion_depth"))
     self.assertEqual(False, config.get("mouse_mode"))
Exemplo n.º 12
0
    def testSetCallbackNotCallable(self):
        config = cli_config.CLIConfig(config_file_path=self._tmp_config_path)

        with self.assertRaises(TypeError):
            config.set_callback("graph_recursion_depth", 1)
Exemplo n.º 13
0
    def testSetCallbackInvalidPropertyName(self):
        config = cli_config.CLIConfig(config_file_path=self._tmp_config_path)

        with self.assertRaises(KeyError):
            config.set_callback("nonexistent_property_name", print)
Exemplo n.º 14
0
    def __init__(self,
                 sess,
                 dump_root=None,
                 log_usage=True,
                 ui_type="curses",
                 thread_name_filter=None,
                 config_file_path=False):
        """Constructor of LocalCLIDebugWrapperSession.

    Args:
      sess: The TensorFlow `Session` object being wrapped.
      dump_root: (`str`) optional path to the dump root directory. Must be a
        directory that does not exist or an empty directory. If the directory
        does not exist, it will be created by the debugger core during debug
        `run()` calls and removed afterwards. If `None`, the debug dumps will
        be at tfdbg_<random_string> under the system temp directory.
      log_usage: (`bool`) whether the usage of this class is to be logged.
      ui_type: (`str`) requested UI type. Currently supported:
        (curses | readline)
      thread_name_filter: Regular-expression white list for thread name. See
        the doc of `BaseDebugWrapperSession` for details.
      config_file_path: Optional override to the default configuration file
        path, which is at `${HOME}/.tfdbg_config`.

    Raises:
      ValueError: If dump_root is an existing and non-empty directory or if
        dump_root is a file.
    """

        if log_usage:
            pass  # No logging for open-source.

        framework.BaseDebugWrapperSession.__init__(
            self, sess, thread_name_filter=thread_name_filter)

        if not dump_root:
            self._dump_root = tempfile.mktemp(prefix=_DUMP_ROOT_PREFIX)
        else:
            dump_root = os.path.expanduser(dump_root)
            if os.path.isfile(dump_root):
                raise ValueError("dump_root path points to a file: %s" %
                                 dump_root)
            elif os.path.isdir(dump_root) and os.listdir(dump_root):
                raise ValueError(
                    "dump_root path points to a non-empty directory: %s" %
                    dump_root)

            self._dump_root = dump_root

        self._initialize_argparsers()

        # Registered tensor filters.
        self._tensor_filters = {}
        # Register frequently-used filter(s).
        self.add_tensor_filter("has_inf_or_nan", debug_data.has_inf_or_nan)

        # Below are the state variables of this wrapper object.
        # _active_tensor_filter: what (if any) tensor filter is in effect. If such
        #   a filter is in effect, this object will call run() method of the
        #   underlying TensorFlow Session object until the filter passes. This is
        #   activated by the "-f" flag of the "run" command.
        # _run_through_times: keeps track of how many times the wrapper needs to
        #   run through without stopping at the run-end CLI. It is activated by the
        #   "-t" option of the "run" command.
        # _skip_debug: keeps track of whether the current run should be executed
        #   without debugging. It is activated by the "-n" option of the "run"
        #   command.
        #
        # _run_start_response: keeps track what OnRunStartResponse the wrapper
        #   should return at the next run-start callback. If this information is
        #   unavailable (i.e., is None), the run-start CLI will be launched to ask
        #   the user. This is the case, e.g., right before the first run starts.
        self._active_tensor_filter = None
        self._active_filter_exclude_node_names = None
        self._active_tensor_filter_run_start_response = None
        self._run_through_times = 1
        self._skip_debug = False
        self._run_start_response = None
        self._is_run_start = True
        self._ui_type = ui_type
        self._config = None
        if config_file_path:
            self._config = cli_config.CLIConfig(
                config_file_path=config_file_path)