Ejemplo n.º 1
0
    def test_extra_arg(self):
        """
        Tests that passing an extra argument gets caught.
        """
        extra_arg = 'extra'
        while extra_arg in QdbConfig.DEFAULT_OPTIONS:
            # Assert athat extra_arg is NOT a valid option.
            extra_arg += '_'

        with self.assertRaisesRegexp(TypeError, extra_arg):
            QdbConfig.get_config({extra_arg: None})
Ejemplo n.º 2
0
    def test_extra_arg(self):
        """
        Tests that passing an extra argument gets caught.
        """
        extra_arg = 'extra'
        while extra_arg in QdbConfig.DEFAULT_OPTIONS:
            # Assert athat extra_arg is NOT a valid option.
            extra_arg += '_'

        with self.assertRaisesRegexp(TypeError, extra_arg):
            QdbConfig.get_config({extra_arg: None})
Ejemplo n.º 3
0
    def setUpClass(cls):
        cls.contents = dedent("""\
            # FOR TESTING PURPOSES
            config = QdbConfig(**{
                'host': 'user-set',
                'port': 'user-set',
                'auth_msg': 'user-set',
                'default_file': 'user-set',
                'default_namespace': 'user-set',
                'eval_fn': 'user-set',
                'exception_serializer': 'user-set',
                'skip_fn': 'user-set',
                'pause_signal': 'user-set',
                'redirect_output': 'user-set',
                'retry_attempts': 'user-set',
                'uuid': 'user-set',
                'cmd_manager': 'user-set',
                'green': 'user-set',
                'repr_fn': 'user-set',
                'log_file': 'user-set',
                'execution_timeout': 'user-set',
            })
            """)
        cls.old_home = os.environ['HOME']
        cls.home = mkdtemp()
        os.environ['HOME'] = cls.home
        cls.profile_path = os.path.join(cls.home, '.qdb')
        cls.profile = open(cls.profile_path, 'w+')
        cls.profile.write(cls.contents)
        cls.profile.flush()

        cls.expected = QdbConfig(
            **{k: 'user-set'
               for k in QdbConfig.DEFAULT_OPTIONS})
Ejemplo n.º 4
0
    def _test_file(self, files=None, use_local=False, use_profile=False):
        """
        Tests reading a local file.
        """
        config = QdbConfig.get_config(
            files=files, use_local=use_local, use_profile=use_profile,
        )

        self.assertEqual(self.expected._asdict(), config._asdict())
Ejemplo n.º 5
0
    def _test_file(self, files=None, use_local=False, use_profile=False):
        """
        Tests reading a local file.
        """
        config = QdbConfig.get_config(
            files=files, use_local=use_local, use_profile=use_profile,
        )

        self.assertEqual(self.expected._asdict(), config._asdict())
Ejemplo n.º 6
0
    def __init__(self, config=None, merge=False, **kwargs):
        """
        See qdb.config for more information about the configuration of
        qdb.
        merge denotes how config and kwargs should be merged.
        QdbConfig.kwargs_first says config will trample kwargs,
        QdbConfig.config_first says kwargs will trample config.
        Otherwise, kwargs and config cannot both be passed.
        """
        super(Qdb, self).__init__()
        if config and kwargs:
            if merge == QdbConfig.kwargs_first:
                first = kwargs
                second = config
            elif merge == QdbConfig.config_first:
                first = config
                second = kwargs
            else:
                raise TypeError('Cannot pass config and kwargs')
            config = first.merge(second)
        else:
            config = QdbConfig.get_config(config or kwargs)

        self.address = config.host, config.port
        self.set_default_file(config.default_file)
        self.default_namespace = config.default_namespace or {}
        self.exception_serializer = config.exception_serializer or \
            default_exception_serializer
        self.eval_fn = config.eval_fn or default_eval_fn
        self.green = config.green
        self._file_cache = {}
        self.redirect_output = config.redirect_output
        self.retry_attepts = config.retry_attepts
        self.repr_fn = config.repr_fn
        self.skip_fn = config.skip_fn or (lambda _: False)
        self.pause_signal = config.pause_signal \
            if config.pause_signal else signal.SIGUSR2
        self.uuid = str(config.uuid or uuid4())
        self.watchlist = {}
        self.execution_timeout = config.execution_timeout
        # We need to be able to send stdout back to the user debugging the
        # program. We hold a handle to this in case the program resets stdout.
        if self.redirect_output:
            self._old_stdout = sys.stdout
            self._old_stderr = sys.stderr
            self.stdout = StringIO()
            self.stderr = StringIO()
            sys.stdout = self.stdout
            sys.stderr = self.stderr
        self.forget()
        self.log_handler = None
        if config.log_file:
            self.log_handler = FileHandler(config.log_file)
            self.log_handler.push_application()
        self.cmd_manager = (config.cmd_manager or RemoteCommandManager)(self)
        self.cmd_manager.start(config.auth_msg)
Ejemplo n.º 7
0
Archivo: tracer.py Proyecto: zw1226/qdb
    def _init(self, config=None, merge=False, **kwargs):
        """
        See qdb.config for more information about the configuration of
        qdb.
        merge denotes how config and kwargs should be merged.
        QdbConfig.kwargs_first says config will trample kwargs,
        QdbConfig.config_first says kwargs will trample config.
        Otherwise, kwargs and config cannot both be passed.
        """
        self.super_ = super(Qdb, self)
        self.super_.__init__()
        self.reset()
        if config and kwargs:
            if merge == QdbConfig.kwargs_first:
                first = kwargs
                second = config
            elif merge == QdbConfig.config_first:
                first = config
                second = kwargs
            else:
                raise TypeError('Cannot pass config and kwargs')
            config = first.merge(second)
        else:
            config = QdbConfig.get_config(config or kwargs)

        self.address = config.host, config.port
        self.set_default_file(config.default_file)
        self.default_namespace = config.default_namespace or {}
        self.exception_serializer = config.exception_serializer or \
            default_exception_serializer
        self.eval_fn = config.eval_fn or default_eval_fn
        self._file_cache = {}
        self.retry_attepts = config.retry_attepts
        self.repr_fn = config.repr_fn
        self._skip_fn = config.skip_fn or (lambda _: False)
        self.pause_signal = config.pause_signal \
            if config.pause_signal else signal.SIGUSR2
        self.uuid = str(config.uuid or uuid4())
        self.watchlist = {}
        self.execution_timeout = config.execution_timeout
        self.reset()
        self.log_handler = None
        if config.log_file:
            self.log_handler = FileHandler(config.log_file)
            self.log_handler.push_application()

        self.bound_cmd_manager = config.cmd_manager or TerminalCommandManager()
        self.bound_cmd_manager.start(config.auth_msg)

        # We need to be able to send stdout back to the user debugging the
        # program. We hold a handle to this in case the program resets stdout.
        self._old_stdout = sys.stdout
        self._old_stderr = sys.stderr
        self.redirect_output = (
            config.redirect_output and
            not isinstance(self.cmd_manager, TerminalCommandManager)
        )
        if self.redirect_output:
            sys.stdout = OutputTee(
                sys.stdout,
                RemoteOutput(self.cmd_manager, '<stdout>'),
            )
            sys.stderr = OutputTee(
                sys.stderr,
                RemoteOutput(self.cmd_manager, '<stderr>'),
            )