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


Python Field.coerce方法代码示例

本文整理汇总了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'))
开发者ID:mnpk,项目名称:flywheel,代码行数:9,代码来源:test_fields.py

示例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')
开发者ID:hoov,项目名称:flywheel,代码行数:10,代码来源:test_fields.py

示例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'])
开发者ID:mnpk,项目名称:flywheel,代码行数:7,代码来源:test_fields.py

示例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'])
开发者ID:mnpk,项目名称:flywheel,代码行数:7,代码来源:test_fields.py

示例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)
开发者ID:mnpk,项目名称:flywheel,代码行数:7,代码来源:test_fields.py

示例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))
开发者ID:mnpk,项目名称:flywheel,代码行数:7,代码来源:test_fields.py

示例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))
开发者ID:mnpk,项目名称:flywheel,代码行数:7,代码来源:test_fields.py

示例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))
开发者ID:mnpk,项目名称:flywheel,代码行数:7,代码来源:test_fields.py

示例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)
开发者ID:mnpk,项目名称:flywheel,代码行数:7,代码来源:test_fields.py

示例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))
开发者ID:mnpk,项目名称:flywheel,代码行数:7,代码来源:test_fields.py

示例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))
开发者ID:mnpk,项目名称:flywheel,代码行数:7,代码来源:test_fields.py

示例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)
开发者ID:mnpk,项目名称:flywheel,代码行数:7,代码来源:test_fields.py

示例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))
开发者ID:mnpk,项目名称:flywheel,代码行数:7,代码来源:test_fields.py

示例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))
开发者ID:mnpk,项目名称:flywheel,代码行数:7,代码来源:test_fields.py

示例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)
开发者ID:mnpk,项目名称:flywheel,代码行数:7,代码来源:test_fields.py


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