本文整理汇总了Python中flywheel.Field类的典型用法代码示例。如果您正苦于以下问题:Python Field类的具体用法?Python Field怎么用?Python Field使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Field类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_int_no_data_loss
def test_int_no_data_loss(self):
""" Int fields refuse to drop floating point data """
field = Field(data_type=int, coerce=True)
with self.assertRaises(ValueError):
field.coerce(4.5)
with self.assertRaises(ValueError):
field.coerce(Decimal('4.5'))
示例2: test_coerce_boto_s3key
def test_coerce_boto_s3key(self):
""" Coerce boto key to S3 key """
field = Field(data_type=S3Type('mybucket'))
boto_key = boto.s3.key.Key()
boto_key.key = 'my/path'
ret = field.coerce(boto_key)
self.assertTrue(isinstance(ret, Key))
self.assertEqual(ret.key, 'my/path')
示例3: test_coerce_unicode
def test_coerce_unicode(self):
""" Coerce to unicode """
field = Field(data_type=six.text_type, coerce=True)
ret = field.coerce(5)
self.assertTrue(isinstance(ret, six.text_type))
示例4: test_naive_datetime
def test_naive_datetime(self):
""" Naive datetime fields don't add timezone """
field = Field(data_type=DateTimeType(naive=True))
dt = field.ddb_load(1432828089.027812)
self.assertIsNone(dt.tzinfo)
示例5: test_coerce_number_set_fail
def test_coerce_number_set_fail(self):
""" Coerce to number set fails """
field = Field(data_type=set_(int))
with self.assertRaises(TypeError):
field.coerce([2, '4'])
示例6: test_coerce_basic_set_fail
def test_coerce_basic_set_fail(self):
""" Coercing to untyped set fails """
field = Field(data_type=set)
with self.assertRaises(TypeError):
field.coerce(['a', 'b'])
示例7: test_coerce_date_fail
def test_coerce_date_fail(self):
""" Coercing to date fails """
field = Field(data_type=date, coerce=True)
with self.assertRaises(TypeError):
field.coerce(12345)
示例8: test_coerce_bool
def test_coerce_bool(self):
""" Coerce to bool """
field = Field(data_type=bool, coerce=True)
ret = field.coerce(2)
self.assertTrue(isinstance(ret, bool))
示例9: test_coerce_list
def test_coerce_list(self):
""" Coerce to list """
field = Field(data_type=list, coerce=True)
ret = field.coerce(set([1, 2]))
self.assertTrue(isinstance(ret, list))
示例10: test_int_coerce_fail
def test_int_coerce_fail(self):
""" Coerce to int fails if coerce=False """
field = Field(data_type=int)
with self.assertRaises(TypeError):
field.coerce(4.0)
示例11: test_int_coerce
def test_int_coerce(self):
""" Int fields can coerce floats """
field = Field(data_type=int, coerce=True)
ret = field.coerce(4.0)
self.assertEquals(ret, 4)
self.assertTrue(isinstance(ret, int))
示例12: test_coerce_str_fail
def test_coerce_str_fail(self):
""" Coerce to bytes fails if coerce=False """
field = Field(data_type=six.binary_type)
with self.assertRaises(TypeError):
field.coerce(5)
示例13: test_coerce_str
def test_coerce_str(self):
""" Coerce to bytes """
field = Field(data_type=six.binary_type, coerce=True)
ret = field.coerce(5)
self.assertTrue(isinstance(ret, six.binary_type))
示例14: test_always_coerce_unicode_str
def test_always_coerce_unicode_str(self):
""" Always coerce unicode to bytes """
field = Field(data_type=six.binary_type)
ret = field.coerce(six.u('val'))
self.assertTrue(isinstance(ret, six.binary_type))
示例15: test_coerce_unicode_fail
def test_coerce_unicode_fail(self):
""" Coerce to unicode fails if coerce=False """
field = Field(data_type=six.text_type)
with self.assertRaises(TypeError):
field.coerce(5)