本文整理匯總了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"}