当前位置: 首页>>代码示例>>Python>>正文


Python app.App方法代码示例

本文整理汇总了Python中cliff.app.App方法的典型用法代码示例。如果您正苦于以下问题:Python app.App方法的具体用法?Python app.App怎么用?Python app.App使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cliff.app的用法示例。


在下文中一共展示了app.App方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _load_app

# 需要导入模块: from cliff import app [as 别名]
# 或者: from cliff.app import App [as 别名]
def _load_app(self):
        mod_str, _sep, class_str = self.arguments[0].rpartition('.')
        if not mod_str:
            return
        try:
            importlib.import_module(mod_str)
        except ImportError:
            return
        try:
            cliff_app_class = getattr(sys.modules[mod_str], class_str)
        except AttributeError:
            return
        if not inspect.isclass(cliff_app_class):
            return
        if not issubclass(cliff_app_class, app.App):
            return
        app_arguments = self.options.get('arguments', '').split()
        return cliff_app_class(*app_arguments) 
开发者ID:openstack,项目名称:cliff,代码行数:20,代码来源:sphinxext.py

示例2: test_show_help_for_command

# 需要导入模块: from cliff import app [as 别名]
# 或者: from cliff.app import App [as 别名]
def test_show_help_for_command(self):
        # FIXME(dhellmann): Are commands tied too closely to the app? Or
        # do commands know too much about apps by using them to get to the
        # command manager?
        stdout = StringIO()
        app = application.App('testing', '1',
                              utils.TestCommandManager(utils.TEST_NAMESPACE),
                              stdout=stdout)
        app.NAME = 'test'
        help_cmd = help.HelpCommand(app, mock.Mock())
        parser = help_cmd.get_parser('test')
        parsed_args = parser.parse_args(['one'])
        try:
            help_cmd.run(parsed_args)
        except SystemExit:
            pass
        self.assertEqual('TestParser', stdout.getvalue()) 
开发者ID:openstack,项目名称:cliff,代码行数:19,代码来源:test_help.py

示例3: test_list_matching_commands

# 需要导入模块: from cliff import app [as 别名]
# 或者: from cliff.app import App [as 别名]
def test_list_matching_commands(self):
        # FIXME(dhellmann): Are commands tied too closely to the app? Or
        # do commands know too much about apps by using them to get to the
        # command manager?
        stdout = StringIO()
        app = application.App('testing', '1',
                              utils.TestCommandManager(utils.TEST_NAMESPACE),
                              stdout=stdout)
        app.NAME = 'test'
        help_cmd = help.HelpCommand(app, mock.Mock())
        parser = help_cmd.get_parser('test')
        parsed_args = parser.parse_args(['t'])
        try:
            help_cmd.run(parsed_args)
        except SystemExit:
            pass
        help_output = stdout.getvalue()
        self.assertIn('Command "t" matches:', help_output)
        self.assertIn('three word command\n  two words\n', help_output) 
开发者ID:openstack,项目名称:cliff,代码行数:21,代码来源:test_help.py

示例4: test_list_matching_commands_no_match

# 需要导入模块: from cliff import app [as 别名]
# 或者: from cliff.app import App [as 别名]
def test_list_matching_commands_no_match(self):
        # FIXME(dhellmann): Are commands tied too closely to the app? Or
        # do commands know too much about apps by using them to get to the
        # command manager?
        stdout = StringIO()
        app = application.App('testing', '1',
                              utils.TestCommandManager(utils.TEST_NAMESPACE),
                              stdout=stdout)
        app.NAME = 'test'
        help_cmd = help.HelpCommand(app, mock.Mock())
        parser = help_cmd.get_parser('test')
        parsed_args = parser.parse_args(['z'])
        self.assertRaises(
            ValueError,
            help_cmd.run,
            parsed_args,
        ) 
开发者ID:openstack,项目名称:cliff,代码行数:19,代码来源:test_help.py

示例5: test_list_deprecated_commands

# 需要导入模块: from cliff import app [as 别名]
# 或者: from cliff.app import App [as 别名]
def test_list_deprecated_commands(self):
        # FIXME(dhellmann): Are commands tied too closely to the app? Or
        # do commands know too much about apps by using them to get to the
        # command manager?
        stdout = StringIO()
        app = application.App('testing', '1',
                              utils.TestCommandManager(utils.TEST_NAMESPACE),
                              stdout=stdout)
        app.NAME = 'test'
        try:
            app.run(['--help'])
        except SystemExit:
            pass
        help_output = stdout.getvalue()
        self.assertIn('two words', help_output)
        self.assertIn('three word command', help_output)
        self.assertNotIn('old cmd', help_output) 
