本文整理汇总了Python中click.testing.CliRunner方法的典型用法代码示例。如果您正苦于以下问题:Python testing.CliRunner方法的具体用法?Python testing.CliRunner怎么用?Python testing.CliRunner使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类click.testing
的用法示例。
在下文中一共展示了testing.CliRunner方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_simple_cloud_commands
# 需要导入模块: from click import testing [as 别名]
# 或者: from click.testing import CliRunner [as 别名]
def test_simple_cloud_commands(ControllerClient, format_result):
commands = [
["claim-node", "token"],
["create-node", "test"],
["delete-node", "test"],
["describe-node", "test"],
["group-add-node", "group", "node"],
["help"],
["list-groups"],
["list-nodes"],
["login"],
["logout"],
["rename-node", "node", "node"]
]
format_result.return_value = "result"
runner = CliRunner()
for command in commands:
result = runner.invoke(cloud.root, command, obj={})
print("Command {} exit code {}".format(command[0], result.exit_code))
assert result.exit_code == 0
示例2: test_csv
# 需要导入模块: from click import testing [as 别名]
# 或者: from click.testing import CliRunner [as 别名]
def test_csv():
expected = '\n'.join([
'source_context, test_context',
'smother/tests/demo.py:11,test2',
'smother/tests/demo.py:4,test4',
'',
])
runner = CliRunner()
with NamedTemporaryFile(mode='w+') as tf:
result = runner.invoke(
cli,
['-r', 'smother/tests/.smother_2',
'csv',
tf.name
]
)
assert result.exit_code == 0
tf.seek(0)
assert tf.read() == expected
示例3: test_semantic_csv
# 需要导入模块: from click import testing [as 别名]
# 或者: from click.testing import CliRunner [as 别名]
def test_semantic_csv():
expected = '\n'.join([
'source_context, test_context',
'smother.tests.demo,test4',
'smother.tests.demo:bar,test2',
'',
])
runner = CliRunner()
with NamedTemporaryFile(mode='w+') as tf:
result = runner.invoke(
cli,
['-r', 'smother/tests/.smother_2',
'--semantic',
'csv',
tf.name
]
)
assert result.exit_code == 0
tf.seek(0)
assert tf.read() == expected
示例4: test_input_file_invalid_ip_addresses_passsed
# 需要导入模块: from click import testing [as 别名]
# 或者: from click.testing import CliRunner [as 别名]
def test_input_file_invalid_ip_addresses_passsed(self, api_client):
"""Error returned if only invalid IP addresses are passed in input file."""
runner = CliRunner()
expected = (
"Error: at least one valid IP address must be passed either as an "
"argument (IP_ADDRESS) or through the -i/--input_file option."
)
result = runner.invoke(
subcommand.interesting,
["-i", StringIO("not-an-ip")],
parent=Context(main, info_name="greynoise"),
)
assert result.exit_code == -1
assert "Usage: greynoise interesting" in result.output
assert expected in result.output
api_client.interesting.assert_not_called()
示例5: test_empty_input_file
# 需要导入模块: from click import testing [as 别名]
# 或者: from click.testing import CliRunner [as 别名]
def test_empty_input_file(self, api_client):
"""Error is returned if empty input fle is passed."""
runner = CliRunner()
expected = (
"Error: at least one query must be passed either as an argument "
"(QUERY) or through the -i/--input_file option."
)
result = runner.invoke(
subcommand.query,
["-i", StringIO()],
parent=Context(main, info_name="greynoise"),
)
assert result.exit_code == -1
assert "Usage: greynoise query" in result.output
assert expected in result.output
api_client.query.assert_not_called()
示例6: test_startserver
# 需要导入模块: from click import testing [as 别名]
# 或者: from click.testing import CliRunner [as 别名]
def test_startserver(self):
runner = CliRunner()
# Starting server with valid parameters
result = runner.invoke(startserver,
["--adduser", "--api", "--no-auth", "--dburl",
"--hydradoc", "--port", "--no-token", "--serverurl",
"serve"])
result.exit_code != 0
# Starting server with invalid parameters
result = runner.invoke(startserver,
["--adduser", "sqlite://not-valid", "http://localhost",
"--port", "serve"])
assert result.exit_code == 2
示例7: test_taskcli_builddata_command
# 需要导入模块: from click import testing [as 别名]
# 或者: from click.testing import CliRunner [as 别名]
def test_taskcli_builddata_command(mocker):
"""Test the CLI task get build data command."""
task_id = "aaaa-bbbb-cccc-dddd"
build_data = [{
"node_name": "foo",
"task_id": task_id,
"collected_data": "1/1/2000",
"generator": "test",
"data_format": "text/plain",
"data_element": "Hello World!",
}]
api_client = mocker.MagicMock()
api_client.get_task_build_data.return_value = build_data
mocker.patch(
'drydock_provisioner.cli.commands.DrydockClient', new=api_client)
mocker.patch('drydock_provisioner.cli.commands.KeystoneClient')
runner = CliRunner()
result = runner.invoke(
cli.drydock, ['-u', 'http://foo', 'task', 'builddata', '-t', task_id])
print(result.exc_info)
api_client.get_task_build_data.assert_called_with(task_id)
assert yaml.safe_dump(
build_data, allow_unicode=True,
default_flow_style=False) in result.output
示例8: test
# 需要导入模块: from click import testing [as 别名]
# 或者: from click.testing import CliRunner [as 别名]
def test():
result = CliRunner().invoke(main, "foo")
assert result.exit_code == 0
示例9: test_notify
# 需要导入模块: from click import testing [as 别名]
# 或者: from click.testing import CliRunner [as 别名]
def test_notify():
result = CliRunner().invoke(main, ["foo", "--notify"])
assert result.exit_code == 0
示例10: test_send
# 需要导入模块: from click import testing [as 别名]
# 或者: from click.testing import CliRunner [as 别名]
def test_send(*_):
result = CliRunner().invoke(main, ["foo", "--send=http://foo"])
assert result.exit_code == 0
示例11: test_send_error
# 需要导入模块: from click import testing [as 别名]
# 或者: from click.testing import CliRunner [as 别名]
def test_send_error(*_):
result = CliRunner().invoke(main, ["foo", "--send=http://foo"])
assert result.exit_code == get_click_exception_return_code()
示例12: test_cli_version
# 需要导入模块: from click import testing [as 别名]
# 或者: from click.testing import CliRunner [as 别名]
def test_cli_version():
runner = CliRunner()
result = runner.invoke(cli, ['--version'])
assert result.exit_code == 0
assert len(result.output.split('.')) == 3
示例13: test_cli_infer_schema_enables_infer_fields
# 需要导入模块: from click import testing [as 别名]
# 或者: from click.testing import CliRunner [as 别名]
def test_cli_infer_schema_enables_infer_fields(validate_mock):
CliRunner().invoke(cli, ['--infer-schema', 'data.csv'])
last_call_args = validate_mock.call_args
assert last_call_args is not None
assert last_call_args[-1].get('infer_schema')
assert last_call_args[-1].get('infer_fields')
示例14: test_cli_accepts_multiple_sources
# 需要导入模块: from click import testing [as 别名]
# 或者: from click.testing import CliRunner [as 别名]
def test_cli_accepts_multiple_sources(validate_mock):
sources = ['data1.csv', 'data2.csv']
expected_sources = [{'source': source} for source in sources]
CliRunner().invoke(cli, sources)
last_call_args = validate_mock.call_args
assert last_call_args is not None
assert last_call_args[0][0] == expected_sources
示例15: test_cli_init
# 需要导入模块: from click import testing [as 别名]
# 或者: from click.testing import CliRunner [as 别名]
def test_cli_init():
resource_path = 'data/valid.csv'
result = CliRunner().invoke(init, [resource_path])
assert result.exit_code == 0
dp = datapackage.Package(json.loads(result.output), strict=True)
resource = dp.resources[0]
assert resource.descriptor['path'] == resource_path
assert 'schema' in resource.descriptor