コード例 #1
0
ファイル: test_legacy.py プロジェクト: Rosuav/clize
 def test_moreargs(self):
     @clize(
         extra=(
             make_flag(
                 source='extra',
                 names=('extra', 'e'),
                 type=str,
                 takes_argument=3
                 ),
             )
         )
     def fn(arg1, arg2, **kwargs):
         return arg1, arg2, kwargs
     arg1, arg2, kwargs = fn(
         'test', 'arg1', '--extra', 'extra1', 'extra2', 'extra3', 'arg2')
     self.assertEqual(arg1, 'arg1')
     self.assertEqual(arg2, 'arg2')
     self.assertEqual(kwargs, {'extra': 'extra1 extra2 extra3'})
     arg1, arg2, kwargs = fn(
         'test', 'arg1', '-e', 'extra1', 'extra2', 'extra3', 'arg2')
     self.assertEqual(arg1, 'arg1')
     self.assertEqual(arg2, 'arg2')
     self.assertEqual(kwargs, {'extra': 'extra1 extra2 extra3'})
     arg1, arg2, kwargs = fn('test', 'arg1', '--extra=extra', 'arg2')
     self.assertEqual(arg1, 'arg1')
     self.assertEqual(arg2, 'arg2')
     self.assertEqual(kwargs, {'extra': 'extra'})
     arg1, arg2, kwargs = fn('test', 'arg1', '-eextra', 'arg2')
     self.assertEqual(arg1, 'arg1')
     self.assertEqual(arg2, 'arg2')
     self.assertEqual(kwargs, {'extra': 'extra'})
     self.assertRaises(errors.NotEnoughValues,
                       fn, 'test', 'arg1', 'arg2', '--extra', 'extra')
コード例 #2
0
ファイル: test_legacy.py プロジェクト: Rosuav/clize
 def test_intopt_moreargs(self):
     @clize(
         extra=(
             make_flag(
                 source='extra',
                 names=('extra', 'e'),
                 type=int,
                 takes_argument=2
                 ),
             )
         )
     def fn(arg1, arg2, **kwargs):
         return arg1, arg2, kwargs
     arg1, arg2, kwargs = fn('test', 'arg1', '-e42', 'arg2')
     self.assertEqual(arg1, 'arg1')
     self.assertEqual(arg2, 'arg2')
     self.assertEqual(kwargs, {'extra': 42})
     arg1, arg2, kwargs = fn('test', 'arg1', '--extra=42', 'arg2')
     self.assertEqual(arg1, 'arg1')
     self.assertEqual(arg2, 'arg2')
     self.assertEqual(kwargs, {'extra': 42})
     self.assertRaises(errors.BadArgumentFormat,
                       fn, 'test', '-e', 'extra1', 'extra2')
     self.assertRaises(errors.BadArgumentFormat,
                       fn, 'test', '--extra', 'extra1', 'extra2')
コード例 #3
0
ファイル: test_legacy.py プロジェクト: Rosuav/clize
    def test_keepgoing(self):
        def extra(name, command, val, params):
            if check_xyz:
                self.assertEqual(params['xyz'], 'xyz')
            else:
                self.assertFalse('xyz' in params)
            params['added'] = 'added'

        @clize(
            extra=(
                    make_flag(
                        source=extra,
                        names=('extra',),
                    ),
                )
            )
        def fn(arg1, arg2, added='', xyz=''):
            self.assertEqual(arg1, 'arg1')
            self.assertEqual(arg2, 'arg2')
            self.assertEqual(xyz, 'xyz')
            self.assertEqual(added, 'added')
        check_xyz = True
        self.run_cli(fn, ['test', 'arg1', '--xyz', 'xyz', 'arg2', '--extra'])
        check_xyz = False
        ret, out, err = self.run_cli(
            fn, ['test', 'arg1', '--extra', 'arg2', '--xyz', 'xyz'])
