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


Python MagicMock.returncode方法代码示例

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


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

示例1: test_wait_for_process_termination

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import returncode [as 别名]
def test_wait_for_process_termination(loop):

    if sys.version_info >= (3, 5):
        # No need for test we use native version
        return
    process = MagicMock()
    process.returncode = 0
    exec = wait_for_process_termination(process)
    loop.run_until_complete(asyncio.async(exec))

    process = MagicMock()
    process.returncode = None
    exec = wait_for_process_termination(process, timeout=0.5)
    with pytest.raises(asyncio.TimeoutError):
        loop.run_until_complete(asyncio.async(exec))
开发者ID:AJNOURI,项目名称:gns3-server,代码行数:17,代码来源:test_asyncio.py

示例2: test_start

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import returncode [as 别名]
def test_start(loop, vm, async_run):
    process = MagicMock()
    process.returncode = None

    with NotificationManager.instance().queue() as queue:
        async_run(queue.get(0))  # Ping

        with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
            with asyncio_patch("asyncio.create_subprocess_exec", return_value=process) as mock_exec:
                with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM.start_wrap_console"):
                    nio = VPCS.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
                    async_run(vm.port_add_nio_binding(0, nio))
                    loop.run_until_complete(asyncio.async(vm.start()))
                    assert mock_exec.call_args[0] == (vm._vpcs_path(),
                                                      '-p',
                                                      str(vm._internal_console_port),
                                                      '-m', '1',
                                                      '-i',
                                                      '1',
                                                      '-F',
                                                      '-R',
                                                      '-s',
                                                      ANY,
                                                      '-c',
                                                      ANY,
                                                      '-t',
                                                      '127.0.0.1')
                assert vm.is_running()
                assert vm.command_line == ' '.join(mock_exec.call_args[0])
        (action, event, kwargs) = async_run(queue.get(0))
        assert action == "node.updated"
        assert event == vm
开发者ID:AJNOURI,项目名称:gns3-server,代码行数:34,代码来源:test_vpcs_vm.py

示例3: test_reload

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import returncode [as 别名]
def test_reload(loop, vm, async_run):
    process = MagicMock()

    # Wait process kill success
    future = asyncio.Future()
    future.set_result(True)
    process.wait.return_value = future
    process.returncode = None

    with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
        with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM.start_wrap_console"):
            with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
                nio = VPCS.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
                async_run(vm.port_add_nio_binding(0, nio))
                async_run(vm.start())
                assert vm.is_running()

                with asyncio_patch("gns3server.utils.asyncio.wait_for_process_termination"):
                    async_run(vm.reload())
                assert vm.is_running() is True

                if sys.platform.startswith("win"):
                    process.send_signal.assert_called_with(1)
                else:
                    process.terminate.assert_called_with()
开发者ID:AJNOURI,项目名称:gns3-server,代码行数:27,代码来源:test_vpcs_vm.py

示例4: popen

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import returncode [as 别名]
def popen(monkeypatch):
    mock_popen = MagicMock()
    mock_popen.return_value = mock_popen
    mock_popen.returncode = 0
    mock_popen.communicate.return_value = b'{"stream": "stdout"}', b'stderr'
    monkeypatch.setattr('lizzy.apps.common.Popen', mock_popen)
    return mock_popen
开发者ID:mfelsche,项目名称:lizzy,代码行数:9,代码来源:test_senza_wrapper.py

示例5: test_start_0_6_1

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import returncode [as 别名]
def test_start_0_6_1(loop, vm, async_run):
    """
    Version 0.6.1 doesn't have the -R options. It's not require
    because GNS3 provide a patch for this.
    """
    process = MagicMock()
    process.returncode = None
    vm._vpcs_version = parse_version("0.6.1")

    with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
        with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM.start_wrap_console"):
            with asyncio_patch("asyncio.create_subprocess_exec", return_value=process) as mock_exec:
                nio = VPCS.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
                async_run(vm.port_add_nio_binding(0, nio))
                async_run(vm.start())
                assert mock_exec.call_args[0] == (vm._vpcs_path(),
                                                  '-p',
                                                  str(vm._internal_console_port),
                                                  '-m', '1',
                                                  '-i',
                                                  '1',
                                                  '-F',
                                                  '-s',
                                                  ANY,
                                                  '-c',
                                                  ANY,
                                                  '-t',
                                                  '127.0.0.1')
                assert vm.is_running()
开发者ID:AJNOURI,项目名称:gns3-server,代码行数:31,代码来源:test_vpcs_vm.py

