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
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"])
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
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"]}
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
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
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"])
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
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
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}
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
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"])
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
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}
def test_command_usage1(): cmd = Command('new', options=[Option(name='<project-name>')]) assert cmd.usage() == USAGE_1
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"])
def test_command_usage2(): cmd = Command('train', options=[Option(name='learning-rate', default=0.0001)]) assert cmd.usage() == USAGE_2