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


Python Mock.type方法代码示例

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


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

示例1: test_type_filters

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import type [as 别名]
def test_type_filters():
    axon = Mock()
    axon.type = NeuriteType.axon
    nt.ok_(axon_filter(axon))
    nt.ok_(not dendrite_filter(axon))

    basal_dendrite = Mock()
    basal_dendrite.type = NeuriteType.basal_dendrite
    nt.ok_(not axon_filter(basal_dendrite))
    nt.ok_(dendrite_filter(basal_dendrite))

    apical_dendrite = Mock()
    apical_dendrite.type = NeuriteType.apical_dendrite
    nt.ok_(not axon_filter(apical_dendrite))
    nt.ok_(dendrite_filter(apical_dendrite))
开发者ID:BlueBrain,项目名称:NeuroM,代码行数:17,代码来源:test_types.py

示例2: test_no_listed_version_reviewer

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import type [as 别名]
    def test_no_listed_version_reviewer(self):
        user = user_factory()
        self.grant_permission(user, 'Addons:Review')
        obj = Mock(spec=[])
        obj.type = amo.ADDON_EXTENSION
        obj.has_listed_versions = lambda: False

        for method in self.safe_methods:
            request = getattr(self.request_factory, method)('/')
            request.user = user

            # When not checking the object, we have permission because we're
            # authenticated.
            assert self.permission.has_permission(request, myview)

            # It doesn't work with the object though, since
            # has_listed_versions() is returning False, we don't have enough
            # permissions, being a "simple" reviewer.
            assert not self.permission.has_object_permission(
                request, myview, obj)

        for method in self.unsafe_methods:
            request = getattr(self.request_factory, method)('/')
            request.user = user

            # When not checking the object, we have permission because we're
            # authenticated.
            assert self.permission.has_permission(request, myview)

            # As above it doesn't work with the object though.
            assert not self.permission.has_object_permission(
                request, myview, obj)
开发者ID:eviljeff,项目名称:olympia,代码行数:34,代码来源:test_permissions.py

示例3: test_create

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import type [as 别名]
    def test_create(self, mock_build, *args):
        rel = Mock()
        rel.type = 'cloudify.gcp.relationships.contained_in_network'
        rel.target.node.type = 'cloudify.gcp.nodes.Network'
        rel.target.node.properties = {
                'auto_subnets': False,
                }
        rel.target.instance.runtime_properties = {
                'selfLink': 'Look at me!',
                }
        self.ctxmock.instance.relationships.append(rel)
        self.ctxmock.node.properties.update({
            'use_external_resource': False,
            'subnet': 'Toki Tori',
            })

        subnetwork.create(
                name='subnet name',
                region='Bukit Bintang',
                subnet='Token Ring',
                )

        mock_build().subnetworks().insert.assert_called_once_with(
                body={
                    'ipCidrRange': 'Token Ring',
                    'network': 'Look at me!',
                    'name': 'subnetname',
                    'description': 'Cloudify generated subnetwork',
                    },
                project='not really a project',
                region='Bukit Bintang',
                )
开发者ID:funkyHat,项目名称:cloudify-gcp-plugin,代码行数:34,代码来源:test_subnetwork.py

示例4: test_onError

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import type [as 别名]
    def test_onError(self, log):
        error = Mock()
        error.type = "test"
        e = self.plugin.onError(error, sentinel.anything)

        self.assertEquals(len(e['events']), 1)
        self.assertEquals(e['events'][0]['severity'], ZenEventClasses.Error)
开发者ID:damienstuart,项目名称:ZenPacks.zenoss.AWS,代码行数:9,代码来源:test_dsplugins.py

