当前位置: 首页>>代码示例>>Python>>正文


Python Bladerunner._send_cmd方法代码示例

本文整理汇总了Python中bladerunner.Bladerunner._send_cmd方法的典型用法代码示例。如果您正苦于以下问题:Python Bladerunner._send_cmd方法的具体用法?Python Bladerunner._send_cmd怎么用?Python Bladerunner._send_cmd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bladerunner.Bladerunner的用法示例。


在下文中一共展示了Bladerunner._send_cmd方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_send_cmd_unix_endings

# 需要导入模块: from bladerunner import Bladerunner [as 别名]
# 或者: from bladerunner.Bladerunner import _send_cmd [as 别名]
def test_send_cmd_unix_endings(unicode_chr):
    """Ensure the correct line ending is used when unix is specified."""

    runner = Bladerunner({
        "unix_line_endings": True,
        "windows_line_endings": False,
        "second_password": "hunter55",
    })
    server = Mock()
    # server.expect returns an integer of the prompt matched in its list
    # we want to return N+1 to simulate matching a passwd prompt
    server.expect = Mock(return_value=(
        len(runner.options["shell_prompts"]) +
        len(runner.options["extra_prompts"]) +
        1
    ))

    with patch.object(base, "format_output") as p_format_out:
        runner._send_cmd("fake", server)

    p_format_out.assert_called_once_with(server.before, "fake", runner.options)
    server.send.assert_called_once_with("fake{0}".format(unicode_chr(0x000A)))

    # the second password should be send with sendline
    server.sendline.assert_called_once_with("hunter55")

    assert server.expect.call_count == 2
开发者ID:Demonware,项目名称:bladerunner,代码行数:29,代码来源:test_base.py

示例2: test_fallback_prompt_guess

# 需要导入模块: from bladerunner import Bladerunner [as 别名]
# 或者: from bladerunner.Bladerunner import _send_cmd [as 别名]
def test_fallback_prompt_guess(pexpect_exceptions):
    """If a TIMEOUT or EOF error is raised, call _try_for_unmatched_prompt."""

    server = Mock()
    server.expect = Mock(side_effect=pexpect_exceptions("mock exception"))
    runner = Bladerunner({
        "username": "guy",
        "password": "hunter2",
    })

    with patch.object(runner, "_try_for_unmatched_prompt") as p_try_for:
        runner._send_cmd("not real", server)

    p_try_for.assert_called_once_with(server, server.before, "not real")
开发者ID:Demonware,项目名称:bladerunner,代码行数:16,代码来源:test_base.py

示例3: test_send_cmd_no_preference

# 需要导入模块: from bladerunner import Bladerunner [as 别名]
# 或者: from bladerunner.Bladerunner import _send_cmd [as 别名]
def test_send_cmd_no_preference():
    """Ensure we call to pexpect's sendline which uses os.linesep."""

    runner = Bladerunner()
    server = Mock()
    server.expect = Mock(return_value=1)

    with patch.object(base, "format_output") as p_format_out:
        runner._send_cmd("mock", server)

    p_format_out.assert_called_once_with(server.before, "mock", runner.options)
    server.sendline.assert_called_once_with("mock")

    assert server.expect.call_count == 1
开发者ID:Demonware,项目名称:bladerunner,代码行数:16,代码来源:test_base.py

示例4: test_send_cmd_winderps_endings

# 需要导入模块: from bladerunner import Bladerunner [as 别名]
# 或者: from bladerunner.Bladerunner import _send_cmd [as 别名]
def test_send_cmd_winderps_endings(unicode_chr):
    """Ensure the wrong line endings are used when winderps is required."""

    runner = Bladerunner({
        "unix_line_endings": False,
        "windows_line_endings": True,
    })
    server = Mock()
    server.expect = Mock(return_value=1)

    with patch.object(base, "format_output") as p_format_out:
        runner._send_cmd("faked", server)

    p_format_out.assert_called_once_with(server.before, "faked", runner.options)
    server.send.assert_called_once_with("faked{0}{1}".format(
        unicode_chr(0x000D),
        unicode_chr(0x000A),
    ))

    assert server.expect.call_count == 1
开发者ID:Demonware,项目名称:bladerunner,代码行数:22,代码来源:test_base.py

示例5: test_send_cmd_no_line_endings

# 需要导入模块: from bladerunner import Bladerunner [as 别名]
# 或者: from bladerunner.Bladerunner import _send_cmd [as 别名]
def test_send_cmd_no_line_endings():
    """If are False, pexpect's sendline should be called (which uses os)."""

    runner = Bladerunner()
    # we need to update after init as init will fallback to os preferred
    runner.options.update({
        "unix_line_endings": False,
        "windows_line_endings": False,
    })
    server = Mock()
    server.expect = Mock(return_value=1)

    with patch.object(base, "format_output") as p_format_out:
        runner._send_cmd("fake_cmd", server)

    p_format_out.assert_called_once_with(
        server.before,
        "fake_cmd",
        runner.options,
    )
    server.sendline.assert_called_once_with("fake_cmd")

    assert server.expect.call_count == 1
开发者ID:Demonware,项目名称:bladerunner,代码行数:25,代码来源:test_base.py


注:本文中的bladerunner.Bladerunner._send_cmd方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。