示例6: test_start

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import returncode [as 别名]
def test_start(loop, vm):
    process = MagicMock()
    process.returncode = None
    queue = vm.project.get_listen_queue()

    with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
        with asyncio_patch("asyncio.create_subprocess_exec", return_value=process) as mock_exec:
            nio = VPCS.instance().create_nio(vm.vpcs_path, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
            vm.port_add_nio_binding(0, nio)
            loop.run_until_complete(asyncio.async(vm.start()))
            assert mock_exec.call_args[0] == (vm.vpcs_path,
                                              '-p',
                                              str(vm.console),
                                              '-m', '1',
                                              '-i',
                                              '1',
                                              '-F',
                                              '-R',
                                              '-s',
                                              '4242',
                                              '-c',
                                              '4243',
                                              '-t',
                                              '127.0.0.1')
            assert vm.is_running()
            assert vm.command_line == ' '.join(mock_exec.call_args[0])
    (action, event) = queue.get_nowait()
    assert action == "vm.started"
    assert event == vm
开发者ID:ravirajsdeshmukh,项目名称:gns3-server,代码行数:31,代码来源:test_vpcs_vm.py

示例7: test_stop

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import returncode [as 别名]
def test_stop(loop, vm):
    process = MagicMock()

    # Wait process kill success
    future = asyncio.Future()
    future.set_result(True)
    process.wait.return_value = future
    process.returncode = None

    with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
        with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
            nio = VPCS.instance().create_nio(vm.vpcs_path, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
            vm.port_add_nio_binding(0, nio)

            loop.run_until_complete(asyncio.async(vm.start()))
            assert vm.is_running()

            queue = vm.project.get_listen_queue()

            with asyncio_patch("gns3server.utils.asyncio.wait_for_process_termination"):
                loop.run_until_complete(asyncio.async(vm.stop()))
            assert vm.is_running() is False

            if sys.platform.startswith("win"):
                process.send_signal.assert_called_with(1)
            else:
                process.terminate.assert_called_with()

            (action, event) = queue.get_nowait()
            assert action == "vm.stopped"
            assert event == vm
开发者ID:ravirajsdeshmukh,项目名称:gns3-server,代码行数:33,代码来源:test_vpcs_vm.py

示例8: test_start_0_6_1

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import returncode [as 别名]
def test_start_0_6_1(loop, vm):
    """
    Version 0.6.1 doesn't have the -R options. It's not require
    because GNS3 provide a patch for this.
    """
    process = MagicMock()
    process.returncode = None
    queue = vm.project.get_listen_queue()
    vm._vpcs_version = parse_version("0.6.1")

    with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
        with asyncio_patch("asyncio.create_subprocess_exec", return_value=process) as mock_exec:
            nio = VPCS.instance().create_nio(vm.vpcs_path, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
            vm.port_add_nio_binding(0, nio)
            loop.run_until_complete(asyncio.async(vm.start()))
            assert mock_exec.call_args[0] == (vm.vpcs_path,
                                              '-p',
                                              str(vm.console),
                                              '-m', '1',
                                              '-i',
                                              '1',
                                              '-F',
                                              '-s',
                                              '4242',
                                              '-c',
                                              '4243',
                                              '-t',
                                              '127.0.0.1')
            assert vm.is_running()
    (action, event) = queue.get_nowait()
    assert action == "vm.started"
    assert event == vm
开发者ID:ravirajsdeshmukh,项目名称:gns3-server,代码行数:34,代码来源:test_vpcs_vm.py

示例9: test_stop

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import returncode [as 别名]
def test_stop(loop, vm, async_run):
    process = MagicMock()

    # Wait process kill success
    future = asyncio.Future()
    future.set_result(True)
    process.wait.return_value = future
    process.returncode = None

    vm.ip_address = "192.168.1.1"
    with NotificationManager.instance().queue() as queue:
        with patch("sys.platform", return_value="win"):
            with asyncio_patch("gns3server.compute.traceng.traceng_vm.TraceNGVM._check_requirements", return_value=True):
                with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
                    nio = TraceNG.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1", "filters": {}})
                    async_run(vm.port_add_nio_binding(0, nio))

                    vm._ubridge_send = AsyncioMagicMock()
                    async_run(vm.start("192.168.1.2"))
                    assert vm.is_running()

                    with asyncio_patch("gns3server.utils.asyncio.wait_for_process_termination"):
                        loop.run_until_complete(asyncio.ensure_future(vm.stop()))
                    assert vm.is_running() is False

                    process.terminate.assert_called_with()

                    async_run(queue.get(1))  #  Ping
                    async_run(queue.get(1))  #  Started

                    (action, event, kwargs) = async_run(queue.get(1))
                    assert action == "node.updated"
                    assert event == vm
开发者ID:GNS3,项目名称:gns3-server,代码行数:35,代码来源:test_traceng_vm.py

示例10: test_start

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import returncode [as 别名]
def test_start(loop, vm, async_run):
    process = MagicMock()
    process.returncode = None

    with NotificationManager.instance().queue() as queue:
        async_run(queue.get(1))  # Ping

        vm.ip_address = "192.168.1.1"
        with patch("sys.platform", return_value="win"):
            with asyncio_patch("gns3server.compute.traceng.traceng_vm.TraceNGVM._check_requirements", return_value=True):
                with asyncio_patch("asyncio.create_subprocess_exec", return_value=process) as mock_exec:
                    loop.run_until_complete(asyncio.ensure_future(vm.start("192.168.1.2")))
                    assert mock_exec.call_args[0] == (vm._traceng_path(),
                                                      '-u',
                                                      '-c',
                                                      ANY,
                                                      '-v',
                                                      ANY,
                                                      '-b',
                                                      '127.0.0.1',
                                                      '-s',
                                                      'ICMP',
                                                      '-f',
                                                      '192.168.1.1',
                                                      '192.168.1.2')
                    assert vm.is_running()
                    assert vm.command_line == ' '.join(mock_exec.call_args[0])
        (action, event, kwargs) = async_run(queue.get(1))
        assert action == "node.updated"
        assert event == vm
开发者ID:GNS3,项目名称:gns3-server,代码行数:32,代码来源:test_traceng_vm.py

示例11: test_reload

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import returncode [as 别名]
def test_reload(loop, vm, async_run):
    process = MagicMock()

    # Wait process kill success
    future = asyncio.Future()
    future.set_result(True)
    process.wait.return_value = future
    process.returncode = None

    vm.ip_address = "192.168.1.1"
    with patch("sys.platform", return_value="win"):
        with asyncio_patch("gns3server.compute.traceng.traceng_vm.TraceNGVM._check_requirements", return_value=True):
            with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
                nio = TraceNG.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1", "filters": {}})
                async_run(vm.port_add_nio_binding(0, nio))

                vm._ubridge_send = AsyncioMagicMock()
                async_run(vm.start("192.168.1.2"))
                assert vm.is_running()

                with asyncio_patch("gns3server.utils.asyncio.wait_for_process_termination"):
                    async_run(vm.reload())
                assert vm.is_running() is True

                #if sys.platform.startswith("win"):
                #    process.send_signal.assert_called_with(1)
                #else:
                process.terminate.assert_called_with()
开发者ID:GNS3,项目名称:gns3-server,代码行数:30,代码来源:test_traceng_vm.py

示例12: test_stop

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import returncode [as 别名]
def test_stop(loop, vm, async_run):
    process = MagicMock()

    # Wait process kill success
    future = asyncio.Future()
    future.set_result(True)
    process.wait.return_value = future
    process.returncode = None

    with NotificationManager.instance().queue() as queue:
        with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
            with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM.start_wrap_console"):
                with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
                    nio = VPCS.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
                    async_run(vm.port_add_nio_binding(0, nio))

                    async_run(vm.start())
                    assert vm.is_running()

                    with asyncio_patch("gns3server.utils.asyncio.wait_for_process_termination"):
                        loop.run_until_complete(asyncio.async(vm.stop()))
                    assert vm.is_running() is False

                    if sys.platform.startswith("win"):
                        process.send_signal.assert_called_with(1)
                    else:
                        process.terminate.assert_called_with()

                    async_run(queue.get(0))  #  Ping
                    async_run(queue.get(0))  #  Started

                    (action, event, kwargs) = async_run(queue.get(0))
                    assert action == "node.updated"
                    assert event == vm
开发者ID:AJNOURI,项目名称:gns3-server,代码行数:36,代码来源:test_vpcs_vm.py

示例13: test_sign_one_cmd_erro

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import returncode [as 别名]
    def test_sign_one_cmd_erro(self, mc_popen):
        mc_handle = MagicMock()
        mc_handle.communicate.return_value = (STDOUT, STDERR)
        mc_handle.returncode = 1
        mc_popen.return_value = mc_handle

        fake_path = "/tmp/pkg.rpm"
        with pytest.raises(CoprSignError):
            _sign_one(fake_path, self.usermail)
开发者ID:0-T-0,项目名称:copr,代码行数:11,代码来源:test_sign.py

示例14: test_get_pubkey

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import returncode [as 别名]
    def test_get_pubkey(self, mc_popen):
        mc_handle = MagicMock()
        mc_handle.communicate.return_value = (STDOUT, STDERR)
        mc_handle.returncode = 0
        mc_popen.return_value = mc_handle

        result = get_pubkey(self.username, self.projectname)
        assert result == STDOUT
        assert mc_popen.call_args[0][0] == ['sudo', '/bin/sign', '-u', self.usermail, '-p']
开发者ID:0-T-0,项目名称:copr,代码行数:11,代码来源:test_sign.py

示例15: test_start

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import returncode [as 别名]
def test_start(loop, vm):
    process = MagicMock()
    process.returncode = None

    with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
        with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
            nio = VPCS.instance().create_nio(vm.vpcs_path, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
            vm.port_add_nio_binding(0, nio)
            loop.run_until_complete(asyncio.async(vm.start()))
            assert vm.is_running()
开发者ID:bluca,项目名称:gns3-server,代码行数:12,代码来源:test_vpcs_vm.py


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