本文整理汇总了Python中gnome.multi_model_broadcast.ModelBroadcaster类的典型用法代码示例。如果您正苦于以下问题:Python ModelBroadcaster类的具体用法?Python ModelBroadcaster怎么用?Python ModelBroadcaster使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ModelBroadcaster类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_timeout
def test_timeout(secs, timeout, expected_runtime, valid_func):
model = make_model()
model_broadcaster = ModelBroadcaster(model,
('down', 'normal', 'up'),
('down', 'normal', 'up'))
try:
print '\nsleeping for {} secs...'.format(secs)
if timeout is None:
begin = time.time()
res = model_broadcaster.cmd('sleep', {'secs': secs})
end = time.time()
else:
begin = time.time()
res = model_broadcaster.cmd('sleep', {'secs': secs},
timeout=timeout)
end = time.time()
rt = end - begin
# runtime duraton should be either:
# - the expected response time plus a bit of overhead
# - the expected timeout plus a bit of overhead
print 'runtime: ', rt
assert rt >= expected_runtime
assert rt < expected_runtime + (expected_runtime * 0.06)
assert valid_func(res)
finally:
model_broadcaster.stop()
示例2: test_uncertainty_array_size
def test_uncertainty_array_size():
model = make_model()
model_broadcaster = ModelBroadcaster(model,
('down',),
('down',))
try:
assert len(model_broadcaster.tasks) == 1
finally:
model_broadcaster.stop()
model_broadcaster = ModelBroadcaster(model,
('down', 'up'),
('down', 'up'))
try:
assert len(model_broadcaster.tasks) == 4
finally:
model_broadcaster.stop()
model_broadcaster = ModelBroadcaster(model,
('down', 'normal', 'up'),
('down', 'normal', 'up'))
try:
assert len(model_broadcaster.tasks) == 9
finally:
model_broadcaster.stop()
示例3: test_timeout_2_times
def test_timeout_2_times():
model = make_model()
model_broadcaster = ModelBroadcaster(model,
('down', 'normal', 'up'),
('down', 'normal', 'up'))
try:
#
# First, we set a short timeout for a command, but a shorter command.
# The command should succeed
#
secs, timeout, expected_runtime = 4, 5, 4
print '\nsleeping for {} secs...'.format(secs)
begin = time.time()
res = model_broadcaster.cmd('sleep', {'secs': secs}, timeout=timeout)
end = time.time()
rt = end - begin
assert rt >= expected_runtime
assert rt < expected_runtime + (expected_runtime * 0.06)
assert is_valid(res)
#
# Next, run a command with no timeout specified. The timeout should
# have reverted back to the default, and the command should succeed.
#
secs, expected_runtime = 9, 9
print '\nsleeping for {} secs...'.format(secs)
begin = time.time()
res = model_broadcaster.cmd('sleep', {'secs': secs})
end = time.time()
rt = end - begin
assert rt >= expected_runtime
assert rt < expected_runtime + (expected_runtime * 0.06)
assert is_valid(res)
finally:
model_broadcaster.stop()
示例4: test_init
def test_init():
model = make_model()
with pytest.raises(TypeError):
# no uncertainty arguments
ModelBroadcaster(model)
with pytest.raises(TypeError):
# no spill amount uncertainties
ModelBroadcaster(model,
('down', 'normal', 'up'))
model_broadcaster = ModelBroadcaster(model,
('down', 'normal', 'up'),
('down', 'normal', 'up'))
try:
assert hasattr(model_broadcaster, 'id')
finally:
model_broadcaster.stop()
示例5: test_weathering_output_only
def test_weathering_output_only():
model = make_model(geojson_output=True)
model_broadcaster = ModelBroadcaster(model,
('down', 'normal', 'up'),
('down', 'normal', 'up'))
print '\nOutputter results:'
res = model_broadcaster.cmd('get_outputters', {})
assert not [o for r in res for o in r
if not isinstance(o, WeatheringOutput)]
print '\nStep results:'
res = model_broadcaster.cmd('step', {})
assert len(res) == 9
# added a 'valid' flag to output
assert [r.keys() for r in res
if len(r.keys()) == 2
and 'WeatheringOutput' in r]
model_broadcaster.stop()
示例6: test_uncertainty_array_indexing
def test_uncertainty_array_indexing():
model = make_model()
model_broadcaster = ModelBroadcaster(model,
('down', 'normal', 'up'),
('down', 'normal', 'up'))
try:
res = model_broadcaster.cmd('get_wind_timeseries', {},
('down', 'down'))
assert np.allclose([r[0] for r in res], 17.449237)
res = model_broadcaster.cmd('get_spill_amounts', {}, ('down', 'down'))
assert np.isclose(res[0], 333.33333)
res = model_broadcaster.cmd('get_wind_timeseries', {}, ('up', 'up'))
assert np.allclose([r[0] for r in res], 20.166224)
res = model_broadcaster.cmd('get_spill_amounts', {}, ('up', 'up'))
assert np.isclose(res[0], 1666.66666)
finally:
model_broadcaster.stop()
示例7: Burn
Burn(),
Skimmer()]
print 'adding outputters'
model.outputters += WeatheringOutput()
return model
if __name__ == '__main__':
scripting.make_images_dir()
model = make_model()
model_broadcaster = ModelBroadcaster(model,
('down', 'normal', 'up'),
('down', 'normal', 'up'))
print '\nStep results:'
pp.pprint(model_broadcaster.cmd('step', {}))
print '\nGetting wind timeseries for all models:'
pp.pprint(model_broadcaster.cmd('get_wind_timeseries', {}))
print '\nGetting spill amounts for all models:'
pp.pprint(model_broadcaster.cmd('get_spill_amounts', {}))
print '\nGetting time & spill values for just the (down, down) model:'
pp.pprint((model_broadcaster.cmd('get_wind_timeseries', {},
('down', 'down')),
model_broadcaster.cmd('get_spill_amounts', {},