Python marshmallow.fields.Float() Examples
The following are 10
code examples of marshmallow.fields.Float().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
marshmallow.fields
, or try the search function
.
Example #1
Source File: utils_test.py From flask_accepts with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 )
Example #2
Source File: utils_test.py From flask_accepts with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 )
Example #3
Source File: utils_test.py From flask_accepts with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 )
Example #4
Source File: test_marshmallow.py From pydantic with MIT License | 6 votes |
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()
Example #5
Source File: utils_test.py From flask_accepts with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #6
Source File: test_converter.py From marshmallow-annotations with MIT License | 5 votes |
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)
Example #7
Source File: custom_fields.py From FlowKit with Mozilla Public License 2.0 | 5 votes |
def __init__(self, **kwargs): super().__init__( fields.Float(validate=Range(min=-1.0, max=1.0)), validate=Length(equal=24), **kwargs, )
Example #8
Source File: custom_fields.py From FlowKit with Mozilla Public License 2.0 | 5 votes |
def __init__(self, **kwargs): days_of_week = [ "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday", ] super().__init__( keys=fields.String(validate=OneOf(days_of_week)), values=fields.Float(validate=Range(min=-1.0, max=1.0)), **kwargs, )
Example #9
Source File: test_field_for_schema.py From marshmallow_dataclass with MIT License | 5 votes |
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, ), )
Example #10
Source File: test_jit.py From toasted-marshmallow with Apache License 2.0 | 5 votes |
def __init__(self, places, **kwargs): super(fields.Float, self).__init__(**kwargs) self.num_type = lambda x: round(x, places)