예제 #1
0
    def _register_app_args(self, h: OptionContext):
        if self._version:
            h.add_custom_decorator(lambda: click.version_option(self._version))

        h.add_option('--cwd', dest='cwd', help='Change to specified directory')
        h.add_option('--wait',
                     is_flag=True,
                     help='Wait for user input before terminating application')
        h.add_option('--print-backtraces',
                     dest='print_backtraces',
                     is_flag=True,
                     help='Print backtraces of the exceptions')

        debug_opts = ['--debug']
        if self._enable_short_debug_option:
            debug_opts.insert(0, '-d')
        h.add_option(*debug_opts,
                     dest='debug',
                     is_flag=True,
                     help='Enable print/log debug messages')
        if self._enable_env_options:
            h.add_option(
                '-e',
                '--environment',
                dest='environment',
                help=f'Specifies the environment to run the app '
                f'under ({"/".join(sorted(self._env_config.available_envs))})')

        logging = h.add_group('Logging')
        logging.add_option('--log-level',
                           dest='log_level',
                           help='Set log level, default: warning',
                           type=click.Choice(
                               [i.name.lower() for i in LogLevel]),
                           default='info')
        logging.add_option(
            '--log-syslog',
            dest='log_syslog',
            is_flag=True,
            help='Log to syslog. Can be combined with other log targets')
        logging.add_option(
            '--log-console',
            '--log-stdout',
            dest='log_console',
            is_flag=True,
            help=
            'Log to STDOUT, the console. Can be combined with other targets.'
            'If no target is specified, this is used as default.')
        logging.add_option(
            '--log-file',
            dest='log_file',
            multiple=True,
            help='Log to a file. Can be specified multiple times and '
            'can be combined with other options.')
        logging.add_option(
            '--no-log',
            '-l',
            dest='log_none',
            is_flag=True,
            help='Disable logging. If this is set, other targets are invalid.')
예제 #2
0
    def register_arguments(c: OptionContext):
        c.add_option('--wait-for-close', help='Wait a minute before closing Chrome', is_flag=True)

        driver_grp = c.add_group(
            'Browser and WebDriver options',
            help='Options influences the behaviour of Selenium Web Driver and Google Chrome / Firefox')

        driver_grp.add_option('--screenshots', '--screenshot-dir', dest='screenshot_dir', default='.',
                                help='The directory to save any screenshot, default: current directory')
        driver_grp.add_option('--download-directory', '--dl-dir', dest='download_dir', required=True,
                                help='Download directory')
        driver_grp.add_option('--headless', is_flag=True, help='Start Chrome in headless mode')
        driver_grp.add_option('--timeout', type=int, default=60,
                                help='Timeout for waiting any element or action, default: 60s')
예제 #3
0
class OptionContextTest(_InvokableTestBase):
    def test_embedded_groups(self):
        params = dict()

        def f(p):
            nonlocal params
            params = p

        self.tested = OptionContext()
        self.tested.add_option('--first-option', help='The first option')
        grp = self.tested.add_group()
        grp.add_option(
            '--grp1',
            dest='grp1arg',
            is_flag=True,
        )
        self.tested.add_option(
            '--second-option',
            is_flag=True,
        )
        grp2 = self.tested.add_group('A title')
        self.tested.add_option(
            '--3rd-option',
            dest='opt3',
            is_flag=True,
        )
        grp2.add_option(
            '--grp2',
            dest='grp2arg',
            is_flag=True,
        )
        grp.add_option(
            '--grp1-second',
            is_flag=True,
        )

        r = self._invoke_redirected(self.tested,
                                    f,
                                    self.HELP_ARGS,
                                    expected_exit_value=0)
        self.assert_equal({}, params)
        self.assert_equal('', r.stderr.getvalue())
        lines = r.stdout.getvalue().splitlines(keepends=False)
        self.assert_equal(11, len(lines))
        self.assert_true(lines[0].startswith('Usage'))
        self.assert_equal([
            'Options:',
            _i('--first-option TEXT  The first option', 1),
            _i('--grp1', 2),
            _i('--grp1-second', 2),
            _i('--second-option', 1),
            _i('A title: ', 1),
            _i('--grp2', 2),
            _i('--3rd-option', 1)
        ], lines[2:-1])

        r = self._invoke_redirected(self.tested,
                                    f, ['--first-option', 'something'],
                                    expected_exit_value=0)
        self.assert_equal(
            {
                'first_option': 'something',
                'grp1arg': False,
                'grp1_second': False,
                'second_option': False,
                'grp2arg': False,
                'opt3': False
            }, params)
        self.assert_equal('', r.stdout.getvalue())
        self.assert_equal('', r.stderr.getvalue())