示例5: test_fsync2

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import type [as 别名]
    def test_fsync2(self):
        file = "/dir1/dir2/file"
        testfs = vofs.VOFS(self.testMountPoint, self.testCacheDir, opt)

        testfs.client = Object()
        node = Mock(spec=vos.Node)
        node.isdir = Mock(return_value=False)
        node.props = Object
        node.props.get = Mock(side_effect=SideEffect({
            ('islocked', False): False,
            ('length',): 10,
            ('MD5',): 12354,
        }, name="node.props.get"))
        node.type = "vos:DataNode"
        testfs.client.get_node = Mock(return_value=node)
        # Try flushing on a read-only file.
        with patch('vofs.CadcCache.FileHandle') as mockFileHandle:
            mockFileHandle.return_value = MyFileHandle(
                file, testfs.cache, None)
            fh = testfs.open(file, os.O_RDONLY, None)
            self.assertFalse(HandleWrapper.file_handle(fh).cache_file_handle.
                             fileModified)
            HandleWrapper.file_handle(fh).cache_file_handle.fsync = \
                Mock(wraps=HandleWrapper.file_handle(fh).cache_file_handle.
                     fsync)
            with self.assertRaises(FuseOSError) as e:
                testfs.fsync(file, False, fh)
            self.assertEqual(e.exception.errno, EPERM)
            self.assertEqual(HandleWrapper.file_handle(fh).cache_file_handle.
                             fsync.call_count, 0)
            self.assertFalse(HandleWrapper.file_handle(fh).cache_file_handle.
                             fileModified)

            testfs.release(file, fh)

        # Try with an invalid file descriptor
        with self.assertRaises(FuseOSError) as e:
            testfs.fsync(file, False, -1)
        self.assertEqual(e.exception.errno, EIO)

        # Try flushing on a read-only file system.
        with patch('vofs.CadcCache.FileHandle') as mockFileHandle:
            myopt = copy.copy(opt)
            testfs = vofs.VOFS(self.testMountPoint, self.testCacheDir, myopt)
            mockFileHandle.return_value = MyFileHandle(
                file, testfs.cache, None)
            myopt.readonly = True
            testfs.client = Object()
            testfs.client.get_node = Mock(return_value=node)
            fh = testfs.open(file, os.O_RDONLY, None)
            HandleWrapper.file_handle(fh).cache_file_handle.fsync = \
                Mock(wraps=HandleWrapper.file_handle(fh).cache_file_handle.
                     fsync)
            testfs.fsync(file, False, fh)
            self.assertEqual(
                HandleWrapper.file_handle(fh).cache_file_handle.fsync.
                call_count, 0)
            testfs.release(file, fh)
开发者ID:canfar,项目名称:vos,代码行数:60,代码来源:test_vofs.py

示例6: test_anchor

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import type [as 别名]
    def test_anchor(self):
        target = Mock()
        target.type = "node"

        source = Mock()
        source.type = "node"

        relation = Mock()
        relation.type = "edge"

        # given two node objects connected by an edge object
        
        target.name = "target"
        source.name = "source"

        properties = {"source-object": "source", "target-object": "target"}

        def getitem(name):
            return properties[name]

        relation.__getitem__ = Mock(side_effect=getitem)
        relation.name = "relation"

        # added to diagram

        self.diagram.add(relation)
        self.diagram.add(target)
        self.diagram.add(source)

        # when anchors are set 

        self.diagram.set_anchors()

        # each DrawableNode object should be referenced by proper DrawableEdge object's anchors
        drawable_relation = self.diagram.edges["relation"]
        drawable_source = self.diagram.nodes["source"]
        drawable_target = self.diagram.nodes["target"]

        self.assertEquals(drawable_source, drawable_relation.source_anchor.slot)
        self.assertEquals(drawable_target, drawable_relation.target_anchor.slot)

        # and each DrawableNode object's anchor should reference the
        # DrawableEdge object
        self.assertEquals(drawable_relation, drawable_source.anchors.pop().connector)
        self.assertEquals(drawable_relation, drawable_target.anchors.pop().connector)
开发者ID:barnaba,项目名称:omelette,代码行数:47,代码来源:test_diagram.py

示例7: test_authenticated_but_not_reviewer

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import type [as 别名]
 def test_authenticated_but_not_reviewer(self):
     request = self.request_factory.get('/')
     request.user = user_factory()
     obj = Mock(spec=[])
     obj.type = amo.ADDON_EXTENSION
     obj.has_listed_versions = lambda: True
     assert self.permission.has_permission(request, myview)
     assert not self.permission.has_object_permission(
         request, myview, obj)
开发者ID:eviljeff,项目名称:olympia,代码行数:11,代码来源:test_permissions.py

示例8: setUp

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import type [as 别名]
    def setUp(self):
        super(TestGCPRecord, self).setUp()

        rel = Mock()
        rel.type = 'cloudify.gcp.relationships.dns_record_contained_in_zone'
        rel.target.instance.runtime_properties = {
                'name': 'target instance',
                'dnsName': 'example.com.',
                }
        self.ctxmock.instance.relationships = [rel]
开发者ID:funkyHat,项目名称:cloudify-gcp-plugin,代码行数:12,代码来源:test_record.py

示例9: test_populate_database_non_existent_model

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import type [as 别名]
    def test_populate_database_non_existent_model(self):
        # given
        item = Mock()
        item.type = 'random'
        item.properties = ['']
        items = [item]

        # then
        with self.assertRaises(NonExistentModelException):
            populate_database(items)
开发者ID:jrm2k6,项目名称:jeremydagorn-blog,代码行数:12,代码来源:test_parse_file.py

示例10: test_user_cannot_be_anonymous

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import type [as 别名]
    def test_user_cannot_be_anonymous(self):
        request = self.request_factory.get('/')
        request.user = AnonymousUser()
        obj = Mock(spec=[])
        obj.type = amo.ADDON_EXTENSION
        obj.has_listed_versions = lambda: True

        assert not self.permission.has_permission(request, myview)
        assert not self.permission.has_object_permission(
            request, myview, obj)
开发者ID:eviljeff,项目名称:olympia,代码行数:12,代码来源:test_permissions.py

