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')
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')
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'])
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')
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})
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"})
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})
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'})
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})
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")
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(), "")
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'})
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(), '')
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"])
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')
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(), '')
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")
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'])
'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,
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! """
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)
'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