本文整理汇总了Python中nameko.cli.main.setup_parser函数的典型用法代码示例。如果您正苦于以下问题:Python setup_parser函数的具体用法?Python setup_parser怎么用?Python setup_parser使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setup_parser函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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'
}
示例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
示例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
示例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)
示例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)
示例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)
示例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()
示例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()
示例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()
示例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
示例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()
示例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()
示例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
示例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
示例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()