コード例 #1
0
ファイル: context.py プロジェクト: tony/invoke
    class help_for:
        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(myarg, otherarg, optval):
                pass

            col = Collection(mytask)
            self.tasked = col.to_contexts()[0]

        @raises(ValueError)
        def raises_ValueError_for_non_flag_values(self):
            self.vanilla.help_for('foo')

        def vanilla_no_helpstr(self):
            eq_(self.vanilla.help_for('--foo'), ("--foo=STRING", ""))

        def vanilla_with_helpstr(self):
            eq_(self.vanilla.help_for('--bar'),
                ("--bar=STRING", "bar the baz"))

        def task_driven_with_helpstr(self):
            eq_(self.tasked.help_for('--otherarg'),
                ("-o STRING, --otherarg=STRING", "other help"))

        # Yes, the next 3 tests are identical in form, but technically they
        # test different behaviors. HERPIN' AN' DERPIN'
        def task_driven_no_helpstr(self):
            eq_(self.tasked.help_for('--myarg'),
                ("-m STRING, --myarg=STRING", ""))

        def short_form_before_long_form(self):
            eq_(self.tasked.help_for('--myarg'),
                ("-m STRING, --myarg=STRING", ""))

        def equals_sign_for_long_form_only(self):
            eq_(self.tasked.help_for('--myarg'),
                ("-m STRING, --myarg=STRING", ""))

        def kind_to_placeholder_map(self):
            # str=STRING, int=INT, etc etc
            skip()

        def shortflag_inputs_work_too(self):
            eq_(self.tasked.help_for('-m'), self.tasked.help_for('--myarg'))

        def optional_values_use_brackets(self):
            eq_(self.tasked.help_for('--optval'),
                ("-p [STRING], --optval[=STRING]", ""))

        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'))
コード例 #2
0
ファイル: context.py プロジェクト: offbyone/invoke
 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')
コード例 #3
0
ファイル: context.py プロジェクト: offbyone/invoke
    class help_for:
        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]

        def raises_ValueError_for_non_flag_values(self):
            with raises(ValueError):
                self.vanilla.help_for('foo')

        def vanilla_no_helpstr(self):
            assert self.vanilla.help_for('--foo') == ("--foo=STRING", "")

        def vanilla_with_helpstr(self):
            result = self.vanilla.help_for('--bar')
            assert result == ("--bar=STRING", "bar the baz")

        def task_driven_with_helpstr(self):
            result = self.tasked.help_for('--otherarg')
            assert result == ("-o STRING, --otherarg=STRING", "other help")

        # Yes, the next 3 tests are identical in form, but technically they
        # test different behaviors. HERPIN' AN' DERPIN'
        def task_driven_no_helpstr(self):
            result = self.tasked.help_for('--myarg')
            assert result == ("-m STRING, --myarg=STRING", "")

        def short_form_before_long_form(self):
            result = self.tasked.help_for('--myarg')
            assert result == ("-m STRING, --myarg=STRING", "")

        def equals_sign_for_long_form_only(self):
            result = self.tasked.help_for('--myarg')
            assert result == ("-m STRING, --myarg=STRING", "")

        def kind_to_placeholder_map(self):
            # Strings
            helpfor = self.tasked.help_for('--myarg')
            assert helpfor == ("-m STRING, --myarg=STRING", "")
            # Ints
            helpfor = self.tasked.help_for('--intval')
            assert helpfor == ("-i INT, --intval=INT", "")
            # TODO: others

        def shortflag_inputs_work_too(self):
            m = self.tasked.help_for('-m')
            myarg = self.tasked.help_for('--myarg')
            assert m == myarg

        def optional_values_use_brackets(self):
            result = self.tasked.help_for('--optval')
            assert result == ("-p [STRING], --optval[=STRING]", "")

        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')

        def true_default_args(self):
            c = Context(args=(Argument('truthy', kind=bool, default=True),))
            assert c.help_for('--truthy') == ('--[no-]truthy', '')
コード例 #4
0
ファイル: context.py プロジェクト: tony/invoke
 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])
コード例 #5
0
ファイル: context.py プロジェクト: tony/invoke
 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'))
コード例 #6
0
ファイル: parser_context.py プロジェクト: miradam/invoke
 def true_default_args(self):
     c = Context(args=(Argument("truthy", kind=bool, default=True),))
     assert c.help_for("--truthy") == ("--[no-]truthy", "")
コード例 #7
0
ファイル: context.py プロジェクト: B-Rich/invoke
 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]
     )
コード例 #8
0
 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
