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


Python mock.Mock方法代碼示例

本文整理匯總了Python中mock.mock.Mock方法的典型用法代碼示例。如果您正苦於以下問題:Python mock.Mock方法的具體用法?Python mock.Mock怎麽用?Python mock.Mock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在mock.mock的用法示例。


在下文中一共展示了mock.Mock方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_time_measure

# 需要導入模塊: from mock import mock [as 別名]
# 或者: from mock.mock import Mock [as 別名]
def test_time_measure():
    T = 1.2
    measurable = mock.Mock()
    reader = mock.Mock()
    reader.diagnostics.side_effect = {'some_diags': 1}
    wait_times = [0.0, T, T]

    def mock_next_item():
        a = 1
        for _ in six.moves.xrange(10000):
            a += 1
        sleep(wait_times.pop(0))
        return 0

    measurable.next_item.side_effect = mock_next_item
    result = _time_warmup_and_work(reader, 1, 2, measurable.next_item)
    assert result.time_mean >= T / 2.0
    assert result.samples_per_second < 1.0 / T
    assert result.memory_info 
開發者ID:uber,項目名稱:petastorm,代碼行數:21,代碼來源:test_benchmark.py

示例2: _mock_parquet_dataset

# 需要導入模塊: from mock import mock [as 別名]
# 或者: from mock.mock import Mock [as 別名]
def _mock_parquet_dataset(partitions, arrow_schema):
    """Creates a pyarrow.ParquetDataset mock capable of returning:

        parquet_dataset.pieces[0].get_metadata(parquet_dataset.fs.open).schema.to_arrow_schema() == schema
        parquet_dataset.partitions = partitions

    :param partitions: expected to be a list of pa.parquet.PartitionSet
    :param arrow_schema: an instance of pa.arrow_schema to be assumed by the mock parquet dataset object.
    :return:
    """
    piece_mock = mock.Mock()
    piece_mock.get_metadata().schema.to_arrow_schema.return_value = arrow_schema

    dataset_mock = mock.Mock()
    type(dataset_mock).pieces = mock.PropertyMock(return_value=[piece_mock])
    type(dataset_mock).partitions = partitions

    return dataset_mock 
開發者ID:uber,項目名稱:petastorm,代碼行數:20,代碼來源:test_unischema.py

示例3: setUp

# 需要導入模塊: from mock import mock [as 別名]
# 或者: from mock.mock import Mock [as 別名]
def setUp(self):
        self.request = Mock(name='request')
        self.request.args = {}
        self.request.base_url = 'http://puncover.com'
        self.request.blueprint = None

        def url_adapter_func(url, *args, **kwargs):
            return url

        reqctx = Mock(name='reqctx')
        reqctx.request = self.request
        reqctx.url_adapter = Mock(name='url_adapter')
        reqctx.url_adapter.build = Mock(side_effect=url_adapter_func)
        globals._request_ctx_stack.push(reqctx)

        self.appctx = Mock(name='appctx')
        globals._app_ctx_stack.push(self.appctx) 
開發者ID:HBehrens,項目名稱:puncover,代碼行數:19,代碼來源:test_renderer.py

示例4: test_sorted_filter_code

# 需要導入模塊: from mock import mock [as 別名]
# 或者: from mock.mock import Mock [as 別名]
def test_sorted_filter_code(self):
        ctx = Mock()
        ctx.parent = {'sort': 'code_asc'}
        a = {'type': 'folder', 'sub_folders': [], 'files': [
        ]}
        b = {'type': 'file', 'symbols': [
            {'type': 'function', 'size': 200}
        ]}
        c = {'type': 'file', 'symbols': [
            {'type': 'function', 'size': 300}
        ]}
        actual = renderers.sorted_filter(ctx, [b, c, a])

        self.assertEqual([a, b, c], actual)

        ctx.parent = {'sort': 'code_desc'}
        actual = renderers.sorted_filter(ctx, [b, c, a])
        self.assertEqual([c, b, a], actual) 
開發者ID:HBehrens,項目名稱:puncover,代碼行數:20,代碼來源:test_renderer.py

示例5: test_sorted_filter_vars

