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


Python parser.Parser类代码示例

本文整理汇总了Python中invoke.parser.Parser的典型用法代码示例。如果您正苦于以下问题:Python Parser类的具体用法?Python Parser怎么用?Python Parser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: parses_sys_argv_style_list_of_strings

 def parses_sys_argv_style_list_of_strings(self):
     "parses sys.argv-style list of strings"
     # Doesn't-blow-up tests FTL
     mytask = Context(name="mytask")
     mytask.add_arg("arg")
     p = Parser(contexts=[mytask])
     p.parse_argv(["mytask", "--arg", "value"])
开发者ID:pyinvoke,项目名称:invoke,代码行数:7,代码来源:parser_parser.py

示例2: value_requiring_core_flags_also_work_correctly

 def value_requiring_core_flags_also_work_correctly(self):
     "value-requiring core flags also work correctly"
     initial = Context(args=[Argument("hide")])
     task1 = Context("mytask")
     parser = Parser(initial=initial, contexts=[task1])
     result = parser.parse_argv(["mytask", "--hide", "both"])
     assert result[0].args.hide.value == "both"
开发者ID:pyinvoke,项目名称:invoke,代码行数:7,代码来源:parser_parser.py

示例3: by_itself_base_case

 def by_itself_base_case(self):
     task1 = Context("mytask")
     init = Context(args=[Argument("help", optional=True)])
     parser = Parser(initial=init, contexts=[task1])
     result = parser.parse_argv(["mytask", "--help"])
     assert len(result) == 2
     assert result[0].args.help.value == "mytask"
     assert "help" not in result[1].args
开发者ID:pyinvoke,项目名称:invoke,代码行数:8,代码来源:parser_parser.py

示例4: flag_values_not_parsed_as_flags

 def flag_values_not_parsed_as_flags(self):
     a = Argument('foo', default=False, optional=True)
     b = Argument('bar', default='')
     c = Context(name='mytask', args=(a, b))
     p = Parser(contexts=(c,))
     r = p.parse_argv(['mytask', '--bar=--foo'])
     assert not r[0].args['foo'].value
     eq_(r[0].args['bar'].value, '--foo')
开发者ID:pmdarrow,项目名称:invoke,代码行数:8,代码来源:parser.py

示例5: task_has_no_help_shows_per_task_help

 def task_has_no_help_shows_per_task_help(self):
     task1 = Context('mytask')
     init = Context(args=[Argument('help', optional=True)])
     parser = Parser(initial=init, contexts=[task1])
     result = parser.parse_argv(['mytask', '--help'])
     assert len(result) == 2
     assert result[0].args.help.value == 'mytask'
     assert 'help' not in result[1].args
开发者ID:offbyone,项目名称:invoke,代码行数:8,代码来源:parser.py

示例6: core_flags_work_normally_when_no_conflict

 def core_flags_work_normally_when_no_conflict(self):
     # Initial parse context with an --echo, plus a no-args task
     initial = Context(args=[self._echo()])
     task1 = Context("mytask")
     parser = Parser(initial=initial, contexts=[task1])
     # Call with --echo in the per-task context, expect the core
     # context got updated (vs an error)
     result = parser.parse_argv(["mytask", "--echo"])
     assert result[0].args.echo.value is True
开发者ID:pyinvoke,项目名称:invoke,代码行数:9,代码来源:parser_parser.py

示例7: task_has_no_h_shortflag_shows_per_task_help

 def task_has_no_h_shortflag_shows_per_task_help(self):
     task1 = Context("mytask")
     arg = Argument(names=("help", "h"), optional=True)
     init = Context(args=[arg])
     parser = Parser(initial=init, contexts=[task1])
     result = parser.parse_argv(["mytask", "-h"])
     assert len(result) == 2
     assert result[0].args.help.value == "mytask"
     assert "help" not in result[1].args
开发者ID:miradam,项目名称:invoke,代码行数:9,代码来源:parser_parser.py

示例8: other_tokens_afterwards_raise_parse_errors

 def other_tokens_afterwards_raise_parse_errors(self):
     # NOTE: this is because of the special-casing where we supply
     # the task name as the value when the flag is literally named
     # "help".
     task1 = Context("mytask")
     init = Context(args=[Argument("help", optional=True)])
     parser = Parser(initial=init, contexts=[task1])
     with raises(ParseError, match=r".*foobar.*"):
         parser.parse_argv(["mytask", "--help", "foobar"])
