Beispiel #1
0
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
Beispiel #2
0
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
Beispiel #3
0
 class Args(Namespace):
     arg = Argument(type=int, choices=[2, 3, 5])
Beispiel #4
0
 class Args(Namespace):
     arg = Argument(type=int)
Beispiel #5
0
 class Args(Namespace):
     req1 = Argument(type=int)
     opt2 = Argument(type=int, nargs='?')
     req3 = Argument(type=int)
Beispiel #6
0
 class Base(Namespace):
     arg1 = Argument(type=int)
     arg2 = Argument(type=float)
     arg3 = Argument(type=str)
Beispiel #7
0
 class Args(Derived1, Derived2):
     arg4 = Argument(type=int)
Beispiel #8
0
 class Derived2(Base):
     arg3 = Argument(type=str)
Beispiel #9
0
 class Cmd2_2(Namespace):
     arg1 = Argument(type=int)
     arg2 = Argument(type=int)
Beispiel #10
0
 class Cmd1_1(Namespace):
     arg1 = Argument(type=str)
Beispiel #11
0
 class AddCmd(Namespace):
     name = Argument(type=str)
     surname = Argument(type=str)
     age = Argument(type=int)
Beispiel #12
0
 class DeleteCmd(Namespace):
     id = Argument(type=int)
Beispiel #13
0
 class Args(Base):
     derived1 = Argument(type=float)
     derived2 = Argument(type=int)
Beispiel #14
0
 class Base(Namespace):
     base1 = Argument(type=int)
     base2 = Argument(type=str)
     base3 = Argument(type=int)
Beispiel #15
0
 class Args(Namespace):
     arg = Argument(type=int, nargs='?', default=5)
     arg2 = Argument(type=int, nargs='*', default=[6, 7])
Beispiel #16
0
 class Base(Namespace):
     arg1 = Argument(type=int)
Beispiel #17
0
 class Derived1(Base):
     arg2 = Argument(type=float)