コード例 #4
0
ファイル: test_legacy.py プロジェクト: mgielda/clize
    def test_moreargs(self):
        @clize(extra=(make_flag(source='extra',
                                names=('extra', 'e'),
                                type=str,
                                takes_argument=3), ))
        def fn(arg1, arg2, **kwargs):
            return arg1, arg2, kwargs

        arg1, arg2, kwargs = fn('test', 'arg1', '--extra', 'extra1', 'extra2',
                                'extra3', 'arg2')
        self.assertEqual(arg1, 'arg1')
        self.assertEqual(arg2, 'arg2')
        self.assertEqual(kwargs, {'extra': 'extra1 extra2 extra3'})
        arg1, arg2, kwargs = fn('test', 'arg1', '-e', 'extra1', 'extra2',
                                'extra3', 'arg2')
        self.assertEqual(arg1, 'arg1')
        self.assertEqual(arg2, 'arg2')
        self.assertEqual(kwargs, {'extra': 'extra1 extra2 extra3'})
        arg1, arg2, kwargs = fn('test', 'arg1', '--extra=extra', 'arg2')
        self.assertEqual(arg1, 'arg1')
        self.assertEqual(arg2, 'arg2')
        self.assertEqual(kwargs, {'extra': 'extra'})
        arg1, arg2, kwargs = fn('test', 'arg1', '-eextra', 'arg2')
        self.assertEqual(arg1, 'arg1')
        self.assertEqual(arg2, 'arg2')
        self.assertEqual(kwargs, {'extra': 'extra'})
        self.assertRaises(errors.NotEnoughValues, fn, 'test', 'arg1', 'arg2',
                          '--extra', 'extra')
コード例 #5
0
ファイル: test_legacy.py プロジェクト: mgielda/clize
    def test_flag(self):
        @clize(extra=(make_flag(source='extra', names=('extra', )), ))
        def fn(arg1, arg2, **kwargs):
            return arg1, arg2, kwargs

        arg1, arg2, kwargs = fn('test', 'arg1', '--extra', 'arg2')
        self.assertEqual(arg1, 'arg1')
        self.assertEqual(arg2, 'arg2')
        self.assertEqual(kwargs, {'extra': True})
コード例 #6
0
ファイル: test_legacy.py プロジェクト: Shir0kamii/clize
    def test_opt(self):
        @clize(extra=(make_flag(source="extra", names=("extra",), type=str, takes_argument=1),))
        def fn(arg1, arg2, **kwargs):
            return arg1, arg2, kwargs

        arg1, arg2, kwargs = fn("test", "arg1", "--extra", "extra", "arg2")
        self.assertEqual(arg1, "arg1")
        self.assertEqual(arg2, "arg2")
        self.assertEqual(kwargs, {"extra": "extra"})
コード例 #7
0
ファイル: test_legacy.py プロジェクト: Shir0kamii/clize
    def test_flag(self):
        @clize(extra=(make_flag(source="extra", names=("extra",)),))
        def fn(arg1, arg2, **kwargs):
            return arg1, arg2, kwargs

        arg1, arg2, kwargs = fn("test", "arg1", "--extra", "arg2")
        self.assertEqual(arg1, "arg1")
        self.assertEqual(arg2, "arg2")
        self.assertEqual(kwargs, {"extra": True})
コード例 #8
0
ファイル: test_legacy.py プロジェクト: mgielda/clize
    def test_opt(self):
        @clize(extra=(make_flag(source='extra',
                                names=('extra', ),
                                type=str,
                                takes_argument=1), ))
        def fn(arg1, arg2, **kwargs):
            return arg1, arg2, kwargs

        arg1, arg2, kwargs = fn('test', 'arg1', '--extra', 'extra', 'arg2')
        self.assertEqual(arg1, 'arg1')
        self.assertEqual(arg2, 'arg2')
        self.assertEqual(kwargs, {'extra': 'extra'})