开发者ID:pyinvoke,项目名称:invoke,代码行数:9,代码来源:parser_parser.py

示例9: task_has_no_h_shortflag_shows_per_task_help

 def task_has_no_h_shortflag_shows_per_task_help(self):
     task1 = Context('mytask')
     arg = Argument(names=('help', 'h'), optional=True)
     init = Context(args=[arg])
     parser = Parser(initial=init, contexts=[task1])
     result = parser.parse_argv(['mytask', '-h'])
     eq_(len(result), 2)
     eq_(result[0].args.help.value, 'mytask')
     ok_('help' not in result[1].args)
开发者ID:jr-minnaar,项目名称:invoke,代码行数:9,代码来源:parser.py

示例10: when_conflict_per_task_args_win_out

 def when_conflict_per_task_args_win_out(self):
     # Initial parse context with an --echo, plus task w/ same
     initial = Context(args=[self._echo()])
     task1 = Context("mytask", args=[self._echo()])
     parser = Parser(initial=initial, contexts=[task1])
     # Call with --echo in the per-task context, expect the task
     # context got updated, and not core.
     result = parser.parse_argv(["mytask", "--echo"])
     assert result[0].args.echo.value is False
     assert result[1].args.echo.value is True
开发者ID:pyinvoke,项目名称:invoke,代码行数:10,代码来源:parser_parser.py

示例11: _parse

def _parse(argstr, parser=None, collection=None):
    # TODO: this will clearly turn into the actual main cli stub sometime.
    # TODO: Replace with actual objects at that time.
    # Set up a parser
    if parser is None:
        parser = Parser()
    # Naive string-to-argv: split on whitespace.
    # It's probably safe to assume most tests won't be using spaces in flag
    # values and stuff (e.g. "invoke --foo='biz baz'")
    argv = argstr.split()
    return parser.parse_argv(argv)
开发者ID:msabramo,项目名称:invoke,代码行数:11,代码来源:cli.py

示例12: setup

        class parsing_errors:
            def setup(self):
                self.p = Parser([Context(name='foo', args=[Argument('bar')])])

            @raises(ParseError)
            def missing_flag_values_raise_ParseError(self):
                self.p.parse_argv(['foo', '--bar'])

            def attaches_context_to_ParseErrors(self):
                try:
                    self.p.parse_argv(['foo', '--bar'])
                except ParseError, e:
                    assert e.context is not None
开发者ID:alex,项目名称:invoke,代码行数:13,代码来源:parser.py

示例13: clones_noninitial_contexts

 def clones_noninitial_contexts(self):
     a = Argument("foo")
     assert a.value is None
     c = Context(name="mytask", args=(a,))
     p = Parser(contexts=(c,))
     assert p.contexts["mytask"] is c
     r = p.parse_argv(["mytask", "--foo", "val"])
     assert p.contexts["mytask"] is c
     c2 = r[0]
     assert c2 is not c
     a2 = c2.args["foo"]
     assert a2 is not a
     assert a.value is None
     assert a2.value == "val"
开发者ID:pyinvoke,项目名称:invoke,代码行数:14,代码来源:parser_parser.py

示例14: clones_initial_context

 def clones_initial_context(self):
     a = Argument("foo", kind=bool)
     assert a.value is None
     c = Context(args=(a,))
     p = Parser(initial=c)
     assert p.initial is c
     r = p.parse_argv(["--foo"])
     assert p.initial is c
     c2 = r[0]
     assert c2 is not c
     a2 = c2.args["foo"]
     assert a2 is not a
     assert a.value is None
     assert a2.value is True
开发者ID:pyinvoke,项目名称:invoke,代码行数:14,代码来源:parser_parser.py

示例15: core_bool_but_per_task_string

 def core_bool_but_per_task_string(self):
     # Initial parse context with bool --hide, and a task with a
     # regular (string) --hide
     initial = Context(
         args=[Argument("hide", kind=bool, default=False)]
     )
     task1 = Context("mytask", args=[Argument("hide")])
     parser = Parser(initial=initial, contexts=[task1])
     # Expect that, because the task's version wins, we're able to
     # call it with a value. (If there were weird bugs where the
     # core flag informed the parsing, this would fail.)
     result = parser.parse_argv(["mytask", "--hide", "both"])
     assert result[0].args.hide.value is False
     assert result[1].args.hide.value == "both"
开发者ID:pyinvoke,项目名称:invoke,代码行数:14,代码来源:parser_parser.py


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