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


Python messages.IntegerField方法代码示例

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


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

示例1: testNestedMessageField

# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import IntegerField [as 别名]
def testNestedMessageField(self):
    class Inner(messages.Message):
      count = messages.IntegerField(1)
      greet = messages.MessageField(Greeting, 2)

    class Outer(messages.Message):
      inner = messages.MessageField(Inner, 1)
      extra = messages.StringField(2)

    class Store(model.Model):
      outer = msgprop.MessageProperty(Outer,
                                      indexed_fields=['inner.greet.text'])
    greet = Greeting(text='abc', when=123)
    inner = Inner(count=42, greet=greet)
    outer = Outer(inner=inner)
    st = Store(outer=outer)
    st.put()
    res = Store.query(Store.outer.inner.greet.text == 'abc').fetch()
    self.assertEqual(res, [st]) 
开发者ID:GoogleCloudPlatform,项目名称:datastore-ndb-python,代码行数:21,代码来源:msgprop_test.py

示例2: testNestedRepeatedMessageField

# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import IntegerField [as 别名]
def testNestedRepeatedMessageField(self):
    class Outer(messages.Message):
      greetings = messages.MessageField(Greeting, 1, repeated=True)
      extra = messages.IntegerField(2)

    class Store(model.Model):
      outer = msgprop.MessageProperty(Outer, indexed_fields=['greetings.text',
                                                             'extra'])
    gr1 = Greeting(text='abc', when=123)
    gr2 = Greeting(text='def', when=456)
    outer1 = Outer(greetings=[gr1], extra=1)
    outer2 = Outer(greetings=[gr2], extra=2)
    outer3 = Outer(greetings=[gr1, gr2], extra=3)
    store1 = Store(outer=outer1)
    store1.put()
    store2 = Store(outer=outer2)
    store2.put()
    store3 = Store(outer=outer3)
    store3.put()
    res = Store.query(Store.outer.greetings.text == 'abc').fetch()
    self.assertEqual(res, [store1, store3]) 
开发者ID:GoogleCloudPlatform,项目名称:datastore-ndb-python,代码行数:23,代码来源:msgprop_test.py

示例3: testNestedFieldErrors

# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import IntegerField [as 别名]
def testNestedFieldErrors(self):
    class Outer(messages.Message):
      greetings = messages.MessageField(Greeting, 1, repeated=True)
      extra = messages.IntegerField(2)
    # Parent/child conflicts.
    self.assertRaises(ValueError, msgprop.MessageProperty,
                      Outer, indexed_fields=['greetings.text', 'greetings'])
    self.assertRaises(ValueError, msgprop.MessageProperty,
                      Outer, indexed_fields=['greetings', 'greetings.text'])
    # Duplicate inner field.
    self.assertRaises(ValueError, msgprop.MessageProperty,
                      Outer, indexed_fields=['greetings.text',
                                             'greetings.text'])
    # Can't index MessageField.
    self.assertRaises(ValueError, msgprop.MessageProperty,
                      Outer, indexed_fields=['greetings'])
    # Can't specify subfields for non-MessageField.
    self.assertRaises(ValueError, msgprop.MessageProperty,
                      Outer, indexed_fields=['extra.foobar'])
    # Non-existent subfield.
    self.assertRaises(ValueError, msgprop.MessageProperty,
                      Outer, indexed_fields=['greetings.foobar']) 
开发者ID:GoogleCloudPlatform,项目名称:datastore-ndb-python,代码行数:24,代码来源:msgprop_test.py

示例4: testDefineField_Optional

# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import IntegerField [as 别名]
def testDefineField_Optional(self):
    """Test defining an optional field instance from a method descriptor."""
    field_descriptor = descriptor.FieldDescriptor()

    field_descriptor.name = 'a_field'
    field_descriptor.number = 1
    field_descriptor.variant = descriptor.FieldDescriptor.Variant.INT32
    field_descriptor.label = descriptor.FieldDescriptor.Label.OPTIONAL

    field = definition.define_field(field_descriptor)

    # Name will not be set from the original descriptor.
    self.assertFalse(hasattr(field, 'name'))

    self.assertTrue(isinstance(field, messages.IntegerField))
    self.assertEquals(1, field.number)
    self.assertEquals(descriptor.FieldDescriptor.Variant.INT32, field.variant)
    self.assertFalse(field.required)
    self.assertFalse(field.repeated) 
开发者ID:google,项目名称:protorpc,代码行数:21,代码来源:definition_test.py

示例5: testDefineField_Default_Int

# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import IntegerField [as 别名]
def testDefineField_Default_Int(self):
    """Test defining a default value for an int."""
    field_descriptor = descriptor.FieldDescriptor()

    field_descriptor.name = 'a_field'
    field_descriptor.number = 1
    field_descriptor.variant = descriptor.FieldDescriptor.Variant.INT64
    field_descriptor.default_value = u'34'

    field = definition.define_field(field_descriptor)

    # Name will not be set from the original descriptor.
    self.assertFalse(hasattr(field, 'name'))

    self.assertTrue(isinstance(field, messages.IntegerField))
    self.assertEquals(1, field.number)
    self.assertEquals(descriptor.FieldDescriptor.Variant.INT64, field.variant)
    self.assertFalse(field.required)
    self.assertFalse(field.repeated)
    self.assertEqual(field.default, 34) 
开发者ID:google,项目名称:protorpc,代码行数:22,代码来源:definition_test.py

示例6: testDefineField_Default_Invalid

# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import IntegerField [as 别名]
def testDefineField_Default_Invalid(self):
    """Test defining a default value that is not valid."""
    field_descriptor = descriptor.FieldDescriptor()

    field_descriptor.name = 'a_field'
    field_descriptor.number = 1
    field_descriptor.variant = descriptor.FieldDescriptor.Variant.INT64
    field_descriptor.default_value = u'Test'

    # Verify that the string is passed to the Constructor.
    mock = mox.Mox()
    mock.StubOutWithMock(messages.IntegerField, '__init__')
    messages.IntegerField.__init__(
        default=u'Test',
        number=1,
        variant=messages.Variant.INT64
        ).AndRaise(messages.InvalidDefaultError)

    mock.ReplayAll()
    self.assertRaises(messages.InvalidDefaultError,
                      definition.define_field, field_descriptor)
    mock.VerifyAll()

    mock.ResetAll()
    mock.UnsetStubs() 
开发者ID:google,项目名称:protorpc,代码行数:27,代码来源:definition_test.py

示例7: testDefineMessageFieldsOnly

# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import IntegerField [as 别名]
def testDefineMessageFieldsOnly(self):
    """Test definition a message with only fields."""

    class AMessage(messages.Message):

      field1 = messages.IntegerField(1)
      field2 = messages.StringField(2)

    message_descriptor = descriptor.describe_message(AMessage)

    message_class = definition.define_message(message_descriptor, '__main__')

    self.assertEquals('AMessage', message_class.__name__)
    self.assertEquals('__main__', message_class.__module__)

    self.assertEquals(message_descriptor,
                      descriptor.describe_message(message_class)) 
开发者ID:google,项目名称:protorpc,代码行数:19,代码来源:definition_test.py

示例8: testDefineMessage

# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import IntegerField [as 别名]
def testDefineMessage(self):
    """Test defining Message class from descriptor."""

    class AMessage(messages.Message):
      class NestedEnum(messages.Enum):
        pass

      field1 = messages.IntegerField(1)
      field2 = messages.StringField(2)

    message_descriptor = descriptor.describe_message(AMessage)

    message_class = definition.define_message(message_descriptor, '__main__')

    self.assertEquals('AMessage', message_class.__name__)
    self.assertEquals('__main__', message_class.__module__)

    self.assertEquals(message_descriptor,
                      descriptor.describe_message(message_class)) 
开发者ID:google,项目名称:protorpc,代码行数:21,代码来源:definition_test.py

示例9: testDefaultFields_Single

# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import IntegerField [as 别名]
def testDefaultFields_Single(self):
    """Test default field is correct type (single)."""
    defaults = {messages.IntegerField: 10,
                messages.FloatField: 1.5,
                messages.BooleanField: False,
                messages.BytesField: b'abc',
                messages.StringField: u'abc',
               }

    def action(field_class):
      field_class(1, default=defaults[field_class])
    self.ActionOnAllFieldClasses(action)

    # Run defaults test again checking for str/unicode compatiblity.
    defaults[messages.StringField] = 'abc'
    self.ActionOnAllFieldClasses(action) 
开发者ID:google,项目名称:protorpc,代码行数:18,代码来源:messages_test.py

示例10: testValidate_Repeated

# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import IntegerField [as 别名]
def testValidate_Repeated(self):
    """Tests validation of repeated fields."""
    class SimpleMessage(messages.Message):
      repeated = messages.IntegerField(1, repeated=True)

    simple_message = SimpleMessage()

    # Check valid values.
    for valid_value in [], [10], [10, 20], (), (10,), (10, 20):
      simple_message.repeated = valid_value
      simple_message.check_initialized()

    # Check cleared.
    simple_message.repeated = []
    simple_message.check_initialized()

    # Check invalid values.
    for invalid_value in 10, ['10', '20'], [None], (None,):
      self.assertRaises(messages.ValidationError,
                        setattr, simple_message, 'repeated', invalid_value) 
