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


Python Mock.returncode方法代码示例

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


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

示例1: test_run_job_no_watchdog

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import returncode [as 别名]
 def test_run_job_no_watchdog(self, m_tempfile, m_safe_dump, m_environ,
                              m_popen, m_t_config, m_symlink_log, m_sleep):
     config = {
         "suite_path": "suite/path",
         "config": {"foo": "bar"},
         "verbose": True,
         "owner": "the_owner",
         "archive_path": "archive/path",
         "name": "the_name",
         "description": "the_description",
         "worker_log": "worker/log.log"
     }
     m_tmp = MagicMock()
     temp_file = Mock()
     temp_file.name = "the_name"
     m_tmp.__enter__.return_value = temp_file
     m_tempfile.return_value = m_tmp
     env = dict(PYTHONPATH="python/path")
     m_environ.copy.return_value = env
     m_p = Mock()
     m_p.returncode = 1
     m_popen.return_value = m_p
     m_t_config.results_server = False
     worker.run_job(config, "teuth/bin/path")
     m_symlink_log.assert_called_with(config["worker_log"], config["archive_path"])
开发者ID:andrewschoen,项目名称:teuthology,代码行数:27,代码来源:test_worker.py

示例2: test_raises_stderr_on_failure

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import returncode [as 别名]
 def test_raises_stderr_on_failure(self, Popen):
     result = Mock()
     result.returncode = 1
     result.communicate.return_value = ('', 'error')
     Popen.return_value = result
     with self.assertRaises(AssetHandlerError):
         Exec().run('input')
开发者ID:excieve,项目名称:gears,代码行数:9,代码来源:test_exec_mixin.py

示例3: patch_popen

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import returncode [as 别名]
 def patch_popen(self, return_value=0):
     process = Mock()
     process.returncode = return_value
     process.communicate = Mock(return_value=('output', 'error output'))
     self.patch(
         provisioningserver.utils, 'Popen', Mock(return_value=process))
     return process
开发者ID:deepakhajare,项目名称:maas,代码行数:9,代码来源:test_utils.py

示例4: test_mysql_mode_locks_unlocks_tables

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import returncode [as 别名]
    def test_mysql_mode_locks_unlocks_tables(self, mock_create_dir, mock_get_lvm_info, mock_get_vol_fs_type, mock_popen):
        mock_get_vol_fs_type.return_value = 'xfs'
        mock_get_lvm_info.return_value = {
            'volgroup': 'lvm_volgroup',
            'srcvol': 'lvm_device',
            'snap_path': 'snap_path'}
        mock_process = Mock()
        mock_process.communicate.return_value = '', ''
        mock_process.returncode = 0
        mock_popen.return_value = mock_process

        backup_opt = Mock()
        backup_opt.snapshot = True
        backup_opt.lvm_auto_snap = ''
        backup_opt.path_to_backup = '/just/a/path'
        backup_opt.lvm_dirmount = '/var/mountpoint'
        backup_opt.lvm_snapperm = 'ro'
        backup_opt.mode = 'mysql'
        backup_opt.mysql_db_inst = Mock()
        mock_cursor = Mock()
        backup_opt.mysql_db_inst.cursor.return_value = mock_cursor

        self.assertTrue(lvm.lvm_snap(backup_opt))

        first_call = call('FLUSH TABLES WITH READ LOCK')
        second_call = call('UNLOCK TABLES')
        self.assertEquals(first_call, mock_cursor.execute.call_args_list[0])
        self.assertEquals(second_call, mock_cursor.execute.call_args_list[1])
开发者ID:sckevmit,项目名称:freezer,代码行数:30,代码来源:test_lvm.py

示例5: test_snapshot_mount_error_raises_Exception

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import returncode [as 别名]
    def test_snapshot_mount_error_raises_Exception(self,
                                                   mock_create_dir,
                                                   mock_get_lvm_info,
                                                   mock_get_vol_fs_type,
                                                   mock_popen,
                                                   mock_lvm_snap_remove):
        mock_get_vol_fs_type.return_value = 'xfs'
        mock_get_lvm_info.return_value = {
            'volgroup': 'lvm_volgroup',
            'srcvol': 'lvm_device',
            'snap_path': 'snap_path'}
        mock_lvcreate_process, mock_mount_process = Mock(), Mock()

        mock_lvcreate_process.communicate.return_value = '', ''
        mock_lvcreate_process.returncode = 0

        mock_mount_process.communicate.return_value = '', 'mount error'
        mock_mount_process.returncode = 1

        mock_popen.side_effect = [mock_lvcreate_process, mock_mount_process]

        backup_opt = Mock()
        backup_opt.snapshot = True
        backup_opt.lvm_auto_snap = ''
        backup_opt.path_to_backup = '/just/a/path'
        backup_opt.lvm_dirmount = '/var/mountpoint'
        backup_opt.lvm_snapperm = 'ro'

        with self.assertRaises(Exception) as cm:
            lvm.lvm_snap(backup_opt)
        the_exception = cm.exception
        self.assertIn('lvm snapshot mounting error', the_exception.message)

        mock_lvm_snap_remove.assert_called_once_with(backup_opt)
