當前位置: 首頁>>代碼示例>>Python>>正文


Python testing.CliRunner方法代碼示例

本文整理匯總了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 
開發者ID:ParadropLabs,項目名稱:Paradrop,代碼行數:24,代碼來源:test_cloud.py

示例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 
開發者ID:ChrisBeaumont,項目名稱:smother,代碼行數:23,代碼來源:test_cli.py

示例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 
開發者ID:ChrisBeaumont,項目名稱:smother,代碼行數:24,代碼來源:test_cli.py

示例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() 
開發者ID:GreyNoise-Intelligence,項目名稱:pygreynoise,代碼行數:20,代碼來源:test_subcommand.py

示例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() 
開發者ID:GreyNoise-Intelligence,項目名稱:pygreynoise,代碼行數:20,代碼來源:test_subcommand.py

示例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 
開發者ID:HTTP-APIs,項目名稱:hydrus,代碼行數:17,代碼來源:test_cli.py

示例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 
開發者ID:airshipit,項目名稱:drydock,代碼行數:31,代碼來源:test_cli_task.py

示例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 
開發者ID:bcb,項目名稱:jsonrpcclient,代碼行數:5,代碼來源:test_main.py

示例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 
開發者ID:bcb,項目名稱:jsonrpcclient,代碼行數:5,代碼來源:test_main.py

示例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 
開發者ID:bcb,項目名稱:jsonrpcclient,代碼行數:5,代碼來源:test_main.py

示例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() 
開發者ID:bcb,項目名稱:jsonrpcclient,代碼行數:5,代碼來源:test_main.py

示例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 
開發者ID:frictionlessdata,項目名稱:goodtables-py,代碼行數:7,代碼來源:test_cli.py

示例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') 
開發者ID:frictionlessdata,項目名稱:goodtables-py,代碼行數:9,代碼來源:test_cli.py

示例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 
開發者ID:frictionlessdata,項目名稱:goodtables-py,代碼行數:11,代碼來源:test_cli.py

示例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 
開發者ID:frictionlessdata,項目名稱:goodtables-py,代碼行數:13,代碼來源:test_cli.py


注:本文中的click.testing.CliRunner方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。