本文整理汇总了Python中nameko.cli.main.setup_parser函数的典型用法代码示例。如果您正苦于以下问题:Python setup_parser函数的具体用法?Python setup_parser怎么用?Python setup_parser使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setup_parser函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_main_with_config
def test_main_with_config(rabbit_config, tmpdir):
config = tmpdir.join('config.yaml')
config.write("""
WEB_SERVER_ADDRESS: '0.0.0.0:8001'
AMQP_URI: '{}'
serializer: 'json'
""".format(rabbit_config[AMQP_URI_CONFIG_KEY]))
parser = setup_parser()
args = parser.parse_args([
'run',
'--config',
config.strpath,
'test.sample',
])
with patch('nameko.cli.run.run') as run:
main(args)
assert run.call_count == 1
(_, config) = run.call_args[0]
assert config == {
WEB_SERVER_CONFIG_KEY: '0.0.0.0:8001',
AMQP_URI_CONFIG_KEY: rabbit_config[AMQP_URI_CONFIG_KEY],
SERIALIZER_CONFIG_KEY: 'json'
}
开发者ID:davidszotten,项目名称:nameko,代码行数:27,代码来源:test_run.py
示例2: test_flag_action
def test_flag_action(param, value):
parser = setup_parser()
args = ['backdoor', 0]
if param is not None:
args.append(param)
parsed = parser.parse_args(args)
assert parsed.rlwrap is value
开发者ID:onefinestay,项目名称:nameko,代码行数:7,代码来源:test_main.py
示例3: test_main
def test_main(mock_os, tmpdir, capsys):
config = tmpdir.join('config.yaml')
config.write("""
FOO: ${FOO:foobar}
BAR: ${BAR}
""")
parser = setup_parser()
setup_yaml_parser()
args = parser.parse_args([
'show-config',
'--config',
config.strpath,
])
mock_os.environ = {
'BAR': '[1,2,3]'
}
ShowConfig.main(args)
out, _ = capsys.readouterr()
expected = dedent("""
BAR:
- 1
- 2
- 3
FOO: foobar
""").strip()
assert out.strip() == expected
开发者ID:davidszotten,项目名称:nameko,代码行数:32,代码来源:test_show_config.py
示例4: test_no_telnet
def test_no_telnet():
parser = setup_parser()
args = parser.parse_args(['backdoor', '0'])
with patch('nameko.cli.backdoor.os') as mock_os:
mock_os.system.return_value = -1
with pytest.raises(CommandError) as exc:
Backdoor.main(args)
assert 'Could not find an installed telnet' in str(exc)
开发者ID:davidszotten,项目名称:nameko,代码行数:8,代码来源:test_backdoor.py
示例5: test_stop
def test_stop(running_backdoor):
_, port = running_backdoor
parser = setup_parser()
args = parser.parse_args(['backdoor', str(port)])
with patch.multiple(
'nameko.cli.backdoor', call=DEFAULT, os=DEFAULT
) as mocks:
# choose telnet (skip nc and netcat) and find rlwrap
mocks['os'].system.side_effect = [-1, -1, 0, 0]
mocks['call'].side_effect = [KeyboardInterrupt, 0]
Backdoor.main(args)
开发者ID:davidszotten,项目名称:nameko,代码行数:11,代码来源:test_backdoor.py
示例6: test_no_running_backdoor
def test_no_running_backdoor():
parser = setup_parser()
args = parser.parse_args(['backdoor', '0'])
with patch.multiple(
'nameko.cli.backdoor', call=DEFAULT, os=DEFAULT
) as mocks:
mocks['os'].system.return_value = 0
mocks['call'].return_value = -1
with pytest.raises(CommandError) as exc:
Backdoor.main(args)
assert 'Backdoor unreachable' in str(exc)
开发者ID:davidszotten,项目名称:nameko,代码行数:11,代码来源:test_backdoor.py
示例7: test_plain_fallback
def test_plain_fallback(pystartup):
parser = setup_parser()
args = parser.parse_args(['shell', '--interface', 'bpython'])
with patch('nameko.cli.shell.code') as code:
main(args)
_, kwargs = code.interact.call_args
local = kwargs['local']
assert 'n' in local.keys()
assert local['foo'] == 42
local['n'].disconnect()
开发者ID:SivagnanamCiena,项目名称:nameko,代码行数:12,代码来源:test_shell.py
示例8: test_basic
def test_basic(pystartup):
parser = setup_parser()
args = parser.parse_args(['shell'])
with patch('nameko.cli.shell.code') as code:
Shell.main(args)
_, kwargs = code.interact.call_args
local = kwargs['local']
assert 'n' in local.keys()
assert local['foo'] == 42
local['n'].disconnect()
开发者ID:mattbennett,项目名称:nameko,代码行数:12,代码来源:test_shell.py
示例9: test_ipython
def test_ipython(pystartup):
parser = setup_parser()
args = parser.parse_args(['shell', '--interface', 'ipython'])
with patch('IPython.embed') as embed:
main(args)
_, kwargs = embed.call_args
local = kwargs['user_ns']
assert 'n' in local.keys()
assert local['foo'] == 42
local['n'].disconnect()
开发者ID:SivagnanamCiena,项目名称:nameko,代码行数:12,代码来源:test_shell.py
示例10: test_uses_plain_when_not_tty
def test_uses_plain_when_not_tty(pystartup, rabbit_config, isatty):
parser = setup_parser()
args = parser.parse_args([
'shell', '--broker', rabbit_config[AMQP_URI_CONFIG_KEY],
'--interface', 'ipython'
])
isatty.return_value = False
with patch('nameko.cli.shell.code') as code:
Shell.main(args)
assert code.interact.called
开发者ID:onefinestay,项目名称:nameko,代码行数:13,代码来源:test_shell.py
示例11: test_main_with_logging_config
def test_main_with_logging_config(rabbit_config, tmpdir):
config = """
AMQP_URI: {amqp_uri}
LOGGING:
version: 1
disable_existing_loggers: false
formatters:
simple:
format: "%(name)s - %(levelname)s - %(message)s"
handlers:
capture:
class: logging.FileHandler
level: INFO
formatter: simple
filename: {capture_file}
root:
level: INFO
handlers: [capture]
"""
capture_file = tmpdir.join('capture.log')
config_file = tmpdir.join('config.yaml')
config_file.write(
dedent(config.format(
capture_file=capture_file.strpath,
amqp_uri=rabbit_config['AMQP_URI']
))
)
parser = setup_parser()
args = parser.parse_args([
'run',
'--config',
config_file.strpath,
'test.sample',
])
# start runner and wait for it to come up
with wait_for_call(ServiceRunner, 'start'):
gt = eventlet.spawn(main, args)
with ClusterRpcProxy(rabbit_config) as proxy:
proxy.service.ping()
pid = os.getpid()
os.kill(pid, signal.SIGTERM)
gt.wait()
assert "test.sample - INFO - ping!" in capture_file.read()
开发者ID:davidszotten,项目名称:nameko,代码行数:51,代码来源:test_run.py
示例12: test_basic
def test_basic(pystartup, rabbit_config):
parser = setup_parser()
args = parser.parse_args([
'shell', '--broker', rabbit_config[AMQP_URI_CONFIG_KEY]
])
with patch("nameko.cli.shell.code") as code:
Shell.main(args)
_, kwargs = code.interact.call_args
local = kwargs['local']
assert 'n' in local.keys()
assert local['foo'] == 42
local['n'].disconnect()
开发者ID:onefinestay,项目名称:nameko,代码行数:14,代码来源:test_shell.py
示例13: test_default_host
def test_default_host(running_backdoor):
_, port = running_backdoor
parser = setup_parser()
args = parser.parse_args(['backdoor', str(port)])
with patch.multiple(
'nameko.cli.backdoor', call=DEFAULT, os=DEFAULT
) as mocks:
mock_call = mocks['call']
mocks['os'].system.return_value = 0
mock_call.return_value = 0
Backdoor.main(args)
(cmd, ), _ = mock_call.call_args
expected = ['rlwrap', 'netcat', 'localhost'] + [str(port)] + ['--close']
assert cmd == expected
开发者ID:davidszotten,项目名称:nameko,代码行数:14,代码来源:test_backdoor.py
示例14: test_broker_as_param
def test_broker_as_param(self):
amqp_uri = "amqp://broker/param"
parser = setup_parser()
args = parser.parse_args(['shell', '--broker', amqp_uri])
with patch('nameko.cli.shell.ShellRunner') as shell_runner:
Shell.main(args)
expected_message = (
"Broker: {}".format(amqp_uri)
)
(banner, _), _ = shell_runner.call_args
assert expected_message in banner
开发者ID:onefinestay,项目名称:nameko,代码行数:15,代码来源:test_shell.py
示例15: test_bpython
def test_bpython(pystartup, rabbit_config):
parser = setup_parser()
args = parser.parse_args([
'shell', '--broker', rabbit_config[AMQP_URI_CONFIG_KEY],
'--interface', 'bpython'
])
with patch('bpython.embed') as embed:
Shell.main(args)
_, kwargs = embed.call_args
local = kwargs['locals_']
assert 'n' in local.keys()
assert local['foo'] == 42
local['n'].disconnect()
开发者ID:davidszotten,项目名称:nameko,代码行数:15,代码来源:test_shell.py
示例16: test_config
def test_config(pystartup):
parser = setup_parser()
args = parser.parse_args(['shell', '--config', TEST_CONFIG_FILE])
with patch('nameko.cli.shell.code') as code:
Shell.main(args)
_, kwargs = code.interact.call_args
local = kwargs['local']
assert 'n' in local.keys()
assert local['n'].config == {
WEB_SERVER_CONFIG_KEY: '0.0.0.0:8001',
AMQP_URI_CONFIG_KEY: 'amqp://guest:[email protected]',
SERIALIZER_CONFIG_KEY: 'json'
}
local['n'].disconnect()
开发者ID:mattbennett,项目名称:nameko,代码行数:16,代码来源:test_shell.py
示例17: test_ipython
def test_ipython(pystartup, rabbit_config, isatty):
parser = setup_parser()
args = parser.parse_args([
'shell', '--broker', rabbit_config[AMQP_URI_CONFIG_KEY],
'--interface', 'ipython'
])
isatty.return_value = True
with patch('IPython.embed') as embed:
Shell.main(args)
_, kwargs = embed.call_args
local = kwargs['user_ns']
assert 'n' in local.keys()
assert local['foo'] == 42
local['n'].disconnect()
开发者ID:onefinestay,项目名称:nameko,代码行数:17,代码来源:test_shell.py
示例18: test_basic
def test_basic(tmpdir):
parser = setup_parser()
args = parser.parse_args(['shell'])
startup = tmpdir.join('startup.py')
startup.write('foo = 42')
with patch('nameko.cli.shell.os.environ') as environ:
environ.get.return_value = str(startup)
with patch('nameko.cli.shell.code') as code:
main(args)
_, kwargs = code.interact.call_args
local = kwargs['local']
assert 'n' in local.keys()
assert local['foo'] == 42
local['n'].disconnect()
开发者ID:ayoshi,项目名称:nameko,代码行数:17,代码来源:test_shell.py
示例19: test_main_with_config
def test_main_with_config(rabbit_config):
parser = setup_parser()
args = parser.parse_args([
'run',
'--config',
RUN_CONFIG_FILE,
'test.sample',
])
with patch('nameko.cli.run.run') as run:
main(args)
assert run.call_count == 1
(_, config) = run.call_args[0]
assert config == {
'WEB_SERVER_ADDRESS': '0.0.0.0:8001',
'AMQP_URI': 'amqp://foo:[email protected]'
}
开发者ID:jkal,项目名称:nameko,代码行数:18,代码来源:test_run.py
示例20: test_basic
def test_basic(running_backdoor):
socket_arg = '{}:{}'.format(*running_backdoor)
parser = setup_parser()
args = parser.parse_args(['backdoor', socket_arg])
with patch.multiple(
'nameko.cli.backdoor', call=DEFAULT, os=DEFAULT
) as mocks:
mock_call = mocks['call']
mocks['os'].system.return_value = 0
mock_call.return_value = 0
Backdoor.main(args)
(cmd, ), _ = mock_call.call_args
expected = (
['rlwrap', 'netcat'] +
list(map(str, running_backdoor)) +
['--close']
)
assert cmd == expected
开发者ID:davidszotten,项目名称:nameko,代码行数:18,代码来源:test_backdoor.py
注:本文中的nameko.cli.main.setup_parser函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论