def test_float_field_deserialization(self):
     field = fields.Float()
     assert_almost_equal(field.deserialize('12.3'), 12.3)
     assert_almost_equal(field.deserialize(12.3), 12.3)
     assert field.deserialize(None) == 0.0
     with pytest.raises(UnmarshallingError):
         field.deserialize('bad')
 def test_timedelta_field_deserialization(self):
     field = fields.TimeDelta()
     result = field.deserialize('42')
     assert isinstance(result, dt.timedelta)
     assert total_seconds(result) == 42.0
     result = field.deserialize('-42')
     assert total_seconds(result) == -42.0
     result = field.deserialize(12.3)
     assert_almost_equal(total_seconds(result), 12.3)
    def test_make_object(self):
        class SimpleUserSchema2(Schema):
            name = fields.String()
            age = fields.Float()

            def make_object(self, data):
                return User(**data)
        user_dict = {'name': 'Monty', 'age': '42.3'}
        result, errors = SimpleUserSchema2().load(user_dict)
        assert isinstance(result, User)
        assert result.name == 'Monty'
        assert_almost_equal(result.age, 42.3)
 def test_deserialize_to_dict(self):
     user_dict = {'name': 'Monty', 'age': '42.3'}
     result, errors = SimpleUserSchema().load(user_dict)
     assert result['name'] == 'Monty'
     assert_almost_equal(result['age'], 42.3)
 def test_float_field_deserialization(self):
     field = fields.Float()
     assert_almost_equal(field.deserialize('12.3'), 12.3)
     assert_almost_equal(field.deserialize(12.3), 12.3)
 def test_deserialize_to_dict(self):
     user_dict = {'name': 'Monty', 'age': '42.3'}
     result, errors = SimpleUserSchema().load(user_dict)
     assert result['name'] == 'Monty'
     assert_almost_equal(result['age'], 42.3)