def basic_command_line_config():
"""Returns a basic application config for testing purposes.
The database is in memory.
"""
options = {k.replace("-", "_"): remove_quotes(v)
for k, v in arguments.items()}
return CommandLineConfig(**options)
python类testing()的实例源码
def setUp(self):
self._bind_unused_port_orig = tornado.testing.bind_unused_port
tornado.testing.bind_unused_port = bind_unused_port
def cleanup():
tornado.testing.bind_unused_port = self._bind_unused_port_orig
self.addCleanup(cleanup)
super().setUp()
def supervisor():
"""A running supervisor with two connected status clients."""
info = {
'expected_services':
[
{
"short_name": "service1",
"long_name": "Service 1"
},
{
"short_name": "service2",
"long_name": "Service 2"
}
],
'port': 'unused' # Bind an unused port for testing, the value will appear on visor.port after visor.loaded is set
}
visor = IOTileSupervisor(info)
visor.start()
signaled = visor.loaded.wait(2.0)
if not signaled:
raise ValueError("Could not start supervisor service")
port = visor.port
client1 = ServiceStatusClient('ws://127.0.0.1:%d/services' % port)
yield visor, client1
client1.stop()
visor.stop()