コード例 #9
0
ファイル: test_legacy.py プロジェクト: Rosuav/clize
 def test_flag(self):
     @clize(
         extra=(
             make_flag(
                 source='extra',
                 names=('extra',)
                 ),
             )
         )
     def fn(arg1, arg2, **kwargs):
         return arg1, arg2, kwargs
     arg1, arg2, kwargs = fn('test', 'arg1', '--extra', 'arg2')
     self.assertEqual(arg1, 'arg1')
     self.assertEqual(arg2, 'arg2')
     self.assertEqual(kwargs, {'extra': True})
コード例 #10
0
ファイル: test_legacy.py プロジェクト: Shir0kamii/clize
    def test_intopt_moreargs(self):
        @clize(extra=(make_flag(source="extra", names=("extra", "e"), type=int, takes_argument=2),))
        def fn(arg1, arg2, **kwargs):
            return arg1, arg2, kwargs

        arg1, arg2, kwargs = fn("test", "arg1", "-e42", "arg2")
        self.assertEqual(arg1, "arg1")
        self.assertEqual(arg2, "arg2")
        self.assertEqual(kwargs, {"extra": 42})
        arg1, arg2, kwargs = fn("test", "arg1", "--extra=42", "arg2")
        self.assertEqual(arg1, "arg1")
        self.assertEqual(arg2, "arg2")
        self.assertEqual(kwargs, {"extra": 42})
        self.assertRaises(errors.BadArgumentFormat, fn, "test", "-e", "extra1", "extra2")
        self.assertRaises(errors.BadArgumentFormat, fn, "test", "--extra", "extra1", "extra2")
コード例 #11
0
ファイル: test_legacy.py プロジェクト: Shir0kamii/clize
    def test_version(self):
        def show_version(name, **kwargs):
            print("this is the version")
            return True

        @clize(extra=(make_flag(source=show_version, names=("version", "v"), help="Show the version"),))
        def fn():
            raise NotImplementedError

        ret, out, err = self.run_cli(fn, ["test", "--version"])
        self.assertEqual(out.getvalue(), "this is the version\n")
        self.assertEqual(err.getvalue(), "")
        ret, out, err = self.run_cli(fn, ["test", "-v"])
        self.assertEqual(out.getvalue(), "this is the version\n")
        self.assertEqual(err.getvalue(), "")
コード例 #12
0
ファイル: test_legacy.py プロジェクト: Rosuav/clize
 def test_opt(self):
     @clize(
         extra=(
             make_flag(
                 source='extra',
                 names=('extra',),
                 type=str,
                 takes_argument=1
                 ),
             )
         )
     def fn(arg1, arg2, **kwargs):
         return arg1, arg2, kwargs
     arg1, arg2, kwargs = fn('test', 'arg1', '--extra', 'extra', 'arg2')
     self.assertEqual(arg1, 'arg1')
     self.assertEqual(arg2, 'arg2')
     self.assertEqual(kwargs, {'extra': 'extra'})
コード例 #13
0
ファイル: test_legacy.py プロジェクト: mgielda/clize
    def test_version(self):
        def show_version(name, **kwargs):
            print('this is the version')
            return True

        @clize(extra=(make_flag(
            source=show_version,
            names=('version', 'v'),
            help="Show the version",
        ), ))
        def fn():
            raise NotImplementedError

        ret, out, err = self.run_cli(fn, ['test', '--version'])
        self.assertEqual(out.getvalue(), 'this is the version\n')
        self.assertEqual(err.getvalue(), '')
        ret, out, err = self.run_cli(fn, ['test', '-v'])
        self.assertEqual(out.getvalue(), 'this is the version\n')
        self.assertEqual(err.getvalue(), '')
