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


Python fields.IntegerField方法代码示例

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


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

示例1: test_changed_with_sub_object

# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import IntegerField [as 别名]
def test_changed_with_sub_object(self):
        @base.VersionedObjectRegistry.register
        class ParentObject(base.VersionedObject):
            fields = {'foo': fields.IntegerField(),
                      'bar': fields.ObjectField('MyObj'),
                      }
        obj = ParentObject()
        self.assertEqual(set(), obj.obj_what_changed())
        obj.foo = 1
        self.assertEqual(set(['foo']), obj.obj_what_changed())
        bar = MyObj()
        obj.bar = bar
        self.assertEqual(set(['foo', 'bar']), obj.obj_what_changed())
        obj.obj_reset_changes()
        self.assertEqual(set(), obj.obj_what_changed())
        bar.foo = 1
        self.assertEqual(set(['bar']), obj.obj_what_changed()) 
开发者ID:openstack,项目名称:oslo.versionedobjects,代码行数:19,代码来源:test_objects.py

示例2: test_list_like_operations

# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import IntegerField [as 别名]
def test_list_like_operations(self):
        @base.VersionedObjectRegistry.register
        class MyElement(base.VersionedObject):
            fields = {'foo': fields.IntegerField()}

            def __init__(self, foo):
                super(MyElement, self).__init__()
                self.foo = foo

        class Foo(base.ObjectListBase, base.VersionedObject):
            fields = {'objects': fields.ListOfObjectsField('MyElement')}

        objlist = Foo(context='foo',
                      objects=[MyElement(1), MyElement(2), MyElement(3)])
        self.assertEqual(list(objlist), objlist.objects)
        self.assertEqual(len(objlist), 3)
        self.assertIn(objlist.objects[0], objlist)
        self.assertEqual(list(objlist[:1]), [objlist.objects[0]])
        self.assertEqual(objlist[:1]._context, 'foo')
        self.assertEqual(objlist[2], objlist.objects[2])
        self.assertEqual(objlist.count(objlist.objects[0]), 1)
        self.assertEqual(objlist.index(objlist.objects[1]), 1)
        objlist.sort(key=lambda x: x.foo, reverse=True)
        self.assertEqual([3, 2, 1],
                         [x.foo for x in objlist]) 
开发者ID:openstack,项目名称:oslo.versionedobjects,代码行数:27,代码来源:test_objects.py

示例3: test_obj_make_compatible_obj_relationships

# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import IntegerField [as 别名]
def test_obj_make_compatible_obj_relationships(self):
        @base.VersionedObjectRegistry.register
        class MyElement(base.VersionedObject):
            fields = {'foo': fields.IntegerField()}

        @base.VersionedObjectRegistry.register
        class Bar(base.ObjectListBase, base.VersionedObject):
            VERSION = '1.1'
            fields = {'objects': fields.ListOfObjectsField('MyElement')}
            obj_relationships = {
                'objects': [('1.0', '1.0'), ('1.1', '1.0')]
            }

        subobj = MyElement(foo=1)
        obj = Bar(objects=[subobj])
        primitive = obj.obj_to_primitive()['versioned_object.data']

        with mock.patch.object(subobj, 'obj_make_compatible') as mock_compat:
            obj.obj_make_compatible(copy.copy(primitive), '1.1')
            self.assertTrue(mock_compat.called) 
开发者ID:openstack,项目名称:oslo.versionedobjects,代码行数:22,代码来源:test_objects.py

示例4: test_obj_make_compatible_no_relationships

# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import IntegerField [as 别名]
def test_obj_make_compatible_no_relationships(self):
        @base.VersionedObjectRegistry.register
        class MyElement(base.VersionedObject):
            fields = {'foo': fields.IntegerField()}

        @base.VersionedObjectRegistry.register
        class Baz(base.ObjectListBase, base.VersionedObject):
            VERSION = '1.1'
            fields = {'objects': fields.ListOfObjectsField('MyElement')}

        subobj = MyElement(foo=1)
        obj = Baz(objects=[subobj])
        primitive = obj.obj_to_primitive()['versioned_object.data']

        with mock.patch.object(subobj, 'obj_make_compatible') as mock_compat:
            obj.obj_make_compatible(copy.copy(primitive), '1.1')
            self.assertTrue(mock_compat.called) 
