本文整理汇总了Python中flywheel.Field.coerce方法的典型用法代码示例。如果您正苦于以下问题:Python Field.coerce方法的具体用法?Python Field.coerce怎么用?Python Field.coerce使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flywheel.Field
的用法示例。
在下文中一共展示了Field.coerce方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_int_no_data_loss
# 需要导入模块: from flywheel import Field [as 别名]
# 或者: from flywheel.Field import coerce [as 别名]
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
# 需要导入模块: from flywheel import Field [as 别名]
# 或者: from flywheel.Field import coerce [as 别名]
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_number_set_fail
# 需要导入模块: from flywheel import Field [as 别名]
# 或者: from flywheel.Field import coerce [as 别名]
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'])
示例4: test_coerce_basic_set_fail
# 需要导入模块: from flywheel import Field [as 别名]
# 或者: from flywheel.Field import coerce [as 别名]
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'])
示例5: test_coerce_date_fail
# 需要导入模块: from flywheel import Field [as 别名]
# 或者: from flywheel.Field import coerce [as 别名]
def test_coerce_date_fail(self):
""" Coercing to date fails """
field = Field(data_type=date, coerce=True)
with self.assertRaises(TypeError):
field.coerce(12345)
示例6: test_coerce_bool
# 需要导入模块: from flywheel import Field [as 别名]
# 或者: from flywheel.Field import coerce [as 别名]
def test_coerce_bool(self):
""" Coerce to bool """
field = Field(data_type=bool, coerce=True)
ret = field.coerce(2)
self.assertTrue(isinstance(ret, bool))
示例7: test_coerce_list
# 需要导入模块: from flywheel import Field [as 别名]
# 或者: from flywheel.Field import coerce [as 别名]
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))
示例8: test_coerce_dict
# 需要导入模块: from flywheel import Field [as 别名]
# 或者: from flywheel.Field import coerce [as 别名]
def test_coerce_dict(self):
""" Coerce to dict """
field = Field(data_type=dict, coerce=True)
ret = field.coerce([(1, 2)])
self.assertTrue(isinstance(ret, dict))
示例9: test_coerce_str_fail
# 需要导入模块: from flywheel import Field [as 别名]
# 或者: from flywheel.Field import coerce [as 别名]
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)
示例10: test_always_coerce_unicode_str
# 需要导入模块: from flywheel import Field [as 别名]
# 或者: from flywheel.Field import coerce [as 别名]
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))
示例11: test_coerce_str
# 需要导入模块: from flywheel import Field [as 别名]
# 或者: from flywheel.Field import coerce [as 别名]
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))
示例12: test_coerce_unicode_fail
# 需要导入模块: from flywheel import Field [as 别名]
# 或者: from flywheel.Field import coerce [as 别名]
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)
示例13: test_coerce_unicode
# 需要导入模块: from flywheel import Field [as 别名]
# 或者: from flywheel.Field import coerce [as 别名]
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))
示例14: test_always_coerce_str_unicode
# 需要导入模块: from flywheel import Field [as 别名]
# 或者: from flywheel.Field import coerce [as 别名]
def test_always_coerce_str_unicode(self):
""" Always coerce bytes to unicode """
field = Field(data_type=six.text_type)
ret = field.coerce(b'val')
self.assertTrue(isinstance(ret, six.text_type))
示例15: test_coerce_decimal_fail
# 需要导入模块: from flywheel import Field [as 别名]
# 或者: from flywheel.Field import coerce [as 别名]
def test_coerce_decimal_fail(self):
""" Coerce to Decimal fails if coerce=False """
field = Field(data_type=Decimal)
with self.assertRaises(TypeError):
field.coerce(5.5)