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


Python Mock.description方法代码示例

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


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

示例1: test_delete_interface

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import description [as 别名]
    def test_delete_interface(self, m):
        ip1 = Mock()
        ip1.ip = "1.1.1.1/16"
        ip1.description = "My IPv4 ip"
        ip2 = Mock()
        ip2.ip = "2001:0db8:85a3:0000:0000:8a2e:0370:7334/64"
        ip2.description = "My IPv6 ip"

        # interfaces
        intf1 = Mock()
        intf1.name = "intf1"
        intf1.vlanUntagged = None
        intf1.ips.all.return_value = [ip1, ip2]

        # bindings
        # create a mock SwitchPort instance
        interface_to_remove = Mock()
        interface_to_remove.id = 1
        interface_to_remove.tologdict.return_value = {}
        interface_to_remove.leaf_model_name = "PortInterface"
        interface_to_remove.port.interfaces.all.return_value = [intf1]
        interface_to_remove.port.switch.ofId = "of:1234"
        interface_to_remove.port.portId = "1"
        interface_to_remove.port.host_learning = True

        m.post("http://onos-fabric:8181/onos/v1/network/configuration/", status_code=200)

        m.post("http://onos-fabric:8181/onos/v1/devices/%s/portstate/%s" % (interface_to_remove.port.switch.ofId,
                                                                            interface_to_remove.port.portId),
               status_code=200)

        with patch.object(Service.objects, "get") as onos_fabric_get:
            onos_fabric_get.return_value = self.fabric
            self.sync_step(model_accessor=self.model_accessor).delete_record(interface_to_remove)
            self.assertTrue(m.called)
开发者ID:opencord,项目名称:fabric,代码行数:37,代码来源:test_sync_fabric_port.py

示例2: test_sync

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import description [as 别名]
    def test_sync(self, mock_ndb, mock_repo, mock_set):
        """Ensure that a Repository entity is created for every GitHub repo
        that doesn't already have an entity and a list of the user's repos is
        returned.
        """

        mock_user = Mock()
        repo1 = Mock()
        repo1.id = 'repo1'
        repo2 = Mock()
        repo2.id = 'repo2'
        repo2.name = 'repo2'
        repo2.description = 'description'
        mock_user.github_repos = [repo1, repo2]
        key1 = Mock()
        key2 = Mock()
        keys = [key1, key2]
        mock_ndb.Key.side_effect = keys
        mock_ndb.get_multi.return_value = [repo1, None]

        actual = repository.sync_repos(mock_user)

        self.assertEqual([repo1, mock_repo.return_value], actual)
        expected = [call(repository.Repository, 'github_%s' % repo.id)
                    for repo in [repo1, repo2]]
        self.assertEqual(expected, mock_ndb.Key.call_args_list)
        mock_ndb.get_multi.assert_called_once_with(keys)
        mock_repo.assert_called_once_with(id='github_%s' % repo2.id,
                                          description=repo2.description,
                                          name=repo2.name, owner=mock_user.key)
        mock_ndb.put_multi.assert_called_once_with([mock_repo.return_value])
        mock_set.assert_called_once_with(
            'kaput:repos:%s' % mock_user.key.id(),
            [repo1, mock_repo.return_value])
开发者ID:tylertreat,项目名称:Kaput,代码行数:36,代码来源:test_repository.py

示例3: test_delete_ip

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import description [as 别名]
    def test_delete_ip(self, m):
        ip1 = Mock()
        ip1.ip = "1.1.1.1/16"
        ip1.description = "My IPv4 ip"

        intf1 = Mock()
        intf1.name = "intf1"
        intf1.vlanUntagged = None
        intf1.ips.all.return_value = [ip1]

        ip_to_remove = Mock()
        ip_to_remove.id = 1
        ip_to_remove.leaf_model_name = "FabricIpAddress"
        ip_to_remove.interface.port.interfaces.all.return_value = [intf1]
        ip_to_remove.interface.port.switch.ofId = "of:1234"
        ip_to_remove.interface.port.portId = "1"
        ip_to_remove.interface.port.host_learning = True

        m.post("http://onos-fabric:8181/onos/v1/network/configuration/", status_code=200)

        m.post("http://onos-fabric:8181/onos/v1/devices/%s/portstate/%s" % (ip_to_remove.interface.port.switch.ofId,
                                                                            ip_to_remove.interface.port.portId),
               status_code=200)

        with patch.object(Service.objects, "get") as onos_fabric_get:
            onos_fabric_get.return_value = self.fabric
            self.sync_step(model_accessor=self.model_accessor).delete_record(ip_to_remove)
            self.assertTrue(m.called)
