當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。