开发者ID:openstack,项目名称:cliff,代码行数:19,代码来源:test_help.py

示例6: test_show_help_with_ep_load_fail

# 需要导入模块: from cliff import app [as 别名]
# 或者: from cliff.app import App [as 别名]
def test_show_help_with_ep_load_fail(self, mock_load):
        stdout = StringIO()
        app = application.App('testing', '1',
                              utils.TestCommandManager(utils.TEST_NAMESPACE),
                              stdout=stdout)
        app.NAME = 'test'
        app.options = mock.Mock()
        app.options.debug = False
        help_cmd = help.HelpCommand(app, mock.Mock())
        parser = help_cmd.get_parser('test')
        parsed_args = parser.parse_args([])
        try:
            help_cmd.run(parsed_args)
        except SystemExit:
            pass
        help_output = stdout.getvalue()
        self.assertIn('Commands:', help_output)
        self.assertIn('Could not load', help_output)
        self.assertNotIn('Exception: Could not load EntryPoint', help_output) 
开发者ID:openstack,项目名称:cliff,代码行数:21,代码来源:test_help.py

示例7: test_show_help_print_exc_with_ep_load_fail

# 需要导入模块: from cliff import app [as 别名]
# 或者: from cliff.app import App [as 别名]
def test_show_help_print_exc_with_ep_load_fail(self, mock_load):
        stdout = StringIO()
        app = application.App('testing', '1',
                              utils.TestCommandManager(utils.TEST_NAMESPACE),
                              stdout=stdout)
        app.NAME = 'test'
        app.options = mock.Mock()
        app.options.debug = True
        help_cmd = help.HelpCommand(app, mock.Mock())
        parser = help_cmd.get_parser('test')
        parsed_args = parser.parse_args([])
        try:
            help_cmd.run(parsed_args)
        except SystemExit:
            pass
        help_output = stdout.getvalue()
        self.assertIn('Commands:', help_output)
        self.assertIn('Could not load', help_output)
        self.assertIn('Exception: Could not load EntryPoint', help_output) 
开发者ID:openstack,项目名称:cliff,代码行数:21,代码来源:test_help.py

示例8: test_conflicting_option_custom_arguments_should_not_throw

# 需要导入模块: from cliff import app [as 别名]
# 或者: from cliff.app import App [as 别名]
def test_conflicting_option_custom_arguments_should_not_throw(self):
        class MyApp(application.App):
            def __init__(self):
                super(MyApp, self).__init__(
                    description='testing',
                    version='0.1',
                    command_manager=commandmanager.CommandManager('tests'),
                )

            def build_option_parser(self, description, version):
                argparse_kwargs = {'conflict_handler': 'resolve'}
                parser = super(MyApp, self).build_option_parser(
                    description,
                    version,
                    argparse_kwargs=argparse_kwargs)
                parser.add_argument(
                    '-h', '--help',
                    default=self,  # tricky
                    help="Show help message and exit.",
                )

        MyApp() 
开发者ID:openstack,项目名称:cliff,代码行数:24,代码来源:test_app.py

示例9: test_list_matching_commands

# 需要导入模块: from cliff import app [as 别名]
# 或者: from cliff.app import App [as 别名]
def test_list_matching_commands(self):
        stdout = StringIO()
        app = application.App('testing', '1',
                              test_utils.TestCommandManager(
                                  test_utils.TEST_NAMESPACE),
                              stdout=stdout)
        app.NAME = 'test'
        try:
            self.assertEqual(2, app.run(['t']))
        except SystemExit:
            pass
        output = stdout.getvalue()
        self.assertIn("test: 't' is not a test command. See 'test --help'.",
                      output)
        self.assertIn('Did you mean one of these?', output)
        self.assertIn('three word command\n  two words\n', output) 
开发者ID:openstack,项目名称:cliff,代码行数:18,代码来源:test_app.py

示例10: __init__

# 需要导入模块: from cliff import app [as 别名]
# 或者: from cliff.app import App [as 别名]
def __init__(self):
        """
        Initialization function of the class. It creates instances
        of the lightbulb CLI show and use functionalities.
        """
        super(LightBulb, self).__init__(
            description='LightBulb App',
            version='0.1',
            command_manager=CommandManager('cliff.lightbulb'),
            deferred_help=False,
        )
        self.library = LibraryModules(self, self, None)
        self.librarycat = LibraryCat(self, self, None)
        self.startsaved = StartSaved(self, self, None)
        self.use = Use(self, self, None)
        self.back = Back(self, self, None)
        self.define = Define(self, self, None) 
开发者ID:lightbulb-framework,项目名称:lightbulb-framework,代码行数:19,代码来源:api.py

示例11: make_app

