本文整理匯總了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)