def test_dynamic_addition(): class Args(Namespace): arg1 = Argument(type=int) arg2 = Argument(type=float) arg3 = Argument(type=str) ns_add(Args, 'arg4', Argument(type=int)) args = Parser(Args).parse(['6', '3.0', 'some text', '2']) assert args.arg1 == 6 assert args.arg2 == 3.0 assert args.arg3 == 'some text' assert args.arg4 == 2
def test_dynamic_addition_in_base(): class Base(Namespace): base1 = Argument(type=int) base2 = Argument(type=str) class Args(Base): derived1 = Argument(type=float) derived2 = Argument(type=int) ns_add(Base, 'base3', Argument(type=int)) args = Parser(Args).parse(['6', 'some text', '1', '2.5', '7']) assert args.base1 == 6 assert args.base2 == 'some text' assert args.base3 == 1 assert args.derived1 == 2.5 assert args.derived2 == 7
class Args(Namespace): arg = Argument(type=int, choices=[2, 3, 5])
class Args(Namespace): arg = Argument(type=int)
class Args(Namespace): req1 = Argument(type=int) opt2 = Argument(type=int, nargs='?') req3 = Argument(type=int)
class Base(Namespace): arg1 = Argument(type=int) arg2 = Argument(type=float) arg3 = Argument(type=str)
class Args(Derived1, Derived2): arg4 = Argument(type=int)
class Derived2(Base): arg3 = Argument(type=str)
class Cmd2_2(Namespace): arg1 = Argument(type=int) arg2 = Argument(type=int)
class Cmd1_1(Namespace): arg1 = Argument(type=str)
class AddCmd(Namespace): name = Argument(type=str) surname = Argument(type=str) age = Argument(type=int)
class DeleteCmd(Namespace): id = Argument(type=int)
class Args(Base): derived1 = Argument(type=float) derived2 = Argument(type=int)
class Base(Namespace): base1 = Argument(type=int) base2 = Argument(type=str) base3 = Argument(type=int)
class Args(Namespace): arg = Argument(type=int, nargs='?', default=5) arg2 = Argument(type=int, nargs='*', default=[6, 7])
class Base(Namespace): arg1 = Argument(type=int)
class Derived1(Base): arg2 = Argument(type=float)