Esempio n. 1
0
def client_opts():
    return client_options.Options(
        client_options.Integer("worker_cores",
                               1,
                               min=1,
                               max=4,
                               label="Worker Cores"),
        client_options.Float("worker_memory",
                             1,
                             min=1,
                             max=8,
                             label="Worker Memory (GB)"),
        client_options.Integer("scheduler_cores", 1, label="Scheduler Cores"),
        client_options.Float("scheduler_memory",
                             1,
                             label="Scheduler Memory (GB)"),
        client_options.Select("environment",
                              "basic",
                              options=["basic", "ml"],
                              label="Conda Environment"),
        client_options.Bool("keep_logs", False, label="Keep Logs"),
        client_options.String("queue", "default", label="Queue"),
        client_options.Mapping("environ", {"default": "vals"},
                               label="Environment variables"),
    )
Esempio n. 2
0
def test_select():
    field = "field_name"
    default = "banana"
    options = ["apple", "banana", ("orange", 1)]
    target = "target_name"
    label = "Field Name"

    # Default values
    s_opt = server_options.Select(field, options)
    assert s_opt.default == "apple"
    assert s_opt.label == field
    assert s_opt.target == field

    # Specified values propogate
    s_opt = server_options.Select(field,
                                  options,
                                  default=default,
                                  target=target,
                                  label=label)
    assert s_opt.default == default
    assert s_opt.target == target
    assert s_opt.label == label

    def check(opt):
        assert opt.validate("apple") == "apple"
        assert opt.validate("orange") == "orange"

        with pytest.raises(TypeError):
            opt.validate(1)
        with pytest.raises(ValueError):
            opt.validate("grape")

    # Server-side validation
    check(s_opt)

    # Bad server-side constructors
    with pytest.raises(TypeError):
        server_options.Select(field, 1)

    with pytest.raises(TypeError):
        server_options.Select(field, [1, 2, 3])

    with pytest.raises(ValueError):
        server_options.Select(field, [])

    # Serialization works
    spec = s_opt.json_spec()

    c_opt = client_options.Field._from_spec(spec)

    assert isinstance(c_opt, client_options.Select)
    assert c_opt.value == default
    assert c_opt.options == ("apple", "banana", "orange")
    assert c_opt.label == label

    # Client-side validation
    check(c_opt)

    # Bad client-side constructors
    with pytest.raises(TypeError):
        client_options.Select(field, default, options=1)

    with pytest.raises(TypeError):
        client_options.Select(field, default, options=[1, 2, 3])

    with pytest.raises(ValueError):
        client_options.Select(field, default, options=[])