2017-05-07 20:28:15 +00:00
|
|
|
from __future__ import print_function
|
2017-05-08 01:58:10 +00:00
|
|
|
from builtins import range
|
|
|
|
from builtins import object
|
2017-05-19 05:48:01 +00:00
|
|
|
from builtins import str
|
2016-06-06 21:31:51 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from atrcopy import DefaultSegment, SegmentData, get_xex, interleave_segments
|
|
|
|
|
|
|
|
|
2018-06-25 00:20:32 +00:00
|
|
|
class TestSegment:
|
2016-06-06 21:31:51 +00:00
|
|
|
def setup(self):
|
|
|
|
data = np.ones([4000], dtype=np.uint8)
|
|
|
|
r = SegmentData(data)
|
|
|
|
self.segment = DefaultSegment(r, 0)
|
|
|
|
|
2017-05-19 05:48:01 +00:00
|
|
|
def test_getstate(self):
|
|
|
|
state = self.segment.__getstate__()
|
|
|
|
for k, v in state.items():
|
|
|
|
print("k=%s v=%s type=%s" % (k, v, type(v)))
|
|
|
|
byte_type = type(str(u' ').encode('utf-8')) # py2 and py3
|
2017-05-20 06:12:31 +00:00
|
|
|
try:
|
|
|
|
u = unicode(" ")
|
|
|
|
except:
|
|
|
|
u = str(" ")
|
|
|
|
assert type(state['uuid']) == type(u)
|
2017-05-19 05:48:01 +00:00
|
|
|
|
|
|
|
def test_extra(self):
|
2016-06-06 21:31:51 +00:00
|
|
|
s = self.segment
|
|
|
|
s.set_comment([[4,5]], "test1")
|
|
|
|
s.set_comment([[40,50]], "test2")
|
|
|
|
s.set_style_ranges([[2,100]], comment=True)
|
|
|
|
s.set_style_ranges([[200, 299]], data=True)
|
|
|
|
for i in range(1,4):
|
|
|
|
for j in range(1, 4):
|
|
|
|
# create some with overlapping regions, some without
|
|
|
|
r = [500*j, 500*j + 200*i + 200]
|
|
|
|
s.set_style_ranges([r], user=i)
|
|
|
|
s.set_user_data([r], i, i*10 + j)
|
|
|
|
r = [100, 200]
|
|
|
|
s.set_style_ranges([r], user=4)
|
|
|
|
s.set_user_data([r], 4, 99)
|
|
|
|
r = [3100, 3200]
|
|
|
|
s.set_style_ranges([r], user=4)
|
|
|
|
s.set_user_data([r], 4, 99)
|
|
|
|
|
|
|
|
out = dict()
|
|
|
|
s.serialize_extra_to_dict(out)
|
2017-05-07 20:28:15 +00:00
|
|
|
print("saved", out)
|
2016-06-06 21:31:51 +00:00
|
|
|
|
|
|
|
data = np.ones([4000], dtype=np.uint8)
|
|
|
|
r = SegmentData(data)
|
|
|
|
s2 = DefaultSegment(r, 0)
|
|
|
|
s2.restore_extra_from_dict(out)
|
|
|
|
out2 = dict()
|
|
|
|
s2.serialize_extra_to_dict(out2)
|
2017-05-07 20:28:15 +00:00
|
|
|
print("loaded", out2)
|
2016-06-06 21:31:51 +00:00
|
|
|
assert out == out2
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
t = TestSegment()
|
|
|
|
t.setup()
|
2017-05-19 05:48:01 +00:00
|
|
|
t.test_getstate()
|