當前位置: 首頁>>代碼示例>>Python>>正文


Python parser.Context類代碼示例

本文整理匯總了Python中invoke.parser.Context的典型用法代碼示例。如果您正苦於以下問題:Python Context類的具體用法?Python Context怎麽用?Python Context使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Context類的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: setup

 def setup(self):
     # Normal, non-task/collection related Context
     self.vanilla = Context(args=(
         Argument('foo'),
         Argument('bar', help="bar the baz")
     ))
     # Task/Collection generated Context
     # (will expose flags n such)
     @task(help={'otherarg': 'other help'}, optional=['optval'])
     def mytask(c, myarg, otherarg, optval, intval=5):
         pass
     col = Collection(mytask)
     self.tasked = col.to_contexts()[0]
開發者ID:offbyone,項目名稱:invoke,代碼行數:13,代碼來源:context.py

示例3: _assert_order

 def _assert_order(self, name_tuples, expected_flag_order):
     ctx = Context(args=[Argument(names=x) for x in name_tuples])
     return eq_(
         ctx.help_tuples(),
         [ctx.help_for(x) for x in expected_flag_order]
     )
開發者ID:B-Rich,項目名稱:invoke,代碼行數:6,代碼來源:context.py

示例4: may_give_arg_list_at_init_time

 def may_give_arg_list_at_init_time(self):
     a1 = Argument('foo')
     a2 = Argument('bar')
     c = Context(name='name', args=(a1, a2))
     assert c.get_arg('foo') is a1
開發者ID:msabramo,項目名稱:invoke,代碼行數:5,代碼來源:context.py

示例5: underscored_args

 def underscored_args(self):
     c = Context(args=(Argument('i_have_underscores', help='yup'),))
     eq_(c.help_for('--i-have-underscores'), ('--i-have-underscores=STRING', 'yup'))
開發者ID:B-Rich,項目名稱:invoke,代碼行數:3,代碼來源:context.py

示例6: _assert_order

 def _assert_order(self, name_tuples, expected_flag_order):
     c = Context(args=[Argument(names=x) for x in name_tuples])
     expected = [c.help_for(x) for x in expected_flag_order]
     assert c.help_tuples() == expected
開發者ID:offbyone,項目名稱:invoke,代碼行數:4,代碼來源:context.py

示例7: returns_Argument_for_given_name

 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,代碼行數:5,代碼來源:context.py

示例8: _assert_order

 def _assert_order(self, name_tuples, expected_flag_order):
     ctx = Context(args=map(lambda x: Argument(names=x), name_tuples))
     return eq_(ctx.help_tuples(), map(ctx.help_for, expected_flag_order))
開發者ID:alex,項目名稱:invoke,代碼行數:3,代碼來源:context.py

示例9: raises_ValueError_on_duplicate

 def raises_ValueError_on_duplicate(self):
     c = Context()
     c.add_arg(names=('foo', 'bar'))
     c.add_arg(name='bar')
開發者ID:msabramo,項目名稱:invoke,代碼行數:4,代碼來源:context.py

示例10: returns_True_if_flag_is_valid_arg

 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,代碼行數:4,代碼來源:context.py

示例11: can_take_kwargs

 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,代碼行數:4,代碼來源:context.py

示例12: can_take_name_arg

 def can_take_name_arg(self):
     c = Context()
     c.add_arg('foo')
     assert c.has_arg('foo')
開發者ID:msabramo,項目名稱:invoke,代碼行數:4,代碼來源:context.py

示例13: can_take_Argument_instance

 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,代碼行數:5,代碼來源:context.py

示例14: underscored_args

 def underscored_args(self):
     c = Context(args=(Argument('i_have_underscores', help='yup'),))
     result = c.help_for('--i-have-underscores')
     assert result == ('--i-have-underscores=STRING', 'yup')
開發者ID:offbyone,項目名稱:invoke,代碼行數:4,代碼來源:context.py

示例15: setup

    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,代碼行數:56,代碼來源:context.py


注:本文中的invoke.parser.Context類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。