示例11: test_alert_should_be_ignored_when_subscription_says_so

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import type [as 别名]
    def test_alert_should_be_ignored_when_subscription_says_so(self):
        before = datetime(2010, 1, 1, 23, 59, 0)
        later = datetime(2010, 1, 2, 0, 0, 0)

        qd_alert = Mock()
        qd_alert.alert.history.end_time = before

        sub = Mock()
        sub.ignored_resolved_alerts = True
        sub.type = AlertSubscription.DAILY

        self.assertTrue(alert_should_be_ignored(qd_alert, sub, later))
开发者ID:alexanderfefelov,项目名称:nav,代码行数:14,代码来源:accountalertqueue_test.py

示例12: test_tree_type_checker

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import type [as 别名]
def test_tree_type_checker():
    #check that when NeuriteType.all, we accept all trees, w/o checking type
    tree_filter = tree_type_checker(NeuriteType.all)
    nt.ok_(tree_filter('fake_tree'))

    mock_tree = Mock()
    mock_tree.type = NeuriteType.axon

    #single arg
    tree_filter = tree_type_checker(NeuriteType.axon)
    nt.ok_(tree_filter(mock_tree))

    mock_tree.type = NeuriteType.basal_dendrite
    nt.ok_(not tree_filter(mock_tree))

    #multiple args
    tree_filter = tree_type_checker(NeuriteType.axon, NeuriteType.basal_dendrite)
    nt.ok_(tree_filter(mock_tree))

    tree_filter = tree_type_checker(*NEURITES)
    nt.ok_(tree_filter('fake_tree'))
开发者ID:jdcourcol,项目名称:NeuroM,代码行数:23,代码来源:test_types.py

示例13: test_populate_database_add_technology

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import type [as 别名]
    def test_populate_database_add_technology(self):
        # given
        item = Mock()
        item.type = 'technology'
        item.properties = ['techno_txt']
        items = [item]

        # when
        populate_database(items)

        # then
        self.assert_technology_with_name_exists_in_database(item.properties[0])
开发者ID:jrm2k6,项目名称:jeremydagorn-blog,代码行数:14,代码来源:test_parse_file.py

示例14: test_populate_database_add_user

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import type [as 别名]
    def test_populate_database_add_user(self):
        # given
        item = Mock()
        item.type = 'user'
        item.properties = ['bob', '[email protected]', 'bobpw']
        items = [item]

        # when
        populate_database(items)

        # then
        self.assert_user_with_username_exists_in_database(item.properties[0])
开发者ID:jrm2k6,项目名称:jeremydagorn-blog,代码行数:14,代码来源:test_parse_file.py

示例15: test_get_df_handles_dttm_col

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import type [as 别名]
    def test_get_df_handles_dttm_col(self):
        form_data = {'dummy': 123}
        query_obj = {'granularity': 'day'}
        results = Mock()
        results.query = Mock()
        results.status = Mock()
        results.error_message = Mock()
        datasource = Mock()
        datasource.type = 'table'
        datasource.query = Mock(return_value=results)
        mock_dttm_col = Mock()
        datasource.get_col = Mock(return_value=mock_dttm_col)

        test_viz = viz.BaseViz(datasource, form_data)
        test_viz.df_metrics_to_num = Mock()
        test_viz.get_fillna_for_columns = Mock(return_value=0)

        results.df = pd.DataFrame(data={DTTM_ALIAS: ['1960-01-01 05:00:00']})
        datasource.offset = 0
        mock_dttm_col = Mock()
        datasource.get_col = Mock(return_value=mock_dttm_col)
        mock_dttm_col.python_date_format = 'epoch_ms'
        result = test_viz.get_df(query_obj)
        print(result)
        import logging
        logging.info(result)
        pd.testing.assert_series_equal(
            result[DTTM_ALIAS],
            pd.Series([datetime(1960, 1, 1, 5, 0)], name=DTTM_ALIAS),
        )

        mock_dttm_col.python_date_format = None
        result = test_viz.get_df(query_obj)
        pd.testing.assert_series_equal(
            result[DTTM_ALIAS],
            pd.Series([datetime(1960, 1, 1, 5, 0)], name=DTTM_ALIAS),
        )

        datasource.offset = 1
        result = test_viz.get_df(query_obj)
        pd.testing.assert_series_equal(
            result[DTTM_ALIAS],
            pd.Series([datetime(1960, 1, 1, 6, 0)], name=DTTM_ALIAS),
        )

        datasource.offset = 0
        results.df = pd.DataFrame(data={DTTM_ALIAS: ['1960-01-01']})
        mock_dttm_col.python_date_format = '%Y-%m-%d'
        result = test_viz.get_df(query_obj)
        pd.testing.assert_series_equal(
            result[DTTM_ALIAS],
            pd.Series([datetime(1960, 1, 1, 0, 0)], name=DTTM_ALIAS),
        )
开发者ID:bkyryliuk,项目名称:caravel,代码行数:55,代码来源:viz_tests.py


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