# 需要导入模块: from cliff import app [as 别名]
# 或者: from cliff.app import App [as 别名]
def make_app(**kwargs):
    cmd_mgr = commandmanager.CommandManager('cliff.tests')

    # Register a command that succeeds
    cmd = mock.MagicMock(spec=command.Command)
    command_inst = mock.MagicMock(spec=command.Command)
    command_inst.run.return_value = 0
    cmd.return_value = command_inst
    cmd_mgr.add_command('mock', cmd)

    # Register a command that fails
    err_command = mock.Mock(name='err_command', spec=command.Command)
    err_command_inst = mock.Mock(spec=command.Command)
    err_command_inst.run = mock.Mock(
        side_effect=RuntimeError('test exception')
    )
    err_command.return_value = err_command_inst
    cmd_mgr.add_command('error', err_command)

    app = application.App('testing command hooks',
                          '1',
                          cmd_mgr,
                          stderr=mock.Mock(),  # suppress warning messages
                          **kwargs
                          )
    return app 
开发者ID:openstack,项目名称:cliff,代码行数:28,代码来源:test_command_hooks.py

示例12: given_complete_command

# 需要导入模块: from cliff import app [as 别名]
# 或者: from cliff.app import App [as 别名]
def given_complete_command(self):
        cmd_mgr = commandmanager.CommandManager('cliff.tests')
        app = application.App('testing', '1', cmd_mgr, stdout=FakeStdout())
        sot = complete.CompleteCommand(app, mock.Mock())
        cmd_mgr.add_command('complete', complete.CompleteCommand)
        return sot, app, cmd_mgr 
开发者ID:openstack,项目名称:cliff,代码行数:8,代码来源:test_complete.py

示例13: make_app

# 需要导入模块: from cliff import app [as 别名]
# 或者: from cliff.app import App [as 别名]
def make_app(**kwargs):
    cmd_mgr = commandmanager.CommandManager('cliff.tests')

    # Register a command that succeeds
    command = mock.MagicMock(spec=c_cmd.Command)
    command_inst = mock.MagicMock(spec=c_cmd.Command)
    command_inst.run.return_value = 0
    command.return_value = command_inst
    cmd_mgr.add_command('mock', command)

    # Register a command that fails
    err_command = mock.Mock(name='err_command', spec=c_cmd.Command)
    err_command_inst = mock.Mock(spec=c_cmd.Command)
    err_command_inst.run = mock.Mock(
        side_effect=RuntimeError('test exception')
    )
    err_command.return_value = err_command_inst
    cmd_mgr.add_command('error', err_command)

    app = application.App('testing interactive mode',
                          '1',
                          cmd_mgr,
                          stderr=mock.Mock(),  # suppress warning messages
                          **kwargs
                          )
    return app, command 
开发者ID:openstack,项目名称:cliff,代码行数:28,代码来源:test_app.py

示例14: test_option_parser_abbrev_issue

# 需要导入模块: from cliff import app [as 别名]
# 或者: from cliff.app import App [as 别名]
def test_option_parser_abbrev_issue(self):
        class MyCommand(c_cmd.Command):
            def get_parser(self, prog_name):
                parser = super(MyCommand, self).get_parser(prog_name)
                parser.add_argument("--end")
                return parser

            def take_action(self, parsed_args):
                assert(parsed_args.end == '123')

        class MyCommandManager(commandmanager.CommandManager):
            def load_commands(self, namespace):
                self.add_command("mycommand", MyCommand)

        class MyApp(application.App):
            def __init__(self):
                super(MyApp, self).__init__(
                    description='testing',
                    version='0.1',
                    command_manager=MyCommandManager(None),
                )

            def build_option_parser(self, description, version):
                parser = super(MyApp, self).build_option_parser(
                    description,
                    version,
                    argparse_kwargs={'allow_abbrev': False})
                parser.add_argument('--endpoint')
                return parser

        app = MyApp()
        # NOTE(jd) --debug is necessary so assert in take_action()
        # raises correctly here
        app.run(['--debug', 'mycommand', '--end', '123']) 
开发者ID:openstack,项目名称:cliff,代码行数:36,代码来源:test_app.py

示例15: test_fuzzy_no_commands

# 需要导入模块: from cliff import app [as 别名]
# 或者: from cliff.app import App [as 别名]
def test_fuzzy_no_commands(self):
        cmd_mgr = commandmanager.CommandManager('cliff.fuzzy')
        app = application.App('test', '1.0', cmd_mgr)
        cmd_mgr.commands = {}
        matches = app.get_fuzzy_matches('foo')
        self.assertEqual([], matches) 
开发者ID:openstack,项目名称:cliff,代码行数:8,代码来源:test_app.py


注:本文中的cliff.app.App方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。