本文整理汇总了Python中marshmallow.fields.Float方法的典型用法代码示例。如果您正苦于以下问题:Python fields.Float方法的具体用法?Python fields.Float怎么用?Python fields.Float使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类marshmallow.fields
的用法示例。
在下文中一共展示了fields.Float方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_map_type_calls_type_map_dict_function_for_known_type_with_correct_parameters
# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Float [as 别名]
def test_map_type_calls_type_map_dict_function_for_known_type_with_correct_parameters():
expected_ma_field = ma.Float
expected_model_name, expected_operation, expected_namespace = _get_type_mapper_default_params()
float_type_mapper = Mock()
type_map_mock = {
type(expected_ma_field): float_type_mapper
}
type_map_patch = patch.object(utils, "type_map", new=type_map_mock)
with type_map_patch:
utils.map_type(expected_ma_field, expected_namespace, expected_model_name, expected_operation)
float_type_mapper.assert_called_with(
expected_ma_field, expected_namespace, expected_model_name, expected_operation
)
示例2: test_map_type_calls_type_map_dict_function_for_schema_instance
# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Float [as 别名]
def test_map_type_calls_type_map_dict_function_for_schema_instance():
class MarshmallowSchema(Schema):
test_field: ma.Float
expected_ma_field = MarshmallowSchema()
expected_model_name, expected_operation, expected_namespace = _get_type_mapper_default_params()
schema_type_mapper_mock = Mock()
type_map_mock = dict(utils.type_map)
type_map_mock[Schema] = schema_type_mapper_mock
type_map_patch = patch.object(utils, "type_map", new=type_map_mock)
with type_map_patch:
utils.map_type(expected_ma_field, expected_namespace, expected_model_name, expected_operation)
schema_type_mapper_mock.assert_called_with(
expected_ma_field, expected_namespace, expected_model_name, expected_operation
)
示例3: test_map_type_calls_type_map_dict_function_for_schema_class
# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Float [as 别名]
def test_map_type_calls_type_map_dict_function_for_schema_class():
class InheritedMeta(SchemaMeta):
pass
class MarshmallowSchema(Schema, metaclass=InheritedMeta):
test_field: ma.Float
expected_ma_field = MarshmallowSchema
expected_model_name, expected_operation, expected_namespace = _get_type_mapper_default_params()
schema_type_mapper_mock = Mock()
type_map_mock = dict(utils.type_map)
type_map_mock[Schema] = schema_type_mapper_mock
type_map_patch = patch.object(utils, "type_map", new=type_map_mock)
with type_map_patch:
utils.map_type(expected_ma_field, expected_namespace, expected_model_name, expected_operation)
schema_type_mapper_mock.assert_called_with(
expected_ma_field, expected_namespace, expected_model_name, expected_operation
)
示例4: __init__
# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Float [as 别名]
def __init__(self, allow_extra):
class LocationSchema(Schema):
latitude = fields.Float(allow_none=True)
longitude = fields.Float(allow_none=True)
class SkillSchema(Schema):
subject = fields.Str(required=True)
subject_id = fields.Integer(required=True)
category = fields.Str(required=True)
qual_level = fields.Str(required=True)
qual_level_id = fields.Integer(required=True)
qual_level_ranking = fields.Float(default=0)
class Model(Schema):
id = fields.Integer(required=True)
client_name = fields.Str(validate=validate.Length(max=255), required=True)
sort_index = fields.Float(required=True)
# client_email = fields.Email()
client_phone = fields.Str(validate=validate.Length(max=255), allow_none=True)
location = fields.Nested(LocationSchema)
contractor = fields.Integer(validate=validate.Range(min=0), allow_none=True)
upstream_http_referrer = fields.Str(validate=validate.Length(max=1023), allow_none=True)
grecaptcha_response = fields.Str(validate=validate.Length(min=20, max=1000), required=True)
last_updated = fields.DateTime(allow_none=True)
skills = fields.Nested(SkillSchema, many=True)
self.allow_extra = allow_extra # unused
self.schema = Model()
示例5: test_map_type_raises_error_for_unknown_type
# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Float [as 别名]
def test_map_type_raises_error_for_unknown_type():
class UnknownType:
test_field: ma.Float
unknown_ma_field = UnknownType
expected_model_name, expected_operation, expected_namespace = _get_type_mapper_default_params()
with pytest.raises(TypeError):
utils.map_type(unknown_ma_field, expected_namespace, expected_model_name, expected_operation)
示例6: test_convert_all_generates_schema_fields_from_type
# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Float [as 别名]
def test_convert_all_generates_schema_fields_from_type(registry_):
converter = BaseConverter(registry=registry_)
generated_fields = converter.convert_all(SomeType)
assert set(generated_fields.keys()) == {"id", "name", "points"}
assert isinstance(generated_fields["id"], fields.Integer)
assert isinstance(generated_fields["name"], fields.String)
assert isinstance(generated_fields["points"], fields.List)
assert isinstance(generated_fields["points"].container, fields.Float)
示例7: __init__
# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Float [as 别名]
def __init__(self, **kwargs):
super().__init__(
fields.Float(validate=Range(min=-1.0, max=1.0)),
validate=Length(equal=24),
**kwargs,
)
示例8: test_dict_from_typing
# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Float [as 别名]
def test_dict_from_typing(self):
self.assertFieldsEqual(
field_for_schema(Dict[str, float]),
fields.Dict(
keys=fields.String(required=True),
values=fields.Float(required=True),
required=True,
),
)
示例9: __init__
# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Float [as 别名]
def __init__(self, places, **kwargs):
super(fields.Float, self).__init__(**kwargs)
self.num_type = lambda x: round(x, places)