开发者ID:opencord,项目名称:fabric,代码行数:30,代码来源:test_sync_fabric_port.py

示例4: test_create_resource

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import description [as 别名]
    def test_create_resource(self):
        # Create ResourceType
        rt = Mock()
        rt.name = "bad name"
        with self.assertRaises(BadRequest):
            self.rms.create_resource_type(rt, "123")

        rt.name = "good_name"
        bad_object_id = None
        with self.assertRaises(BadRequest):
            self.rms.create_resource_type(rt, bad_object_id)

        # Create ObjectType
        ot = Mock()
        ot.definition = self.object_definition
        ot.name = "good_name"
        ot.description = "This is just a test. No need to panic"

        self.rms.clients.resource_registry.read.return_value = ot
        resource_id_return_value = '123'
        version_return_value = 1
        self.rms.clients.resource_registry.create.return_value = [resource_id_return_value, version_return_value]
        self.rms.clients.resource_registry.create_association.return_value = '999'

        object_id = "444"
        resource_id = self.rms.create_resource_type(rt, object_id)
        self.assertEqual(resource_id, '123')

        self.rms.clients.resource_registry.read.assert_called_once_with(object_id, '')
        self.rms.clients.resource_registry.create.assert_called_once_with(rt)
        self.rms.clients.resource_registry.create_association.assert_called_once_with(resource_id_return_value, PRED.hasObjectType, object_id, 'H2H')
开发者ID:newbrough,项目名称:coi-services,代码行数:33,代码来源:test_resource_management_service.py

示例5: test__get_or_create_node

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import description [as 别名]
    def test__get_or_create_node(self):
        file = Mock()
        src_node = Mock()
        file.get_node.return_value = sentinel.node

        node = publicdb._get_or_create_node(file, sentinel.group, src_node)
        file.get_node.assert_called_once_with(sentinel.group, src_node.name)
        self.assertEqual(node, sentinel.node)

        file.get_node.side_effect = tables.NoSuchNodeError('no such node!')
        # Raise exception because type of Mock src_node is not Table or VLArray
        self.assertRaises(Exception, publicdb._get_or_create_node, file,
                          sentinel.group, src_node)

        src_node = Mock(spec=tables.Table)
        src_node.description = sentinel.description
        node = publicdb._get_or_create_node(file, sentinel.group, src_node)
        file.create_table.assert_called_once_with(
            sentinel.group, src_node.name, src_node.description,
            src_node.title)

        src_node = Mock(spec=tables.VLArray)
        src_node.atom = sentinel.atom
        node = publicdb._get_or_create_node(file, sentinel.group, src_node)
        file.create_vlarray.assert_called_once_with(
            sentinel.group, src_node.name, src_node.atom, src_node.title)
开发者ID:tomkooij,项目名称:sapphire,代码行数:28,代码来源:test_publicdb.py

示例6: test_files

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import description [as 别名]
    def test_files(self):
        gist = Mock()
        gist.description = "Dale Name #notebook #hello"
        gist.files = object()

        tg = TaggedGist.from_gist(gist)
        assert tg.files is gist.files
开发者ID:dalejung,项目名称:nbx,代码行数:9,代码来源:test_gisthub.py

示例7: test_read_and_update_object

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import description [as 别名]
    def test_read_and_update_object(self):
        with self.assertRaises(BadRequest):
            self.oms.read_object_type(None)

        ot = Mock()
        ot.definition = self.yaml_definition
        ot.name = "name"
        ot.description = "This is just a test, don't panic"
        self.oms.clients.resource_registry.read.return_value = ot

        ot_return = self.oms.read_object_type("123")
        self.assertTrue(ot_return is ot)
        self.oms.clients.resource_registry.read.assert_called_once_with('123','')

        ot_return.name = "new    name"
        with self.assertRaises(BadRequest):
            self.oms.update_object_type(ot_return)

        ot_return.name = "new_name"
        ot_return.definition = self.bad_yaml
        with self.assertRaises(BadRequest):
            self.oms.update_object_type(ot_return)

        ot.definition = self.yaml_definition
        self.oms.clients.resource_registry.update.return_value = ['123', 2]
        ot_id = self.oms.update_object_type(ot_return)
        self.assertEqual(ot_id, '123')
        self.oms.clients.resource_registry.update.assert_called_once_with(ot_return)
