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


Python Context.add_arg方法代码示例

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


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

示例1: parses_sys_argv_style_list_of_strings

# 需要导入模块: from invoke.parser import Context [as 别名]
# 或者: from invoke.parser.Context import add_arg [as 别名]
 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,代码行数:9,代码来源:parser_parser.py

示例2: setup

# 需要导入模块: from invoke.parser import Context [as 别名]
# 或者: from invoke.parser.Context import add_arg [as 别名]
    class add_arg:
        def setup(self):
            self.c = Context()

        def can_take_Argument_instance(self):
            a = Argument(names=('foo',))
            self.c.add_arg(a)
            assert self.c.args['foo'] is a

        def can_take_name_arg(self):
            self.c.add_arg('foo')
            assert 'foo' in self.c.args

        def can_take_kwargs_for_single_Argument(self):
            self.c.add_arg(names=('foo', 'bar'))
            assert 'foo' in self.c.args and 'bar' in self.c.args

        def raises_ValueError_on_duplicate(self):
            self.c.add_arg(names=('foo', 'bar'))
            with raises(ValueError):
                self.c.add_arg(name='bar')

        def adds_flaglike_name_to_dot_flags(self):
            "adds flaglike name to .flags"
            self.c.add_arg('foo')
            assert '--foo' in self.c.flags

        def adds_all_names_to_dot_flags(self):
            "adds all names to .flags"
            self.c.add_arg(names=('foo', 'bar'))
            assert '--foo' in self.c.flags
            assert '--bar' in self.c.flags

        def adds_true_bools_to_inverse_flags(self):
            self.c.add_arg(name='myflag', default=True, kind=bool)
            assert '--myflag' in self.c.flags
            assert '--no-myflag' in self.c.inverse_flags
            assert self.c.inverse_flags['--no-myflag'] == '--myflag'

        def inverse_flags_works_right_with_task_driven_underscored_names(self):
            # Use a Task here instead of creating a raw argument, we're partly
            # testing Task.get_arguments()' transform of underscored names
            # here. Yes that makes this an integration test, but it's nice to
            # test it here at this level & not just in cli tests.
            @task
            def mytask(c, underscored_option=True):
                pass
            self.c.add_arg(mytask.get_arguments()[0])
            flags = self.c.inverse_flags['--no-underscored-option']
            assert flags == '--underscored-option'

        def turns_single_character_names_into_short_flags(self):
            self.c.add_arg('f')
            assert '-f' in self.c.flags
            assert '--f' not in self.c.flags

        def adds_positional_args_to_positional_args(self):
            self.c.add_arg(name='pos', positional=True)
            assert self.c.positional_args[0].name == 'pos'

        def positional_args_empty_when_none_given(self):
            assert len(self.c.positional_args) == 0

        def positional_args_filled_in_order(self):
            self.c.add_arg(name='pos1', positional=True)
            assert self.c.positional_args[0].name == 'pos1'
            self.c.add_arg(name='abc', positional=True)
            assert self.c.positional_args[1].name == 'abc'

        def positional_arg_modifications_affect_args_copy(self):
            self.c.add_arg(name='hrm', positional=True)
            assert self.c.args['hrm'].value == self.c.positional_args[0].value
            self.c.positional_args[0].value = 17
            assert self.c.args['hrm'].value == self.c.positional_args[0].value
开发者ID:offbyone,项目名称:invoke,代码行数:76,代码来源:context.py

示例3: setup

# 需要导入模块: from invoke.parser import Context [as 别名]
# 或者: from invoke.parser.Context import add_arg [as 别名]
    class add_arg:
        def setup(self):
            self.c = Context()

        def can_take_Argument_instance(self):
            a = Argument(names=('foo',))
            self.c.add_arg(a)
            assert self.c.args['foo'] is a

        def can_take_name_arg(self):
            self.c.add_arg('foo')
            assert 'foo' in self.c.args

        def can_take_kwargs_for_single_Argument(self):
            self.c.add_arg(names=('foo', 'bar'))
            assert 'foo' in self.c.args and 'bar' in self.c.args

        @raises(ValueError)
        def raises_ValueError_on_duplicate(self):
            self.c.add_arg(names=('foo', 'bar'))
            self.c.add_arg(name='bar')

        def adds_flaglike_name_to_dot_flags(self):
            "adds flaglike name to .flags"
            self.c.add_arg('foo')
            assert '--foo' in self.c.flags

        def adds_all_names_to_dot_flags(self):
            "adds all names to .flags"
            self.c.add_arg(names=('foo', 'bar'))
            assert '--foo' in self.c.flags
            assert '--bar' in self.c.flags

        def turns_single_character_names_into_short_flags(self):
            self.c.add_arg('f')
            assert '-f' in self.c.flags
            assert '--f' not in self.c.flags

        def adds_positional_args_to_positional_args(self):
            self.c.add_arg(name='pos', positional=True)
            eq_(self.c.positional_args[0].name, 'pos')

        def positional_args_empty_when_none_given(self):
            eq_(len(self.c.positional_args), 0)

        def positional_args_filled_in_order(self):
            self.c.add_arg(name='pos1', positional=True)
            eq_(self.c.positional_args[0].name, 'pos1')
            self.c.add_arg(name='abc', positional=True)
            eq_(self.c.positional_args[1].name, 'abc')

        def positional_arg_modifications_affect_args_copy(self):
            self.c.add_arg(name='hrm', positional=True)
            eq_(self.c.args['hrm'].value, self.c.positional_args[0].value)
            self.c.positional_args[0].value = 17
            eq_(self.c.args['hrm'].value, self.c.positional_args[0].value)
