def test_normalize_multistring(value):
    expected = sum([s.strip().split(',') for s in value], [])

    assert normalize_multistring_option(value) == expected
def test_normalize_multistring_none():
    assert normalize_multistring_option(None) == []
def test_normalize_multistring_string():
    assert normalize_multistring_option(u'foo') == [u'foo']
Exemplo n.º 4
0
    def setup(self):
        # type: () -> None

        self.sentry = gluetool.sentry.Sentry()

        # Python installs SIGINT handler that translates signal to
        # a KeyboardInterrupt exception. It's so good we want to use
        # it for SIGTERM as well, just wrap the handler with some logging.
        orig_sigint_handler = signal.getsignal(signal.SIGINT)
        sigmap = {
            getattr(signal, name): name
            for name in
            [name for name in dir(signal) if name.startswith('SIG')]
        }

        def _signal_handler(signum, frame, handler=None, msg=None):
            # type: (int, FrameType, Optional[Callable[[int, FrameType], None]], Optional[str]) -> Any

            msg = msg or 'Signal {} received'.format(sigmap[signum])

            Glue.warn(msg)

            if handler is not None:
                return handler(signum, frame)

        def _sigusr1_handler(signum, frame):
            # type: (int, FrameType) -> None

            # pylint: disable=unused-argument

            raise GlueError('Pipeline timeout expired.')

        sigint_handler = functools.partial(
            _signal_handler,
            handler=orig_sigint_handler,
            msg='Interrupted by SIGINT (Ctrl+C?)')
        sigterm_handler = functools.partial(_signal_handler,
                                            handler=orig_sigint_handler,
                                            msg='Interrupted by SIGTERM')
        sigusr1_handler = functools.partial(_signal_handler,
                                            handler=_sigusr1_handler)

        # pylint: disable=invalid-name
        Glue = self.Glue = gluetool.Glue(tool=self, sentry=self.sentry)

        # Glue is initialized, we can install our logging handlers
        signal.signal(signal.SIGINT, sigint_handler)
        signal.signal(signal.SIGTERM, sigterm_handler)
        signal.signal(signal.SIGUSR1, sigusr1_handler)

        for signum in DEFAULT_HANDLED_SIGNALS:
            signal.signal(signum, _signal_handler)

        # process configuration
        Glue.parse_config(self.gluetool_config_paths)
        Glue.parse_args(sys.argv[1:])

        # store tool's configuration - everything till the start of "pipeline" (the first module)
        self.argv = sys.argv[1:len(sys.argv) - len(Glue.option('pipeline'))]

        if Glue.option('pid'):
            Glue.info('PID: {} PGID: {}'.format(os.getpid(), os.getpgrp()))

        # version
        if Glue.option('version'):
            Glue.info('{} {}'.format(self._command_name, self._version))
            sys.exit(0)

        GlueError.no_sentry_exceptions = normalize_multistring_option(
            Glue.option('no-sentry-exceptions'))

        Glue.load_modules()