开发者ID:Bobfrat,项目名称:coi-services,代码行数:30,代码来源:test_object_management_service.py

示例8: test_read_and_update_resource

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import description [as 别名]
    def test_read_and_update_resource(self):
        with self.assertRaises(BadRequest):
            self.sms.read_service_definition()

        service_definition = Mock()
        service_definition.name = "name"

        service_definition.definition = self.yaml_definition
        service_definition.description = "This is just a test, don't panic"
        self.mock_clients.resource_registry.read.return_value = service_definition

        sd = self.sms.read_service_definition("123")
        self.assertTrue(sd is service_definition)
        self.mock_clients.resource_registry.read.assert_called_once_with('123', '')

        sd.name = "new    name"
        with self.assertRaises(BadRequest):
            self.sms.update_service_definition(sd)

        sd.definition = self.bad_yaml
        with self.assertRaises(BadRequest):
            self.sms.update_service_definition(service_definition)

        sd.name = "new_name"
        sd.definition = self.yaml_definition
        self.mock_clients.resource_registry.update.return_value = ['123', 2]
        sd_id = self.sms.update_service_definition(sd)
        self.assertEqual(sd_id, '123')
        self.mock_clients.resource_registry.update.assert_called_once_with(sd)
开发者ID:Bobfrat,项目名称:coi-services,代码行数:31,代码来源:test_service_management_service.py

示例9: test_fetchone_nt

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import description [as 别名]
 def test_fetchone_nt(self):
     cursor = Mock()
     cursor.description = (('id', 3, 2, 11, 11, 0, 0), ('status', 253, 7, 80, 80, 0, 0))
     cursor.fetchone = Mock(return_value=(34, 'info'))
     r = fetchone_nt(cursor)
     self.assertEqual(r.__class__.__name__, 'Results')
     self.assertEqual(r.id, 34)
     self.assertEqual(r.status, 'info')
开发者ID:albertoalcolea,项目名称:dbhelpers,代码行数:10,代码来源:tests.py

示例10: test_fetchiter_nt

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import description [as 别名]
    def test_fetchiter_nt(self):
        cursor = Mock()
        cursor.description = (('id', 3, 2, 11, 11, 0, 0), ('status', 253, 7, 80, 80, 0, 0))

        # Standard
        cursor.fetchmany = Mock(return_value=((34, 'info'), (99, 'warning')))
        num_it = 0
        for row in fetchiter_nt(cursor):
            self.assertEqual(row.__class__.__name__, 'Results')
            if num_it == 0:
                self.assertEqual(row.id, 34)
                self.assertEqual(row.status, 'info')
            if num_it == 1:
                self.assertEqual(row.id, 99)
                self.assertEqual(row.status, 'warning')
            if num_it == 2:
                raise StopIteration
            num_it += 1
            if num_it == 2:
                cursor.fetchmany = Mock(return_value=[])
        self.assertEqual(num_it, 2)

        # Batch
        cursor.fetchmany = Mock(return_value=((34, 'info'), (99, 'warning')))
        num_it = 0
        for row in fetchiter_nt(cursor, batch=True):
            self.assertEqual(row.__class__.__name__, 'list')
            self.assertEqual(row[0].__class__.__name__, 'Results')
            self.assertEqual(row[0].id, 34)
            self.assertEqual(row[0].status, 'info')
            self.assertEqual(row[1].__class__.__name__, 'Results')
            self.assertEqual(row[1].id, 99)
            self.assertEqual(row[1].status, 'warning')
            if num_it == 1:
                raise StopIteration
            num_it += 1
            if num_it == 1:
                cursor.fetchmany = Mock(return_value=[])
        self.assertEqual(num_it, 1)

        # Server cursor
        cursor.fetchall = Mock(return_value=((34, 'info'), (99, 'warning')))
        num_it = 0
        for row in fetchiter_nt(cursor, server_cursor='C'):
            self.assertEqual(row.__class__.__name__, 'Results')
            if num_it == 0:
                self.assertEqual(row.id, 34)
                self.assertEqual(row.status, 'info')
            if num_it == 1:
                self.assertEqual(row.id, 99)
                self.assertEqual(row.status, 'warning')
            if num_it == 2:
                raise StopIteration
            num_it += 1
            if num_it == 2:
                cursor.fetchall = Mock(return_value=[])
        self.assertEqual(num_it, 2)
