|
@ -95,11 +95,23 @@ def test_encode_dict_with_nonprimative_keys(): |
|
|
def __init__(self, value: str) -> None: |
|
|
def __init__(self, value: str) -> None: |
|
|
self.value = value |
|
|
self.value = value |
|
|
|
|
|
|
|
|
|
|
|
def __eq__(self, other) -> bool: |
|
|
|
|
|
return isinstance(other, CustomString) and self.value == other.value |
|
|
|
|
|
|
|
|
|
|
|
def __hash__(self): |
|
|
|
|
|
return hash(self.value) |
|
|
|
|
|
|
|
|
assert jsonable_encoder( |
|
|
assert jsonable_encoder( |
|
|
{CustomString("foo"): "bar"}, |
|
|
{CustomString("foo"): "bar"}, |
|
|
custom_encoder={CustomString: lambda v: v.value} |
|
|
custom_encoder={CustomString: lambda v: v.value} |
|
|
) == {"foo": "bar"} |
|
|
) == {"foo": "bar"} |
|
|
|
|
|
|
|
|
|
|
|
def test_encode_dict_with_custom_encoder_keys(): |
|
|
|
|
|
assert jsonable_encoder( |
|
|
|
|
|
{"foo": "bar"}, |
|
|
|
|
|
custom_encoder={str: lambda v: "_" + v} |
|
|
|
|
|
) == {"_foo": "_bar"} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_encode_dict_with_sqlalchemy_safe(): |
|
|
def test_encode_dict_with_sqlalchemy_safe(): |
|
|
obj = {"_sa_foo": "foo", "bar": "bar"} |
|
|
obj = {"_sa_foo": "foo", "bar": "bar"} |
|
|