开发者ID:openstack,项目名称:oslo.versionedobjects,代码行数:19,代码来源:test_objects.py

示例5: test_serializer_subclass_namespace_mismatch

# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import IntegerField [as 别名]
def test_serializer_subclass_namespace_mismatch(self):
        @base.VersionedObjectRegistry.register
        class MyNSObj(base.VersionedObject):
            OBJ_SERIAL_NAMESPACE = 'foo'
            fields = {'foo': fields.IntegerField()}

        class MySerializer(base.VersionedObjectSerializer):
            OBJ_BASE_CLASS = MyNSObj

        myser = MySerializer()
        voser = base.VersionedObjectSerializer()
        obj = MyObj(foo=123)
        obj2 = myser.deserialize_entity(None,
                                        voser.serialize_entity(None, obj))

        # NOTE(danms): The new serializer should have ignored the objects
        # serialized by the base serializer, so obj2 here should be a dict
        # primitive and not a hydrated object
        self.assertNotIsInstance(obj2, MyNSObj)
        self.assertIn('versioned_object.name', obj2) 
开发者ID:openstack,项目名称:oslo.versionedobjects,代码行数:22,代码来源:test_objects.py

示例6: test_serializer_subclass_base_object_indirection

# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import IntegerField [as 别名]
def test_serializer_subclass_base_object_indirection(self):
        @base.VersionedObjectRegistry.register
        class MyNSObj(base.VersionedObject):
            OBJ_SERIAL_NAMESPACE = 'foo'
            fields = {'foo': fields.IntegerField()}
            indirection_api = mock.MagicMock()

        class MySerializer(base.VersionedObjectSerializer):
            OBJ_BASE_CLASS = MyNSObj

        ser = MySerializer()
        prim = MyNSObj(foo=1).obj_to_primitive()
        prim['foo.version'] = '2.0'
        ser.deserialize_entity(mock.sentinel.context, prim)
        indirection_api = MyNSObj.indirection_api
        indirection_api.object_backport_versions.assert_called_once_with(
            mock.sentinel.context, prim, {'MyNSObj': '1.0'}) 
开发者ID:openstack,项目名称:oslo.versionedobjects,代码行数:19,代码来源:test_objects.py

示例7: test_load_in_base

# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import IntegerField [as 别名]
def test_load_in_base(self):
        @base.ZunObjectRegistry.register_if(False)
        class Foo(base.ZunPersistentObject, base.ZunObject):
            fields = {'foobar': fields.IntegerField()}
        obj = Foo(self.context)
        # NOTE(danms): Can't use assertRaisesRegexp() because of py26
        raised = False
        ex = None
        try:
            obj.foobar
        except NotImplementedError as e:
            raised = True
            ex = e
        self.assertTrue(raised)
        self.assertIn('foobar', str(ex)) 
开发者ID:openstack,项目名称:zun,代码行数:17,代码来源:test_objects.py

示例8: test_obj_fields

# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import IntegerField [as 别名]
def test_obj_fields(self):
        @base.ZunObjectRegistry.register_if(False)
        class TestObj(base.ZunPersistentObject, base.ZunObject):
            fields = {'foo': fields.IntegerField()}
            obj_extra_fields = ['bar']

            @property
            def bar(self):
                return 'this is bar'

        obj = TestObj(self.context)
        self.assertEqual(set(['created_at', 'updated_at', 'foo', 'bar']),
                         set(obj.obj_fields)) 
开发者ID:openstack,项目名称:zun,代码行数:15,代码来源:test_objects.py

示例9: test_load_in_base

# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import IntegerField [as 别名]
def test_load_in_base(self):
        @base.MagnumObjectRegistry.register_if(False)
        class Foo(base.MagnumPersistentObject, base.MagnumObject):
            fields = {'foobar': fields.IntegerField()}
        obj = Foo(self.context)
        # NOTE(danms): Can't use assertRaisesRegexp() because of py26
        raised = False
        ex = None
        try:
            obj.foobar
        except NotImplementedError as e:
            raised = True
            ex = e
        self.assertTrue(raised)
        self.assertIn('foobar', str(ex)) 