开发者ID:albertoalcolea,项目名称:dbhelpers,代码行数:59,代码来源:tests.py

示例11: test_make_float64_meta

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import description [as 别名]
 def test_make_float64_meta(self):
     params = Mock()
     params.name = "me"
     params.description = "desc"
     params.default = 32.6
     name, meta, default = parameters.float64(params)
     self.assertEqual(default, 32.6)
     self.assertEqual(name, "me")
     self.assertEqual(meta.description, "desc")
     self.assertIsInstance(meta, NumberMeta)
     self.assertEqual(meta.dtype, "float64")
开发者ID:dls-controls,项目名称:pymalcolm,代码行数:13,代码来源:test_parameters.py

示例12: test_from_gist

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import description [as 别名]
    def test_from_gist(self):
        gist = Mock()
        gist.description = "Dale Name #notebook #hello"

        tg = TaggedGist.from_gist(gist)
        nt.assert_equals(tg.name, "Dale Name")
        nt.assert_items_equal(tg.tags, ['#notebook', '#hello'])
        nt.assert_true(tg.active)

        gist = Mock()
        gist.description = "Dale Name #notebook #inactive"

        tg = TaggedGist.from_gist(gist)
        nt.assert_equals(tg.name, "Dale Name")
        nt.assert_items_equal(tg.tags, ['#notebook'])

        # explicitly test system tags
        nt.assert_in('#inactive', TaggedGist.system_tags)
        nt.assert_not_in('#inactive', tg.tags)
        nt.assert_false(tg.active)
开发者ID:gitter-badger,项目名称:nbx,代码行数:22,代码来源:test_gisthub.py

示例13: test_from_gist

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import description [as 别名]
    def test_from_gist(self):
        gist = Mock()
        gist.description = "Dale Name #notebook #hello"

        tg = TaggedGist.from_gist(gist)
        assert tg.name == "Dale Name"
        assert_items_equal(tg.tags, ['#notebook', '#hello'])
        assert tg.active

        gist = Mock()
        gist.description = "Dale Name #notebook #inactive"

        tg = TaggedGist.from_gist(gist)
        assert tg.name == "Dale Name"
        assert_items_equal(tg.tags, ['#notebook'])

        # explicitly test system tags
        assert '#inactive' in TaggedGist.system_tags
        assert '#inactive' not in tg.tags
        assert not tg.active
开发者ID:dalejung,项目名称:nbx,代码行数:22,代码来源:test_gisthub.py

示例14: get_contest

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import description [as 别名]
def get_contest():
    contest = Mock()
    contest.id = get_int()
    contest.name = get_string()
    start = get_int(2 ** 11)
    duration = get_int(2 ** 8)
    contest.start = make_datetime(start)
    contest.stop = make_datetime(start + duration)
    contest.score_precision = 2
    contest.description = get_string()
    return contest
开发者ID:olimpiadi-informatica,项目名称:cms,代码行数:13,代码来源:testobjectgenerator.py

示例15: generate_tagged_gists

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import description [as 别名]
def generate_tagged_gists(names):
    mocks = []
    for id, name in enumerate(names, 1):
        mock = Mock()
        mock.description = name
        mock.id = id
        mocks.append(mock)

    tagged_gists = [(mock.id, TaggedGist.from_gist(mock))
                    for mock in mocks if mock.description]
    tagged_gists = dict(tagged_gists)
    return tagged_gists
开发者ID:dalejung,项目名称:nbx,代码行数:14,代码来源:test_gisthub.py


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