2017-05-07 20:28:15 +00:00
|
|
|
from __future__ import print_function
|
2017-05-08 01:58:10 +00:00
|
|
|
from builtins import zip
|
|
|
|
from builtins import range
|
|
|
|
from builtins import object
|
2016-04-04 19:54:59 +00:00
|
|
|
import os
|
|
|
|
|
2017-05-02 22:49:33 +00:00
|
|
|
import pytest
|
|
|
|
jsonpickle = pytest.importorskip("jsonpickle")
|
2016-04-04 19:54:59 +00:00
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
2016-04-13 00:04:21 +00:00
|
|
|
from atrcopy import DefaultSegment, SegmentData
|
2016-04-04 19:54:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestJsonPickle(object):
|
|
|
|
def setup(self):
|
|
|
|
data = np.arange(2048, dtype=np.uint8)
|
|
|
|
self.segment = DefaultSegment(SegmentData(data))
|
|
|
|
|
|
|
|
def test_simple(self):
|
2017-05-07 20:28:15 +00:00
|
|
|
print(self.segment.byte_bounds_offset(), len(self.segment))
|
2016-04-04 19:54:59 +00:00
|
|
|
r2 = self.segment.rawdata[100:400]
|
|
|
|
s2 = DefaultSegment(r2)
|
2017-05-07 20:28:15 +00:00
|
|
|
print(s2.byte_bounds_offset(), len(s2), s2.__getstate__())
|
2016-04-04 19:54:59 +00:00
|
|
|
r3 = s2.rawdata[100:200]
|
|
|
|
s3 = DefaultSegment(r3)
|
2017-05-07 20:28:15 +00:00
|
|
|
print(s3.byte_bounds_offset(), len(s3), s3.__getstate__())
|
2017-05-08 01:58:10 +00:00
|
|
|
order = list(reversed(list(range(700, 800))))
|
2016-04-13 00:04:21 +00:00
|
|
|
r4 = self.segment.rawdata.get_indexed(order)
|
|
|
|
s4 = DefaultSegment(r4)
|
2017-05-07 20:28:15 +00:00
|
|
|
print(s4.byte_bounds_offset(), len(s4), s4.__getstate__())
|
2016-04-04 19:54:59 +00:00
|
|
|
|
|
|
|
slist = [s2, s3, s4]
|
|
|
|
for s in slist:
|
2017-05-07 20:28:15 +00:00
|
|
|
print(s)
|
2016-04-04 19:54:59 +00:00
|
|
|
j = jsonpickle.dumps(slist)
|
2017-05-07 20:28:15 +00:00
|
|
|
print(j)
|
2016-04-04 19:54:59 +00:00
|
|
|
|
|
|
|
slist2 = jsonpickle.loads(j)
|
2017-05-07 20:28:15 +00:00
|
|
|
print(slist2)
|
2016-04-04 19:54:59 +00:00
|
|
|
for s in slist2:
|
|
|
|
s.reconstruct_raw(self.segment.rawdata)
|
2017-05-07 20:28:15 +00:00
|
|
|
print(s)
|
2016-04-04 19:54:59 +00:00
|
|
|
|
|
|
|
for orig, rebuilt in zip(slist, slist2):
|
2017-05-07 20:28:15 +00:00
|
|
|
print("orig", orig.data[:])
|
|
|
|
print("rebuilt", rebuilt.data[:])
|
2016-04-04 19:54:59 +00:00
|
|
|
assert np.array_equal(orig[:], rebuilt[:])
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
t = TestJsonPickle()
|
|
|
|
t.setup()
|
|
|
|
t.test_simple()
|