# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import Integer [as 别名]
def test_cluster_options_client_config(monkeypatch):
monkeypatch.setenv("TEST_OPTION_TWO", "large")
config = Config()
config.InProcessBackend.cluster_config_class = MyClusterConfig
config.InProcessBackend.cluster_options = options.Options(
options.Integer("option_one", default=1, min=1, max=4, target="option_one_b"),
options.Select("option_two", options=[("small", 1.5), ("large", 15)]),
)
async with temp_gateway(config=config) as g:
async with g.gateway_client() as gateway:
with dask.config.set(gateway__cluster__options={"option_one": 2}):
# Local config can override
opts = await gateway.cluster_options()
assert opts.option_one == 2
assert opts.option_two == "small"
# Without local config, uses server-side defaults
opts = await gateway.cluster_options(use_local_defaults=False)
assert opts.option_one == 1
assert opts.option_two == "small"
with dask.config.set(
gateway__cluster__options={"option_two": "{TEST_OPTION_TWO}"}
):
# Values can format from environment variables
opts = await gateway.cluster_options()
assert opts.option_one == 1
assert opts.option_two == "large"
with dask.config.set(
gateway__cluster__options={
"option_two": "{TEST_OPTION_TWO}",
"option_one": 3,
}
):
# Defaults are merged with kwargs to new_cluster
async with gateway.new_cluster(option_one=2) as cluster:
report = await gateway.get_cluster(cluster.name)
assert report.options == {"option_one": 2, "option_two": "large"}
# If passing `cluster_options`, defaults are assumed already applied
opts = await gateway.cluster_options()
opts.option_two = "small"
async with gateway.new_cluster(opts) as cluster:
report = await gateway.get_cluster(cluster.name)
assert report.options == {"option_one": 3, "option_two": "small"}