當前位置: 首頁>>代碼示例>>Python>>正文


Python fields.Float方法代碼示例

本文整理匯總了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
        ) 
開發者ID:apryor6,項目名稱:flask_accepts,代碼行數:18,代碼來源:utils_test.py

示例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
        ) 
開發者ID:apryor6,項目名稱:flask_accepts,代碼行數:20,代碼來源:utils_test.py

示例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
        ) 
開發者ID:apryor6,項目名稱:flask_accepts,代碼行數:23,代碼來源:utils_test.py

示例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() 
開發者ID:samuelcolvin,項目名稱:pydantic,代碼行數:32,代碼來源:test_marshmallow.py

示例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) 
開發者ID:apryor6,項目名稱:flask_accepts,代碼行數:11,代碼來源:utils_test.py

示例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) 
開發者ID:justanr,項目名稱:marshmallow-annotations,代碼行數:11,代碼來源:test_converter.py

示例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,
        ) 
開發者ID:Flowminder,項目名稱:FlowKit,代碼行數:8,代碼來源:custom_fields.py

示例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,
            ),
        ) 
開發者ID:lovasoa,項目名稱:marshmallow_dataclass,代碼行數:11,代碼來源:test_field_for_schema.py

示例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) 
開發者ID:lyft,項目名稱:toasted-marshmallow,代碼行數:5,代碼來源:test_jit.py


注:本文中的marshmallow.fields.Float方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。