开发者ID:sckevmit,项目名称:freezer,代码行数:36,代码来源:test_lvm.py

示例6: test_downloadStream_should_timeout_on_stall

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import returncode [as 别名]
    def test_downloadStream_should_timeout_on_stall(self):
        ospatcher = patch("os.path.getsize")
        ospatcher.start()
        import os
        os.path.getsize = Mock()
        os.path.getsize.return_value = 1234

        patcher = patch("subprocess.Popen")
        patcher.start()
        import subprocess
        popen = Mock()
        communicate = Mock()
        communicate.communicate.return_value = ("", "filesize    1234568\n")
        communicate.returncode = None
        popen.return_value = communicate
        subprocess.Popen = popen
        sys.modules["__main__"].xbmcvfs.exists.return_value = True

        downloader = self.SimpleDownloader.SimpleDownloader()
        communicate.stdout.read.return_value = "out"
        downloader._showMessage = Mock()
        downloader._updateProgress = Mock()
        downloader._downloadStream("filename", {"videoid": "someid", "url": "rtmp://url", "Title": "some_title", "download_path": "some_path", "path_incomplete": "incomplete_path", "total_size": 12340.0, "cmd_call": ['rtmpdump', '-r', 'rtmp://url', '-o', 'incomplete_path']})

        ospatcher.stop()
        patcher.stop()

        result = popen.call_args_list[0][0][0]
        print repr(result)
        assert("rtmpdump" in result)
        assert("-r" in result)
        assert("rtmp://url" in result)
        assert("-o" in result)
        assert("incomplete_path" in result)
        assert(len(result) == 5)
开发者ID:HenrikDK,项目名称:xbmc-simple-downloader,代码行数:37,代码来源:TestSimpleDownloader.py

示例7: set_up

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import returncode [as 别名]
    def set_up(self):
        when(execution.LOGGER).info(ANY_ARGUMENTS).then_return(None)
        when(execution.LOGGER).error(ANY_ARGUMENTS).then_return(None)

        process_mock = Mock()
        process_mock.returncode = 0
        self.process_mock = process_mock
开发者ID:jcalta,项目名称:committer,代码行数:9,代码来源:execution_tests.py

示例8: test_failing_git_command

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import returncode [as 别名]
    def test_failing_git_command(self):
        """
        Make sure we properly wrap up any failing git commands in an exception
        """
        code = Code(self.build)

        proc_mock = Mock()
        proc_mock.returncode = 1
        response = Response(proc_mock, '', 'herp derp')
        code._command = Mock(return_value=response)
        code._which_git = Mock(return_value='lol')
        code.update()
开发者ID:plasticine,项目名称:henchman,代码行数:14,代码来源:test_code.py

示例9: test_which_git

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import returncode [as 别名]
    def test_which_git(self):
        """
        Ensure that we can locate the git binary. We should store the path to
        the git binary.
        """

        proc_mock = Mock()
        proc_mock.returncode = 0
        response = Response(proc_mock, '/usr/local/bin/git', '')
        code = Code(self.build)
        code._command = Mock(return_value=response)

        assert_equal(code._which_git(), '/usr/local/bin/git')
开发者ID:plasticine,项目名称:henchman,代码行数:15,代码来源:test_code.py

示例10: _mock_uploader_modules

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import returncode [as 别名]
    def _mock_uploader_modules(self, emulate_success):
        self.mock_dict = {}

        popen_mock = Mock()
        popen_mock.communicate.return_value = ("scp_out dump", "scp_err dump")

        if emulate_success:
            popen_mock.returncode = 0
        else:
            popen_mock.returncode = 1

        subprocess_mock = Mock()
        subprocess_mock.Popen.return_value = popen_mock
        subprocess_mock.PIPE = "MYPIPE"

        tempfile_mock = Mock()
        tempfile_mock.mkstemp.return_value = ("my_handle", "my_tempfile_name")


        self.mock_dict["tempfile"]   = tempfile_mock
        self.mock_dict["subprocess"] = subprocess_mock
        self.mock_dict["os"]         = Mock()

        self.DPMS.module_uploader.modules = self.mock_dict
开发者ID:blazetopher,项目名称:coi-services,代码行数:26,代码来源:test_register_process_definition.py