开发者ID:alex,项目名称:invoke,代码行数:58,代码来源:context.py

示例4: returns_True_if_flag_is_valid_arg

# 需要导入模块: from invoke.parser import Context [as 别名]
# 或者: from invoke.parser.Context import add_arg [as 别名]
 def returns_True_if_flag_is_valid_arg(self):
     c = Context()
     c.add_arg(Argument(names=('foo',)))
     eq_(c.has_arg('foo'), True)
开发者ID:msabramo,项目名称:invoke,代码行数:6,代码来源:context.py

示例5: returns_Argument_for_given_name

# 需要导入模块: from invoke.parser import Context [as 别名]
# 或者: from invoke.parser.Context import add_arg [as 别名]
 def returns_Argument_for_given_name(self):
     c = Context()
     a = Argument(name='foo')
     c.add_arg(a)
     assert c.get_arg('foo') is a
开发者ID:msabramo,项目名称:invoke,代码行数:7,代码来源:context.py

示例6: raises_ValueError_on_duplicate

# 需要导入模块: from invoke.parser import Context [as 别名]
# 或者: from invoke.parser.Context import add_arg [as 别名]
 def raises_ValueError_on_duplicate(self):
     c = Context()
     c.add_arg(names=('foo', 'bar'))
     c.add_arg(name='bar')
开发者ID:msabramo,项目名称:invoke,代码行数:6,代码来源:context.py

示例7: can_take_kwargs

# 需要导入模块: from invoke.parser import Context [as 别名]
# 或者: from invoke.parser.Context import add_arg [as 别名]
 def can_take_kwargs(self):
     c = Context()
     c.add_arg(names=('foo', 'bar'))
     assert c.has_arg('foo') and c.has_arg('bar')
开发者ID:msabramo,项目名称:invoke,代码行数:6,代码来源:context.py

示例8: can_take_name_arg

# 需要导入模块: from invoke.parser import Context [as 别名]
# 或者: from invoke.parser.Context import add_arg [as 别名]
 def can_take_name_arg(self):
     c = Context()
     c.add_arg('foo')
     assert c.has_arg('foo')
开发者ID:msabramo,项目名称:invoke,代码行数:6,代码来源:context.py

示例9: can_take_Argument_instance

# 需要导入模块: from invoke.parser import Context [as 别名]
# 或者: from invoke.parser.Context import add_arg [as 别名]
 def can_take_Argument_instance(self):
     c = Context()
     a = Argument(names=('foo',))
     c.add_arg(a)
     assert c.get_arg('foo') is a
开发者ID:msabramo,项目名称:invoke,代码行数:7,代码来源:context.py

示例10: setup

# 需要导入模块: from invoke.parser import Context [as 别名]
# 或者: from invoke.parser.Context import add_arg [as 别名]
    class add_arg:
        def setup(self):
            self.c = Context()

        def can_take_Argument_instance(self):
            a = Argument(names=('foo',))
            self.c.add_arg(a)
            assert self.c.args['foo'] is a

        def can_take_name_arg(self):
            self.c.add_arg('foo')
            assert 'foo' in self.c.args

        def can_take_kwargs(self):
            self.c.add_arg(names=('foo', 'bar'))
            assert 'foo' in self.c.args and 'bar' in self.c.args

        @raises(ValueError)
        def raises_ValueError_on_duplicate(self):
            self.c.add_arg(names=('foo', 'bar'))
            self.c.add_arg(name='bar')

        def adds_flaglike_name_to_dot_flags(self):
            "adds flaglike name to .flags"
            self.c.add_arg('foo')
            assert '--foo' in self.c.flags

        def adds_all_names_to_dot_flags(self):
            "adds all names to .flags"
            self.c.add_arg(names=('foo', 'bar'))
            assert '--foo' in self.c.flags
            assert '--bar' in self.c.flags

        def turns_single_character_names_into_short_flags(self):
            self.c.add_arg('f')
            assert '-f' in self.c.flags
            assert '--f' not in self.c.flags
开发者ID:markatto,项目名称:invoke,代码行数:39,代码来源:context.py


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