开发者ID:google,项目名称:protorpc,代码行数:22,代码来源:messages_test.py

示例11: testIsInitializedNestedField

# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import IntegerField [as 别名]
def testIsInitializedNestedField(self):
    """Tests is_initialized for nested fields."""
    class SimpleMessage(messages.Message):
      required = messages.IntegerField(1, required=True)

    class NestedMessage(messages.Message):
      simple = messages.MessageField(SimpleMessage, 1)

    simple_message = SimpleMessage()
    self.assertFalse(simple_message.is_initialized())
    nested_message = NestedMessage(simple=simple_message)
    self.assertFalse(nested_message.is_initialized())

    simple_message.required = 10

    self.assertTrue(simple_message.is_initialized())
    self.assertTrue(nested_message.is_initialized()) 
开发者ID:google,项目名称:protorpc,代码行数:19,代码来源:messages_test.py

示例12: testEqualityWithUnknowns

# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import IntegerField [as 别名]
def testEqualityWithUnknowns(self):
    """Test message class equality with unknown fields."""

    class MyMessage(messages.Message):
      field1 = messages.IntegerField(1)

    message1 = MyMessage()
    message2 = MyMessage()
    self.assertEquals(message1, message2)
    message1.set_unrecognized_field('unknown1', 'value1',
                                    messages.Variant.STRING)
    self.assertEquals(message1, message2)

    message1.set_unrecognized_field('unknown2', ['asdf', 3],
                                    messages.Variant.STRING)
    message1.set_unrecognized_field('unknown3', 4.7,
                                    messages.Variant.DOUBLE)
    self.assertEquals(message1, message2) 
开发者ID:google,项目名称:protorpc,代码行数:20,代码来源:messages_test.py

示例13: testLabel

# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import IntegerField [as 别名]
def testLabel(self):
    for repeated, required, expected_label in (
        (True, False, descriptor.FieldDescriptor.Label.REPEATED),
        (False, True, descriptor.FieldDescriptor.Label.REQUIRED),
        (False, False, descriptor.FieldDescriptor.Label.OPTIONAL)):
      field = messages.IntegerField(10, required=required, repeated=repeated)
      field.name = 'a_field'

      expected = descriptor.FieldDescriptor()
      expected.name = 'a_field'
      expected.number = 10
      expected.label = expected_label
      expected.variant = descriptor.FieldDescriptor.Variant.INT64

      described = descriptor.describe_field(field)
      described.check_initialized()
      self.assertEquals(expected, described) 
开发者ID:google,项目名称:protorpc,代码行数:19,代码来源:descriptor_test.py

示例14: testDefault

# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import IntegerField [as 别名]
def testDefault(self):
    for field_class, default, expected_default in (
        (messages.IntegerField, 200, '200'),
        (messages.FloatField, 1.5, '1.5'),
        (messages.FloatField, 1e6, '1000000.0'),
        (messages.BooleanField, True, 'true'),
        (messages.BooleanField, False, 'false'),
        (messages.BytesField, 'ab\xF1', 'ab\\xf1'),
        (messages.StringField, RUSSIA, RUSSIA),
        ):
      field = field_class(10, default=default)
      field.name = u'a_field'

      expected = descriptor.FieldDescriptor()
      expected.name = u'a_field'
      expected.number = 10
      expected.label = descriptor.FieldDescriptor.Label.OPTIONAL
      expected.variant = field_class.DEFAULT_VARIANT
      expected.default_value = expected_default

      described = descriptor.describe_field(field)
      described.check_initialized()
      self.assertEquals(expected, described) 
开发者ID:google,项目名称:protorpc,代码行数:25,代码来源:descriptor_test.py

示例15: testParameterPrefix

# 需要导入模块: from protorpc import messages [as 别名]
# 或者: from protorpc.messages import IntegerField [as 别名]
def testParameterPrefix(self):
    """Test using the 'prefix' parameter to encode_message."""
    class MyMessage(messages.Message):
      number = messages.IntegerField(1)
      names = messages.StringField(2, repeated=True)

    message = MyMessage()
    message.number = 10
    message.names = [u'Fred', u'Lisa']

    encoded_message = protourlencode.encode_message(message, prefix='prefix-')
    self.assertEquals({'prefix-number': ['10'],
                       'prefix-names-0': ['Fred'],
                       'prefix-names-1': ['Lisa'],
                      },
                      cgi.parse_qs(encoded_message))

    self.assertEquals(message, protourlencode.decode_message(MyMessage,
                                                             encoded_message,
                                                             prefix='prefix-')) 
开发者ID:google,项目名称:protorpc,代码行数:22,代码来源:protourlencode_test.py


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