コード例 #9
0
ファイル: context.py プロジェクト: techniq/invoke
    class help_for:
        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'})
            def mytask(myarg, otherarg):
                pass
            col = Collection(mytask)
            self.tasked = col.to_contexts()[0]

        @raises(ValueError)
        def raises_ValueError_for_non_flag_values(self):
            self.vanilla.help_for('foo')

        def vanilla_no_helpstr(self):
            eq_(
                self.vanilla.help_for('--foo'),
                ("--foo=STRING", "")
            )

        def vanilla_with_helpstr(self):
            eq_(
                self.vanilla.help_for('--bar'),
                ("--bar=STRING", "bar the baz")
            )

        def task_driven_with_helpstr(self):
            eq_(
                self.tasked.help_for('--otherarg'),
                ("-o STRING, --otherarg=STRING", "other help")
            )

        # Yes, the next 3 tests are identical in form, but technically they
        # test different behaviors. HERPIN' AN' DERPIN'
        def task_driven_no_helpstr(self):
            eq_(
                self.tasked.help_for('--myarg'),
                ("-m STRING, --myarg=STRING", "")
            )

        def short_form_before_long_form(self):
            eq_(
                self.tasked.help_for('--myarg'),
                ("-m STRING, --myarg=STRING", "")
            )

        def equals_sign_for_long_form_only(self):
            eq_(
                self.tasked.help_for('--myarg'),
                ("-m STRING, --myarg=STRING", "")
            )

        def kind_to_placeholder_map(self):
            # str=STRING, int=INT, etc etc
            skip()

        def shortflag_inputs_work_too(self):
            eq_(self.tasked.help_for('-m'), self.tasked.help_for('--myarg'))
コード例 #10
0
 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")
コード例 #11
0
 def true_default_args(self):
     c = Context(args=(Argument("truthy", kind=bool, default=True), ))
     assert c.help_for("--truthy") == ("--[no-]truthy", "")
コード例 #12
0
    class help_for:
        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]

        def raises_ValueError_for_non_flag_values(self):
            with raises(ValueError):
                self.vanilla.help_for("foo")

        def vanilla_no_helpstr(self):
            assert self.vanilla.help_for("--foo") == ("--foo=STRING", "")

        def vanilla_with_helpstr(self):
            result = self.vanilla.help_for("--bar")
            assert result == ("--bar=STRING", "bar the baz")

        def task_driven_with_helpstr(self):
            result = self.tasked.help_for("--otherarg")
            assert result == ("-o STRING, --otherarg=STRING", "other help")

        # Yes, the next 3 tests are identical in form, but technically they
        # test different behaviors. HERPIN' AN' DERPIN'
        def task_driven_no_helpstr(self):
            result = self.tasked.help_for("--myarg")
            assert result == ("-m STRING, --myarg=STRING", "")

        def short_form_before_long_form(self):
            result = self.tasked.help_for("--myarg")
            assert result == ("-m STRING, --myarg=STRING", "")

        def equals_sign_for_long_form_only(self):
            result = self.tasked.help_for("--myarg")
            assert result == ("-m STRING, --myarg=STRING", "")

        def kind_to_placeholder_map(self):
            # Strings
            helpfor = self.tasked.help_for("--myarg")
            assert helpfor == ("-m STRING, --myarg=STRING", "")
            # Ints
            helpfor = self.tasked.help_for("--intval")
            assert helpfor == ("-i INT, --intval=INT", "")
            # TODO: others

        def shortflag_inputs_work_too(self):
            m = self.tasked.help_for("-m")
            myarg = self.tasked.help_for("--myarg")
            assert m == myarg

        def optional_values_use_brackets(self):
            result = self.tasked.help_for("--optval")
            assert result == ("-p [STRING], --optval[=STRING]", "")

        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")

        def true_default_args(self):
            c = Context(args=(Argument("truthy", kind=bool, default=True), ))
            assert c.help_for("--truthy") == ("--[no-]truthy", "")
コード例 #13
0
 def true_default_args(self):
     c = Context(args=(Argument('truthy', kind=bool, default=True),))
     eq_(c.help_for('--truthy'), ('--[no-]truthy', ''))
コード例 #14
0
ファイル: context.py プロジェクト: vovanz/invoke
 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')
コード例 #15
0
ファイル: context.py プロジェクト: offbyone/invoke
 def true_default_args(self):
     c = Context(args=(Argument('truthy', kind=bool, default=True),))
     assert c.help_for('--truthy') == ('--[no-]truthy', '')
コード例 #16
0
ファイル: context.py プロジェクト: B-Rich/invoke
 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'))
コード例 #17
0
ファイル: context.py プロジェクト: offbyone/invoke
 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
コード例 #18
0
ファイル: parser_context.py プロジェクト: miradam/invoke
 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")