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


Python MagicMock.returncode方法代码示例

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


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

示例1: test_uninstall

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import returncode [as 别名]
 def test_uninstall(self):
     process = MagicMock()
     process.communicate.side_effect = [('', ''), ('', '')]
     process.returncode = 0
     self.popen.return_value = process
     self.windows.uninstall(self.params)
     self.popen.assert_has_calls([
         call(
             [
                 'powershell.exe',
                 '-Command', 'Stop-Service',
                 '-Name', 'codedeployagent'
             ],
             stdout=subprocess.PIPE,
             stderr=subprocess.PIPE
         ),
         call().communicate(),
         call(
             [
                 'wmic',
                 'product', 'where', 'name="CodeDeploy Host Agent"',
                 'call', 'uninstall', '/nointeractive'
             ],
             stdout=subprocess.PIPE,
             stderr=subprocess.PIPE
         ),
         call().communicate()
     ])
开发者ID:Frame02,项目名称:aws-cli,代码行数:30,代码来源:test_systems.py

示例2: test_install

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import returncode [as 别名]
 def test_install(self):
     process = MagicMock()
     process.communicate.return_value = ('', '')
     process.returncode = 0
     self.popen.return_value = process
     self.ubuntu.install(self.params)
     self.popen.assert_has_calls([
         call(
             ['service', 'codedeploy-agent', 'stop'],
             stdout=subprocess.PIPE,
             stderr=subprocess.PIPE
         ),
         call().communicate()
     ])
     self.check_call.assert_has_calls([
         call(['apt-get', '-y', 'update']),
         call(['apt-get', '-y', 'install', 'ruby2.0']),
         call(['chmod', '+x', './{0}'.format(self.installer)]),
         call(
             ['./{0}'.format(self.installer), 'auto'],
             env=self.environment
         )
     ])
     self.open.assert_called_with(self.installer, 'wb')
     self.open().write.assert_called_with(self.body)
开发者ID:Frame02,项目名称:aws-cli,代码行数:27,代码来源:test_systems.py

示例3: get_proc

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import returncode [as 别名]
 def get_proc(self, return_value=0, stdout='', stderr=''):
     """Return a proc object to attach to the output of Popen
     """
     proc = MagicMock()
     proc.communicate.return_value = self.get_communicate(stdout, stderr)
     proc.returncode = return_value
     return proc
开发者ID:kennydude,项目名称:rest-framework-latex,代码行数:9,代码来源:test_latex.py

示例4: test_call_ipam_plugin_binary_mainline

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import returncode [as 别名]
    def test_call_ipam_plugin_binary_mainline(self, m_popen):
        # Mock _find_ipam_plugin.
        plugin_path = "/opt/bin/cni/calico-ipam"
        self.plugin._find_ipam_plugin = MagicMock(spec=self.plugin._find_ipam_plugin)
        self.plugin._find_ipam_plugin.return_value = plugin_path

        # Mock out return values.
        ip4 = "10.0.0.1/32"
        ip6 = "0:0:0:0:0:ffff:a00:1"
        stdout = json.dumps({"ip4": {"ip": ip4}, "ip6": {"ip": ip6}})
        stderr = ""
        m_proc = MagicMock(spec=Popen)
        m_proc.communicate.return_value = (stdout, stderr)
        m_proc.returncode = 0
        m_popen.return_value = m_proc
        env = {}

        # Set IPAM type.
        self.plugin.ipam_type = "not-calico"

        # Call _call_ipam_plugin.
        rc, result = self.plugin._call_ipam_plugin(env)

        # Assert.
        assert_equal(rc, 0)
        m_popen.assert_called_once_with(plugin_path, 
                                        stdin=PIPE, 
                                        stdout=PIPE, 
                                        stderr=PIPE,
                                        env=env)
        m_proc.communicate.assert_called_once_with(json.dumps(self.plugin.network_config))
        assert_equal(result, stdout)
开发者ID:grkvlt,项目名称:calico-cni,代码行数:34,代码来源:test_cni_plugin.py