# 需要導入模塊: from mock import mock [as 別名]
# 或者: from mock.mock import Mock [as 別名]
def test_sorted_filter_vars(self):
        ctx = Mock()
        ctx.parent = {'sort': 'vars_asc'}
        a = {'type': 'folder', 'sub_folders': [], 'files': [
        ]}
        b = {'type': 'file', 'symbols': [
            {'type': 'variable', 'size': 200}
        ]}
        c = {'type': 'file', 'symbols': [
            {'type': 'variable', 'size': 300}
        ]}
        actual = renderers.sorted_filter(ctx, [b, c, a])

        self.assertEqual([a, b, c], actual)

        ctx.parent = {'sort': 'vars_desc'}
        actual = renderers.sorted_filter(ctx, [b, c, a])
        self.assertEqual([c, b, a], actual) 
開發者ID:HBehrens,項目名稱:puncover,代碼行數:20,代碼來源:test_renderer.py

示例6: test_sorted_filter_stack

# 需要導入模塊: from mock import mock [as 別名]
# 或者: from mock.mock import Mock [as 別名]
def test_sorted_filter_stack(self):
        ctx = Mock()
        ctx.parent = {'sort': 'stack_asc'}
        a = {'type': 'folder', 'sub_folders': [], 'files': [
        ]}
        b = {'type': 'file', 'symbols': [
            {'type': 'function', 'stack_size': 200}
        ]}
        c = {'type': 'file', 'symbols': [
            {'type': 'function', 'stack_size': 300}
        ]}
        actual = renderers.sorted_filter(ctx, [b, c, a])

        self.assertEqual([a, b, c], actual)

        ctx.parent = {'sort': 'stack_desc'}
        actual = renderers.sorted_filter(ctx, [b, c, a])
        self.assertEqual([c, b, a], actual) 
開發者ID:HBehrens,項目名稱:puncover,代碼行數:20,代碼來源:test_renderer.py

示例7: test_col_sortable_filter_stack

# 需要導入模塊: from mock import mock [as 別名]
# 或者: from mock.mock import Mock [as 別名]
def test_col_sortable_filter_stack(self):
        ctx = Mock()
        ctx.parent = {}
        self.request.args = {'foo': 'bar'}

        expected = '<a href="http://puncover.com?foo=bar&sort=stack_asc" class="sortable">Stack</a>'
        actual = renderers.col_sortable_filter(ctx, 'Stack', True)
        self.assertEqual(expected, actual)

        # if current sort is ascending,
        # mark as sorted ascending and populate link for descending
        ctx.parent = {'sort': 'stack_asc'}
        self.request.args = {'sort': 'foo'}
        expected = '<a href="http://puncover.com?sort=stack_desc" class="sortable sort_asc_alpha">Stack</a>'
        actual = renderers.col_sortable_filter(ctx, 'Stack', True)
        self.assertEqual(expected, actual) 
開發者ID:HBehrens,項目名稱:puncover,代碼行數:18,代碼來源:test_renderer.py

示例8: test_platform_path_added

# 需要導入模塊: from mock import mock [as 別名]
# 或者: from mock.mock import Mock [as 別名]
def test_platform_path_added():
    '''
    Ensure /platform is added when legacy_upload is false
    Ensure it's not added when legacy_upload is true
    '''
    # auto_config=True, legacy_upload=True
    config = Mock(base_url='test.satellite.com:443/redhat_access/r/insights', auto_config=True, legacy_upload=True, offline=False)
    try_auto_configuration(config)
    assert config.base_url == 'test.satellite.com:443/redhat_access/r/insights'

    # auto_config=True, legacy_upload=False
    config = Mock(base_url='test.satellite.com:443/redhat_access/r/insights', auto_config=True, legacy_upload=False, offline=False)
    try_auto_configuration(config)
    assert config.base_url == 'test.satellite.com:443/redhat_access/r/insights/platform'

    # auto_config=False, legacy_upload=True
    config = Mock(base_url='test.satellite.com:443/redhat_access/r/insights', auto_config=False, legacy_upload=True, offline=False)
    try_auto_configuration(config)
    assert config.base_url == 'test.satellite.com:443/redhat_access/r/insights'

    # auto_config=False, legacy_upload=False
    config = Mock(base_url='test.satellite.com:443/redhat_access/r/insights', auto_config=False, legacy_upload=False, offline=False)
    try_auto_configuration(config)
    assert config.base_url == 'test.satellite.com:443/redhat_access/r/insights/platform' 
