e41094f908
Fixed #12 Fixed #13 Fixed #14
36 lines
808 B
Python
36 lines
808 B
Python
import io
|
|
|
|
from sdp.sheerkaSerializer import JsonSerializer
|
|
|
|
|
|
class ObjNoKey:
|
|
"""
|
|
Object with no key, they won't be ordered
|
|
Not suitable for Json dump as there is no to_dict() method
|
|
"""
|
|
|
|
def __init__(self, a, b):
|
|
self.a = a
|
|
self.b = b
|
|
|
|
def __hash__(self):
|
|
return hash((self.a, self.b))
|
|
|
|
def __eq__(self, obj):
|
|
return isinstance(obj, ObjNoKey) and \
|
|
self.a == obj.a and \
|
|
self.b == obj.b
|
|
|
|
def __repr__(self):
|
|
return f"ObjNoKey({self.a}, {self.b})"
|
|
|
|
|
|
def test_i_can_json_serialize():
|
|
json_serializer = JsonSerializer(lambda o: True)
|
|
obj = ObjNoKey("a", "b")
|
|
stream = io.BytesIO()
|
|
|
|
stream = json_serializer.dump(stream, obj, None)
|
|
res = json_serializer.load(stream, None)
|
|
assert res == obj
|