示例5: test_main_kafka_dies

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import returncode [as 别名]
    def test_main_kafka_dies(self, mock_kafka_start, mock_kazoo):
        mock_popen = MagicMock(spec=Popen)
        mock_kafka_start.return_value = mock_popen
        mock_popen.returncode = -1

        main_return = main()

        self.assertEqual(-1, main_return)
        mock_kazoo.assert_not_called()
开发者ID:pebble,项目名称:docker-kafka,代码行数:11,代码来源:test_start.py

示例6: fake_subprocess

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import returncode [as 别名]
def fake_subprocess(stdout, stderr, returncode):
    proc = MagicMock()
    proc.returncode = returncode
    proc.communicate.return_value = (stdout, stderr)

    sub = MagicMock()
    sub.popen.return_value = proc

    return (sub, proc)
开发者ID:mvinesn,项目名称:sshm,代码行数:11,代码来源:test_lib.py

示例7: test_main_static

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import returncode [as 别名]
    def test_main_static(self, mock_conn_string, mock_kafka_start, mock_kazoo):
        mock_conn_string.return_value = []
        mock_popen = MagicMock(spec=Popen)
        mock_kafka_start.return_value = mock_popen
        mock_popen.returncode = None

        main_return = main(loops=1, loop_interval=0.001)

        self.assertEqual(0, main_return)
        mock_kazoo.assert_not_called()
开发者ID:pebble,项目名称:docker-kafka,代码行数:12,代码来源:test_start.py

示例8: test_run_cmd_str

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import returncode [as 别名]
 def test_run_cmd_str(self, m_Popen):
     m_pd = MagicMock()
     m_pd.returncode = 0
     stdout = b"stdout"
     stderr = b"stderr"
     m_pd.communicate.return_value = stdout, stderr
     m_Popen.return_value = m_pd
     a = module.Antivirus()
     res = a.run_cmd("/usr/bin/ls")
     m_Popen.assert_called_once_with(['/usr/bin/ls'],
                                     stderr=module.PIPE,
                                     stdout=module.PIPE)
     self.assertEquals(res, (0, "stdout", "stderr"))
开发者ID:quarkslab,项目名称:irma,代码行数:15,代码来源:test_base.py

示例9: test_run_cmd_list

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import returncode [as 别名]
 def test_run_cmd_list(self, m_Popen):
     m_pd = MagicMock()
     m_pd.returncode = 0
     stdout = b"stdout"
     stderr = b"stderr"
     m_pd.communicate.return_value = stdout, stderr
     m_Popen.return_value = m_pd
     a = module.Antivirus()
     res = a.run_cmd(["ls", "-la", "/tmp"])
     m_Popen.assert_called_once_with(['ls', '-la', '/tmp'],
                                     stderr=module.PIPE,
                                     stdout=module.PIPE)
     self.assertEquals(res, (0, "stdout", "stderr"))
开发者ID:quarkslab,项目名称:irma,代码行数:15,代码来源:test_base.py

示例10: update_job_test

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import returncode [as 别名]
    def update_job_test(self, mock_popen, mock_gjax):
        mock_popen_instance = MagicMock()
        mock_popen.return_value = mock_popen_instance

        mock_popen_instance.returncode = 0
        mock_popen_instance.communicate = MagicMock()

        mock_gjax.return_value = "job as xml"

        self.jenkins.update_job(self.job)

        assert mock_popen.called
        command = mock_popen.call_args[0][0]
        assert sorted(command) == sorted(self.jenkins.cli + [platform_ci.jenkins.PlatformJenkinsJavaCLI.UPDATE_JOB,
                                                             self.job.name])
        assert mock_gjax.called
        assert mock_popen_instance.communicate.called

        communicate = mock_popen_instance.communicate.call_args[1]
        assert communicate == {"input": mock_gjax.return_value}

        mock_popen_instance.returncode = 1
        assert_raises(platform_ci.jenkins.PlatformJenkinsException, self.jenkins.update_job, self.job)
开发者ID:gsr-shanks,项目名称:platform-ci,代码行数:25,代码来源:jenkins_test.py