开发者ID:openstack,项目名称:magnum,代码行数:17,代码来源:test_objects.py

示例10: test_obj_fields

# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import IntegerField [as 别名]
def test_obj_fields(self):
        @base.MagnumObjectRegistry.register_if(False)
        class TestObj(base.MagnumPersistentObject, base.MagnumObject):
            fields = {'foo': fields.IntegerField()}
            obj_extra_fields = ['bar']

            @property
            def bar(self):
                return 'this is bar'

        obj = TestObj(self.context)
        self.assertEqual(set(['created_at', 'updated_at', 'foo', 'bar']),
                         set(obj.obj_fields)) 
开发者ID:openstack,项目名称:magnum,代码行数:15,代码来源:test_objects.py

示例11: setUp

# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import IntegerField [as 别名]
def setUp(self):
        super(TestField, self).setUp()
        self.field = fields.IntegerField()
        self.coerce_good_values = [(1, 1), ('1', 1)]
        self.coerce_bad_values = ['foo', None]
        self.to_primitive_values = self.coerce_good_values[0:1]
        self.from_primitive_values = self.coerce_good_values[0:1] 
开发者ID:openstack,项目名称:oslo.versionedobjects,代码行数:9,代码来源:test_fields.py

示例12: test__make_class_properties_setter_value_error

# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import IntegerField [as 别名]
def test__make_class_properties_setter_value_error(self, mock_log):
        @obj_base.VersionedObjectRegistry.register
        class AnObject(obj_base.VersionedObject):
            fields = {
                'intfield': fields.IntegerField(),
            }

        self.assertRaises(ValueError, AnObject, intfield='badvalue')
        self.assertFalse(mock_log.called) 
开发者ID:openstack,项目名称:oslo.versionedobjects,代码行数:11,代码来源:test_fields.py

示例13: test__make_class_properties_setter_setattr_fails

# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import IntegerField [as 别名]
def test__make_class_properties_setter_setattr_fails(self, mock_log):
        @obj_base.VersionedObjectRegistry.register
        class AnObject(obj_base.VersionedObject):
            fields = {
                'intfield': fields.IntegerField(),
            }

        # We want the setattr() call in _make_class_properties.setter() to
        # raise an exception
        with mock.patch.object(obj_base, '_get_attrname') as mock_attr:
            mock_attr.return_value = '__class__'
            self.assertRaises(TypeError, AnObject, intfield=2)
            mock_attr.assert_called_once_with('intfield')
            mock_log.assert_called_once_with(mock.ANY,
                                             {'attr': 'AnObject.intfield'}) 
开发者ID:openstack,项目名称:oslo.versionedobjects,代码行数:17,代码来源:test_fields.py

示例14: test_serializer_subclass_namespace

# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import IntegerField [as 别名]
def test_serializer_subclass_namespace(self):
        @base.VersionedObjectRegistry.register
        class MyNSObj(base.VersionedObject):
            OBJ_SERIAL_NAMESPACE = 'foo'
            fields = {'foo': fields.IntegerField()}

        class MySerializer(base.VersionedObjectSerializer):
            OBJ_BASE_CLASS = MyNSObj

        ser = MySerializer()
        obj = MyNSObj(foo=123)
        obj2 = ser.deserialize_entity(None, ser.serialize_entity(None, obj))
        self.assertIsInstance(obj2, MyNSObj)
        self.assertEqual(obj.foo, obj2.foo) 
开发者ID:openstack,项目名称:oslo.versionedobjects,代码行数:16,代码来源:test_objects.py

示例15: _from_db_object

# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import IntegerField [as 别名]
def _from_db_object(context, operation_log, db_operation_log):
        for name, field in operation_log.fields.items():
            value = db_operation_log.get(name)
            if isinstance(field, fields.IntegerField):
                value = value or 0
            elif isinstance(field, fields.DateTimeField):
                value = value or None
            operation_log[name] = value

        operation_log._context = context
        operation_log.obj_reset_changes()
        return operation_log 
开发者ID:openstack,项目名称:karbor,代码行数:14,代码来源:operation_log.py


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