コード例 #14
0
ファイル: test_legacy.py プロジェクト: Shir0kamii/clize
    def test_keepgoing(self):
        def extra(name, command, val, params):
            if check_xyz:
                self.assertEqual(params["xyz"], "xyz")
            else:
                self.assertFalse("xyz" in params)
            params["added"] = "added"

        @clize(extra=(make_flag(source=extra, names=("extra",)),))
        def fn(arg1, arg2, added="", xyz=""):
            self.assertEqual(arg1, "arg1")
            self.assertEqual(arg2, "arg2")
            self.assertEqual(xyz, "xyz")
            self.assertEqual(added, "added")

        check_xyz = True
        self.run_cli(fn, ["test", "arg1", "--xyz", "xyz", "arg2", "--extra"])
        check_xyz = False
        ret, out, err = self.run_cli(fn, ["test", "arg1", "--extra", "arg2", "--xyz", "xyz"])
コード例 #15
0
ファイル: test_legacy.py プロジェクト: mgielda/clize
    def test_intopt_moreargs(self):
        @clize(extra=(make_flag(source='extra',
                                names=('extra', 'e'),
                                type=int,
                                takes_argument=2), ))
        def fn(arg1, arg2, **kwargs):
            return arg1, arg2, kwargs

        arg1, arg2, kwargs = fn('test', 'arg1', '-e42', 'arg2')
        self.assertEqual(arg1, 'arg1')
        self.assertEqual(arg2, 'arg2')
        self.assertEqual(kwargs, {'extra': 42})
        arg1, arg2, kwargs = fn('test', 'arg1', '--extra=42', 'arg2')
        self.assertEqual(arg1, 'arg1')
        self.assertEqual(arg2, 'arg2')
        self.assertEqual(kwargs, {'extra': 42})
        self.assertRaises(errors.BadArgumentFormat, fn, 'test', '-e', 'extra1',
                          'extra2')
        self.assertRaises(errors.BadArgumentFormat, fn, 'test', '--extra',
                          'extra1', 'extra2')
コード例 #16
0
ファイル: test_legacy.py プロジェクト: Rosuav/clize
    def test_version(self):
        def show_version(name, **kwargs):
            print('this is the version')
            return True

        @clize(
            extra=(
                    make_flag(
                        source=show_version,
                        names=('version', 'v'),
                        help="Show the version",
                    ),
                )
            )
        def fn():
            raise NotImplementedError
        ret, out, err = self.run_cli(fn, ['test', '--version'])
        self.assertEqual(out.getvalue(), 'this is the version\n')
        self.assertEqual(err.getvalue(), '')
        ret, out, err = self.run_cli(fn, ['test', '-v'])
        self.assertEqual(out.getvalue(), 'this is the version\n')
        self.assertEqual(err.getvalue(), '')
コード例 #17
0
ファイル: test_legacy.py プロジェクト: Shir0kamii/clize
    def test_moreargs(self):
        @clize(extra=(make_flag(source="extra", names=("extra", "e"), type=str, takes_argument=3),))
        def fn(arg1, arg2, **kwargs):
            return arg1, arg2, kwargs

        arg1, arg2, kwargs = fn("test", "arg1", "--extra", "extra1", "extra2", "extra3", "arg2")
        self.assertEqual(arg1, "arg1")
        self.assertEqual(arg2, "arg2")
        self.assertEqual(kwargs, {"extra": "extra1 extra2 extra3"})
        arg1, arg2, kwargs = fn("test", "arg1", "-e", "extra1", "extra2", "extra3", "arg2")
        self.assertEqual(arg1, "arg1")
        self.assertEqual(arg2, "arg2")
        self.assertEqual(kwargs, {"extra": "extra1 extra2 extra3"})
        arg1, arg2, kwargs = fn("test", "arg1", "--extra=extra", "arg2")
        self.assertEqual(arg1, "arg1")
        self.assertEqual(arg2, "arg2")
        self.assertEqual(kwargs, {"extra": "extra"})
        arg1, arg2, kwargs = fn("test", "arg1", "-eextra", "arg2")
        self.assertEqual(arg1, "arg1")
        self.assertEqual(arg2, "arg2")
        self.assertEqual(kwargs, {"extra": "extra"})
        self.assertRaises(errors.NotEnoughValues, fn, "test", "arg1", "arg2", "--extra", "extra")
