@@ -0,0 +1,35 @@
|
||||
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 obj: True)
|
||||
obj = ObjNoKey("a", "b")
|
||||
stream = io.BytesIO()
|
||||
|
||||
stream = json_serializer.dump(stream, obj, None)
|
||||
res = json_serializer.load(stream, None)
|
||||
assert res == obj
|
||||
Reference in New Issue
Block a user