開發者ID:RedHatInsights,項目名稱:insights-core,代碼行數:26,代碼來源:test_autoconfig_urls.py

示例9: test_registration_check_ok_unreg

# 需要導入模塊: from mock import mock [as 別名]
# 或者: from mock.mock import Mock [as 別名]
def test_registration_check_ok_unreg(get_proxies, _init_session, _):
    '''
    Request completed OK, has not been registered
        Returns False
    '''
    config = Mock(legacy_upload=False, base_url='example.com')
    conn = InsightsConnection(config)

    res = requests.Response()
    res._content = json.dumps(
        {
            "count": 0,
            "page": 1,
            "per_page": 50,
            "results": [],
            "total": 0
        })
    res.status_code = 200

    conn.session.get = MagicMock(return_value=res)
    assert conn.api_registration_check() is False 
開發者ID:RedHatInsights,項目名稱:insights-core,代碼行數:23,代碼來源:test_reg_check.py

示例10: test_proxy_request

# 需要導入模塊: from mock import mock [as 別名]
# 或者: from mock.mock import Mock [as 別名]
def test_proxy_request(init, session):
    """
    If proxy authentication is enabled, the failing hacky request is issued with correct timeout set.
    """
    config = Mock()

    # The constructor is bypassed, because it itself runs the _init_session method.
    connection = InsightsConnection(None)
    connection.config = config
    connection.systemid = None
    connection.authmethod = "BASIC"
    connection.username = "some username"
    connection.password = "some password"
    connection.cert_verify = None
    connection.proxies = {"https": "some proxy"}
    connection.proxy_auth = True
    connection.base_url = 'https://cert-api.access.redhat.com/r/insights'

    connection._init_session()

    session.return_value.request.assert_called_once_with(
        "GET",
        "https://cert-api.access.redhat.com/r/insights",
        timeout=config.http_timeout
    ) 
開發者ID:RedHatInsights,項目名稱:insights-core,代碼行數:27,代碼來源:test_init_session.py

示例11: test_run

# 需要導入模塊: from mock import mock [as 別名]
# 或者: from mock.mock import Mock [as 別名]
def test_run(self, localclient, runner, mm):
        rebuild.__opts__ = {}

        rr = rebuild.Rebuild(['data*.ceph'])
        rr._disengaged = mock.Mock()
        rr._disengaged.return_value = True
        rr.minions = ['data1.ceph']
        rr._osd_list = mock.Mock()
        rr._osd_list.return_value = [0, 1]
        rr.safe = mock.Mock()
        rr.safe.return_value = True
        rr._busy_wait = mock.Mock()
        rr.runner.cmd = mock.Mock()
        rr.runner.cmd.return_value = {}
        rr._check_failed = mock.Mock()
        rr._check_failed.return_value = False
        rr._skipped_summary = mock.Mock()

        result = rr.run()
        assert result == ""
        assert rr._osd_list.called
        assert rr.safe.called
        assert rr.runner.cmd.called
        assert rr._check_failed.called
        assert rr._skipped_summary.called 
開發者ID:SUSE,項目名稱:DeepSea,代碼行數:27,代碼來源:test_rebuild.py

示例12: test_run_multiple

# 需要導入模塊: from mock import mock [as 別名]
# 或者: from mock.mock import Mock [as 別名]
def test_run_multiple(self, localclient, runner, mm):
        rebuild.__opts__ = {}

        rr = rebuild.Rebuild(['data*.ceph'])
        rr._disengaged = mock.Mock()
        rr._disengaged.return_value = True
        rr.minions = ['data1.ceph', 'data2.ceph']
        rr._osd_list = mock.Mock()
        rr._osd_list.return_value = [0, 1]
        rr.safe = mock.Mock()
        rr.safe.return_value = True
        rr._busy_wait = mock.Mock()
        rr.runner.cmd = mock.Mock()
        rr.runner.cmd.return_value = {}
        rr._check_failed = mock.Mock()
        rr._check_failed.return_value = False
        rr._skipped_summary = mock.Mock()

        result = rr.run()
        assert result == ""
        assert rr._osd_list.call_count == 2
        assert rr.safe.call_count == 2
        assert rr.runner.cmd.call_count == 4
        assert rr._check_failed.call_count == 2
        assert rr._skipped_summary.called 