示例11: test_prune_obsolete_builds_handle_script_error

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import returncode [as 别名]
    def test_prune_obsolete_builds_handle_script_error(self, test_pruner, mc_popen):
        mc_handle = MagicMock()
        mc_popen.return_value = mc_handle
        mc_handle.returncode = 1
        mc_handle.communicate.return_value = ("foo", "bar")

        # doesn't touch FS if `find_obsolete_build` produce error return code
        self.pruner.prune_obsolete_success_builds(os.path.join(self.tmp_dir_name, self.prj, self.chroots[0]))
        assert mc_popen.called

        assert_same_dirs(
            os.path.join(self.tmp_dir_name, self.prj, self.chroots[0]),
            os.path.join(self.expect_dir_name, self.prj, self.chroots[0]),
        )
开发者ID:danvratil,项目名称:copr,代码行数:16,代码来源:test_copr_prune_results.py

示例12: test_main_restart

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import returncode [as 别名]
    def test_main_restart(self, mock_conn_string, mock_kafka_start, mock_kazoo):
        mock_conn_string.side_effect = [
            ['1.1.1.1', '2.2.2.2'],
            ['2.2.2.2', '3.3.3.3']
        ]
        mock_popen = MagicMock(spec=Popen)
        mock_kafka_start.return_value = mock_popen
        mock_popen.returncode = None

        main_return = main(loops=1, loop_interval=0.001, restart_interval=0.001)

        self.assertEqual(0, main_return)
        mock_kazoo.assert_called_with(hosts=ANY)
        self.assertEqual(2, mock_kafka_start.call_count)
开发者ID:pebble,项目名称:docker-kafka,代码行数:16,代码来源:test_start.py

示例13: test_quality_error

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

        # Patch the output stderr/stdout and returncode of `pylint`

        _mock_communicate = patch.object(subprocess, 'Popen').start()
        subproc_mock = MagicMock()
        subproc_mock.returncode = 1
        subproc_mock.communicate.return_value = (b'file1.py:1: [C0111] Missing docstring', b'oops')
        _mock_communicate.return_value = subproc_mock

        # Parse the report
        quality = PylintQualityReporter('pylint', [])

        # Expect an error
        self.assertRaises(QualityReporterError, quality.violations, 'file1.py')
开发者ID:mblayman,项目名称:diff-cover,代码行数:17,代码来源:test_violations_reporter.py

示例14: test_callSnappy

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import returncode [as 别名]
def test_callSnappy():
    """
    Test pdinstall.snappy.callSnappy
    """
    from pdinstall.snappy import callSnappy

    with patch("pdinstall.snappy.subprocess") as subprocess:
        proc = MagicMock()
        subprocess.Popen.return_value = proc
        proc.stdout = ["Output message"]
        proc.stderr = ["Error message"]
        proc.returncode = 0

        assert callSnappy("install")
        assert proc.wait.called

        subprocess.Popen.side_effect = Exception("Boom!")
        assert callSnappy("install") is False
开发者ID:SejalChauhan,项目名称:Paradrop,代码行数:20,代码来源:test_snappy.py

示例15: test_quality_deprecation_warning

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

        # Patch the output stderr/stdout and returncode of `pylint`
        _mock_communicate = patch.object(subprocess, 'Popen').start()
        subproc_mock = MagicMock()
        # Pylint may raise deprecation warnings on pylint usage itself (such
        # as pylintrc configuration), but continue evaluating for violations.
        # Diff-quality, likewise, will continue.
        subproc_mock.returncode = 0
        subproc_mock.communicate.return_value = (
            b'file1.py:1: [C0111] Missing docstring\n'
            b'file1.py:1: [C0111, func_1] Missing docstring',
            b'Foobar: pylintrc deprecation warning'
        )
        _mock_communicate.return_value = subproc_mock

        # Parse the report
        quality = PylintQualityReporter('pylint', [])
        actual_violations = quality.violations('file1.py')

        # Assert that pylint successfully runs and finds 2 violations
        self.assertEqual(len(actual_violations), 2)
开发者ID:mblayman,项目名称:diff-cover,代码行数:24,代码来源:test_violations_reporter.py


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