当前位置: 首页>>代码示例>>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;未经允许,请勿转载。