開發者ID:SUSE,項目名稱:DeepSea,代碼行數:27,代碼來源:test_rebuild.py

示例13: test_run_check_only

# 需要導入模塊: from mock import mock [as 別名]
# 或者: from mock.mock import Mock [as 別名]
def test_run_check_only(self, localclient, runner, mm):
        rebuild.__opts__ = {}

        rr = rebuild.Rebuild(['data*.ceph'])
        rr._disengaged = mock.Mock()
        rr._disengaged.return_value = True
        rr.minions = ['data1.ceph']
        rr._osd_list = mock.Mock()
        rr._osd_list.return_value = [0, 1]
        rr.safe = mock.Mock()
        rr.safe.return_value = True
        rr.runner.cmd = mock.Mock()
        rr.runner.cmd.return_value = {}
        rr._check_failed = mock.Mock()
        rr._check_failed.return_value = False
        rr._skipped_summary = mock.Mock()

        result = rr.run(checkonly=True)
        assert result == ""
        assert rr._osd_list.called
        assert rr.safe.called
        assert rr.runner.cmd.called is False
        assert rr._check_failed.called is False
        assert rr._skipped_summary.called 
開發者ID:SUSE,項目名稱:DeepSea,代碼行數:26,代碼來源:test_rebuild.py

示例14: test_run_no_remove

# 需要導入模塊: from mock import mock [as 別名]
# 或者: from mock.mock import Mock [as 別名]
def test_run_no_remove(self, localclient, runner, mm):
        rebuild.__opts__ = {}

        rr = rebuild.Rebuild(['data*.ceph'])
        rr._disengaged = mock.Mock()
        rr._disengaged.return_value = True
        rr.minions = ['data1.ceph']
        rr._osd_list = mock.Mock()
        rr._osd_list.return_value = []
        rr.safe = mock.Mock()
        rr.safe.return_value = True
        rr.runner.cmd = mock.Mock()
        rr.runner.cmd.return_value = {}
        rr._check_failed = mock.Mock()
        rr._check_failed.return_value = False
        rr._skipped_summary = mock.Mock()

        result = rr.run()
        assert result == ""
        assert rr._osd_list.called
        assert rr.safe.called is False
        assert rr.runner.cmd.called
        assert rr._check_failed.called is False
        assert rr._skipped_summary.called 
開發者ID:SUSE,項目名稱:DeepSea,代碼行數:26,代碼來源:test_rebuild.py

示例15: test_run_not_safe

# 需要導入模塊: from mock import mock [as 別名]
# 或者: from mock.mock import Mock [as 別名]
def test_run_not_safe(self, localclient, runner, mm):
        rebuild.__opts__ = {}

        rr = rebuild.Rebuild(['data*.ceph'])
        rr._disengaged = mock.Mock()
        rr._disengaged.return_value = True
        rr.minions = ['data1.ceph']
        rr._osd_list = mock.Mock()
        rr._osd_list.return_value = [0, 1]
        rr.safe = mock.Mock()
        rr.safe.return_value = False
        rr.runner.cmd = mock.Mock()
        rr.runner.cmd.return_value = {}
        rr._check_failed = mock.Mock()
        rr._check_failed.return_value = False
        rr._skipped_summary = mock.Mock()

        result = rr.run()
        assert result == ""
        assert rr._osd_list.called
        assert rr.safe.called
        assert rr.runner.cmd.called is False
        assert rr._check_failed.called is False
        assert rr._skipped_summary.called is False 
開發者ID:SUSE,項目名稱:DeepSea,代碼行數:26,代碼來源:test_rebuild.py


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