示例11: setUp

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import returncode [as 别名]
    def setUp(self):
        mock_host_rpm_builder = Mock(HostRpmBuilder)
        mock_host_rpm_builder.hostname = 'berweb01'
        mock_host_rpm_builder.thread_name = 'thread-0'
        mock_host_rpm_builder.logger = Mock()
        mock_host_rpm_builder.work_dir = '/path/to/working/directory'
        mock_host_rpm_builder.rpm_build_dir = '/path/to/rpm/build/directory'
        mock_host_rpm_builder._tar_sources.return_value = '/path/to/tarred_sources.tar.gz'

        mock_process = Mock()
        mock_process.communicate.return_value = ('stdout', 'stderr')
        mock_process.returncode = 0

        self.mock_host_rpm_builder = mock_host_rpm_builder
        self.mock_process = mock_process
开发者ID:yadt,项目名称:yadt-config-rpm-maker,代码行数:17,代码来源:hostrpmbuilder_test.py

示例12: test_run_success

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import returncode [as 别名]
    def test_run_success(self, monkeypatch):
        job = DoitUnstableNoContinue(DODO_FILE, 't1', THIS_PATH)
        doit_result = SAMPLE_RESULT
        mock_result = Mock(return_value=doit_result)
        monkeypatch.setattr(job, "read_json_result", mock_result)
        mock_process = Mock()
        mock_process.returncode = 0 # success (ignore failed on data)

        yi = job.run()
        # 1) execute first time
        (run1, pause1) = yi.next()
        assert isinstance(run1, ProcessTask)
        assert 'run' in run1.cmd
        assert isinstance(pause1, TaskPause)
        run1.proc = mock_process
        py.test.raises(StopIteration, yi.next)
开发者ID:pombredanne,项目名称:serveronduty,代码行数:18,代码来源:test_taskdoit.py

示例13: test_run_error

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import returncode [as 别名]
    def test_run_error(self, monkeypatch):
        job = DoitUnstableNoContinue(DODO_FILE, 't1', THIS_PATH)
        doit_result = None
        mock_result = Mock(return_value=doit_result)
        monkeypatch.setattr(job, "read_json_result", mock_result)
        mock_process = Mock()
        mock_process.returncode = 1

        yi = job.run()
        # 1) execute first time
        (run1, pause1) = yi.next()
        run1.proc = mock_process
        # 2) try again
        (run2, pause2) = yi.next()
        run2.proc = mock_process
        # 3 give-up
        py.test.raises(StopIteration, yi.next)
开发者ID:pombredanne,项目名称:serveronduty,代码行数:19,代码来源:test_taskdoit.py

示例14: test_using_mount

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import returncode [as 别名]
    def test_using_mount(self, mock_get_mount_from_path, mock_lvm_guess, mock_popen):
        mock_get_mount_from_path.return_value = '/home/somedir', 'some-snap-path'
        mock_lvm_guess.side_effect = [(None, None, None), ('vg_test', 'lv_test', 'lvm_device')]
        mounts = ('/dev/mapper/vg_prova-lv_prova_vol1 /home/pippo ext4 rw,relatime,data=ordered 0 0')
        mocked_open_function = mock_open(read_data=mounts)
        mock_process = Mock()
        mock_process.returncode = 0
        mock_popen.return_value = mock_process
        mock_process.communicate.return_value = '', ''

        with patch("__builtin__.open", mocked_open_function):
            res = lvm.get_lvm_info('lvm_auto_snap_value')

        expected_result = {'volgroup': 'vg_test',
                           'snap_path': 'some-snap-path',
                           'srcvol': 'lvm_device'}
        self.assertEquals(res, expected_result)
开发者ID:sckevmit,项目名称:freezer,代码行数:19,代码来源:test_lvm.py

示例15: test_recoverable_error

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import returncode [as 别名]
 def test_recoverable_error(self, mock_popen):
     mock_popen_instance = Mock()
     mock_popen_instance.communicate.return_value = ("stdout", "stderr")
     mock_popen_instance.returncode = 0
     mock_popen.return_value = mock_popen_instance
     self.aptd._call_apport_recoverable_error(
         "msg", "traceback-error", "custom:dupes:signature")
     mock_popen.assert_called_with(
         [APPORT_RECOVERABLE_ERROR], stdin=subprocess.PIPE, 
         stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     # check that we really send the right data 
     args, kwargs = mock_popen_instance.communicate.call_args
     self.assertEqual(
         kwargs["input"].split("\0"),
         [ 'DialogBody', 'msg',
           'Traceback', 'traceback-error',
           'DuplicateSignature', 'custom:dupes:signature',
         ])
开发者ID:pombredanne,项目名称:shop,代码行数:20,代码来源:test_aptd.py


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