Ejemplo n.º 1
0
def test_command_usage5():
    cmd = Command('train',
                  options=[
                      Option(name='optimizer', type=str),
                      Option(name='learning-rate', default=0.0001, short='l')
                  ])
    assert cmd.usage() == USAGE_5
Ejemplo n.º 2
0
def test_command_3():
    cmd = Command('predict', options=[Option(name="@AI")])
    assert cmd.parse(["@stubborn-dishwasher", "predict"]) == {
        '@AI': 'stubborn-dishwasher'
    }
    with pytest.raises(VergeMLError):
        cmd.parse(["predict"])
Ejemplo n.º 3
0
def test_command_usage6():
    cmd = Command('train', options=[
        Option(name='a', type=str, default="A"),
        Option(name='b', type=str, default="B"),
        Option(name='c', type=str, default="C"),
    ])
    assert cmd.usage() == USAGE_6
Ejemplo n.º 4
0
def test_command_2():
    cmd = Command('run', options=[Option('<args>', type=list), Option('@AIs', type=list)])
    assert cmd.parse(["run", "tensorboard"]) == {'@AIs': [], '<args>': ["tensorboard"]}
    assert cmd.parse(["@funky-terminator", "run", "tensorboard"]) == \
        {'@AIs': ['funky-terminator'], '<args>': ["tensorboard"]}
    assert cmd.parse(["@funky-terminator", "@touchy-brobot", "run", "tensorboard", "--port=2204"]) == \
                    {'@AIs': ['funky-terminator', 'touchy-brobot'], '<args>': ["tensorboard", "--port=2204"]}
Ejemplo n.º 5
0
def test_command_usage9():
    cmd = Command('predict', options=[
        Option(name='<file>', type='Optional[str]', descr="The file to use when predicting."),
        Option(name='a', type=str, default="A"),
        Option(name='b', type=str, default="B"),
        Option(name='c', type=str, default="C"),
    ])
    assert cmd.usage() == USAGE_9
Ejemplo n.º 6
0
def test_command_usage8():
    cmd = Command('predict', options=[
        Option(name='<file>', type='Optional[str]'),
        Option(name='a', type=str, default="A"),
        Option(name='b', type=str, default="B"),
        Option(name='c', type=str, default="C"),
    ])
    assert cmd.usage() == USAGE_8
Ejemplo n.º 7
0
def test_command_7():
    cmd = Command('help', options=[Option(name='<topic>'),
                                   Option(name="@AI", type='Optional[@]')], free_form=True)
    assert cmd.parse(["@funky-robot", "help", "--option=xyz", "something"]) == \
           ('funky-robot', ["--option=xyz", "something"])

    assert cmd.parse(["help", "--option=xyz", "something"]) == \
           (None, ["--option=xyz", "something"])
Ejemplo n.º 8
0
def test_command_usage11():
    cmd = Command('predict',
                  options=[
                      Option(name='@AIs', type="List[AI]"),
                      Option(name='threshold',
                             default=0.2,
                             descr="Prediction Threshold.")
                  ])
    assert cmd.usage() == USAGE_11
Ejemplo n.º 9
0
def test_command_usage4():
    cmd = Command('predict',
                  options=[
                      Option(name='@AI'),
                      Option(name='threshold',
                             default=0.2,
                             descr="Prediction Threshold.")
                  ])
    assert cmd.usage() == USAGE_4
Ejemplo n.º 10
0
def test_command_5():
    options = [
        Option('threshold', type=float, validate=">0", short='t'),
        Option('id', default=False, type=bool, flag=True, short='i')
    ]
    cmd = Command('predict', options=options)
    assert cmd.parse(["predict", "--threshold=0.2"]) == {'threshold': 0.2, 'id': False}
    assert cmd.parse(["predict", "-t0.2"]) == {'threshold': 0.2, 'id': False}
    assert cmd.parse(["predict", "-t0.2", "--id"]) == {'threshold': 0.2, 'id': True}
    assert cmd.parse(["predict", "-t0.2", "-i"]) == {'threshold': 0.2, 'id': True}
Ejemplo n.º 11
0
def test_command_usage13():
    cmd = Command('predict',
                  long_descr="Make a prediction.",
                  examples="ml @skynet predict",
                  options=[
                      Option(name='@AIs', type="List[AI]"),
                      Option(name='threshold',
                             default=0.2,
                             descr="Prediction Threshold.")
                  ])
    assert cmd.usage() == USAGE_13
Ejemplo n.º 12
0
def test_command_1():
    cmd = Command('train', options=[Option('epochs', 20, int, validate='>=1')])
    assert cmd.parse(["train", "--epochs=14"]) == {'epochs': 14}

    with pytest.raises(VergeMLError):
        cmd.parse(["train", "--epochs=abc"])

    with pytest.raises(VergeMLError):
        cmd.parse(["train", "--epochz=14"])

    with pytest.raises(VergeMLError):
        cmd.parse(["train", "--epochs=-1"])
Ejemplo n.º 13
0
 def decorator(o):
     assert(getattr(o, _CMD_META_KEY, None) is None)
     _name = name or getattr(o, '__name__', None)
     options = list(reversed(Option.discover(o)))
     cmd = Command(_name, 
                   descr=descr, 
                   long_descr=long_descr, 
                   examples=examples, 
                   options=options,
                   free_form=free_form,
                   kind=kind)
     setattr(o, _CMD_META_KEY, cmd)
     return o
Ejemplo n.º 14
0
def test_command_4():
    cmd = Command('predict', options=[Option(name="@AI", type="Optional[AI]")])
    assert cmd.parse(["@stubborn-dishwasher", "predict"]) == {
        '@AI': 'stubborn-dishwasher'
    }
    assert cmd.parse(["predict"]) == {'@AI': None}
Ejemplo n.º 15
0
def test_command_usage1():
    cmd = Command('new', options=[Option(name='<project-name>')])
    assert cmd.usage() == USAGE_1
Ejemplo n.º 16
0
def test_command_6():
    cmd = Command('new', options=[Option(name='<project-name>', type='str')])
    assert cmd.parse(["new", "xxx"]) == {'<project-name>': "xxx"}
    with pytest.raises(VergeMLError):
        cmd.parse(["new"])
Ejemplo n.º 17
0
def test_command_usage2():
    cmd = Command('train',
                  options=[Option(name='learning-rate', default=0.0001)])
    assert cmd.usage() == USAGE_2