コード例 #18
0
ファイル: test_legacy.py プロジェクト: mgielda/clize
    def test_keepgoing(self):
        def extra(name, command, val, params):
            if check_xyz:
                self.assertEqual(params['xyz'], 'xyz')
            else:
                self.assertFalse('xyz' in params)
            params['added'] = 'added'

        @clize(extra=(make_flag(
            source=extra,
            names=('extra', ),
        ), ))
        def fn(arg1, arg2, added='', xyz=''):
            self.assertEqual(arg1, 'arg1')
            self.assertEqual(arg2, 'arg2')
            self.assertEqual(xyz, 'xyz')
            self.assertEqual(added, 'added')

        check_xyz = True
        self.run_cli(fn, ['test', 'arg1', '--xyz', 'xyz', 'arg2', '--extra'])
        check_xyz = False
        ret, out, err = self.run_cli(
            fn, ['test', 'arg1', '--extra', 'arg2', '--xyz', 'xyz'])
コード例 #19
0
ファイル: org2gantt.py プロジェクト: MichelMina/Wx
    'csv': ('c', ),
    'warning': ('w', ),
    'gantt': ('g', ),
    'svg': ('S', ),
    'resource': ('r', ),
    'availibility': ('a', ),
    'one_line_for_tasks': ('o', ),
    'start_date': ('s', ),
    'end_date': ('e', ),
    'today': ('t', ),
    'filter': ('f', ),
    'scale': ('k', ),
},
             extra=(clize.make_flag(
                 source=__show_version__,
                 names=('version', 'v'),
                 help="Show the version",
             ), ))
def __main__(org,
             csv='',
             gantt='',
             start_date='',
             end_date='',
             today='',
             debug=False,
             resource=False,
             svg='project',
             filter='',
             availibility='',
             warning=False,
             one_line_for_tasks=False,
コード例 #20
0
ファイル: echo.py プロジェクト: cmorgan/clize
from clize import clize, run, make_flag

def show_version(name, **kwargs):
    print("{0} version 1.0".format(os.path.basename(name)))
    return True

@clize(
    require_excess=True,
    alias={
            'reverse': ('r',),
        },
    extra=(
            make_flag(
                source=show_version,
                names=('version', 'v'),
                help="Show the version",
            ),
        )
    )
def echo(reverse=False, *text):
    """
    Echoes text back

    text: The text to be echoed

    reverse: Reverse text before echoing

    Beware! There is no warranty this program will not reverse
    your internets!
    """
コード例 #21
0
from clize import clize, run, make_flag


def show_version(name, **kwargs):
    print("{0} version 1.0".format(os.path.basename(name)))
    return True


@clize(require_excess=True,
       alias={
           'reverse': ('r', ),
       },
       extra=(make_flag(
           source=show_version,
           names=('version', 'v'),
           help="Show the version",
       ), ))
def echo(reverse=False, *text):
    """
    Echoes text back

    text: The text to be echoed

    reverse: Reverse text before echoing

    Beware! There is no warranty this program will not reverse
    your internets!
    """

    text = ' '.join(text)
コード例 #22
0
ファイル: org2gantt.py プロジェクト: MichelMina/Wx
        'warning': ('w',),
        'gantt': ('g',),
        'svg': ('S',),
        'resource': ('r',),
        'availibility': ('a',),
        'one_line_for_tasks': ('o',),
        'start_date': ('s',),
        'end_date': ('e',),
        'today': ('t',),
        'filter': ('f',),
        'scale': ('k',),
        },
    extra = (
        clize.make_flag(
            source=__show_version__,
            names=('version', 'v'),
            help="Show the version",
            ),
        )
    )
def __main__(org, csv='', gantt='', start_date='', end_date='', today='', debug=False, resource=False, svg='project', filter='', availibility='', warning=False, one_line_for_tasks=False, scale='d'):
    """
    org2gantt.py
    
    org: org-mode filename

    gantt: output python-gantt filename (if not specified, code is directly executed)

    svg: svg base name for files output

    resource: generate resources graph