本文整理汇总了Python中traitlets.Integer方法的典型用法代码示例。如果您正苦于以下问题:Python traitlets.Integer方法的具体用法?Python traitlets.Integer怎么用?Python traitlets.Integer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类traitlets
的用法示例。
在下文中一共展示了traitlets.Integer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_cluster_options
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import Integer [as 别名]
def test_cluster_options():
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:
# Create with no parameters
async with gateway.new_cluster() as cluster:
report = await gateway.get_cluster(cluster.name)
assert report.options == {"option_one": 1, "option_two": "small"}
# Create with parameters
async with gateway.new_cluster(option_two="large") as cluster:
report = await gateway.get_cluster(cluster.name)
assert report.options == {"option_one": 1, "option_two": "large"}
# With options object
opts = await gateway.cluster_options()
opts.option_one = 2
async with gateway.new_cluster(opts, option_two="large") as cluster:
report = await gateway.get_cluster(cluster.name)
assert report.options == {"option_one": 2, "option_two": "large"}
# Bad parameters
with pytest.raises(TypeError):
await gateway.new_cluster(cluster_options=10)
with pytest.raises(ValueError) as exc:
await gateway.new_cluster(option_two="medium")
assert "option_two" in str(exc.value)
示例2: test_cluster_options_client_config
# 需要导入模块: 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"}