mirror of
https://github.com/robmcmullen/atrcopy.git
synced 2024-12-28 15:29:33 +00:00
Fixed segment resize that wasn't updating data/style attrs in DefaultSegment
This commit is contained in:
parent
a739b19cf2
commit
3efb3d1afa
@ -3,7 +3,6 @@ import cStringIO
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from profilehooks import coverage
|
|
||||||
|
|
||||||
from errors import *
|
from errors import *
|
||||||
from utils import to_numpy, to_numpy_list
|
from utils import to_numpy, to_numpy_list
|
||||||
@ -170,6 +169,8 @@ class SegmentData(object):
|
|||||||
else:
|
else:
|
||||||
self.data = newdata
|
self.data = newdata
|
||||||
self.style = newstyle
|
self.style = newstyle
|
||||||
|
else:
|
||||||
|
raise ValueError("Can't resize a view of a segment")
|
||||||
|
|
||||||
def replace_arrays(self, base_raw):
|
def replace_arrays(self, base_raw):
|
||||||
newsize = len(base_raw)
|
newsize = len(base_raw)
|
||||||
@ -365,13 +366,16 @@ class DefaultSegment(object):
|
|||||||
|
|
||||||
def set_raw(self, rawdata):
|
def set_raw(self, rawdata):
|
||||||
self.rawdata = rawdata
|
self.rawdata = rawdata
|
||||||
self.data = rawdata.get_data()
|
self.update_raw_pointers()
|
||||||
self.style = rawdata.get_style()
|
|
||||||
self._search_copy = None
|
|
||||||
|
|
||||||
def get_raw(self):
|
def get_raw(self):
|
||||||
return self.rawdata
|
return self.rawdata
|
||||||
|
|
||||||
|
def update_raw_pointers(self):
|
||||||
|
self.data = self.rawdata.get_data()
|
||||||
|
self.style = self.rawdata.get_style()
|
||||||
|
self._search_copy = None
|
||||||
|
|
||||||
def resize(self, newsize, zeros=True):
|
def resize(self, newsize, zeros=True):
|
||||||
""" Resize the data arrays.
|
""" Resize the data arrays.
|
||||||
|
|
||||||
@ -404,6 +408,7 @@ class DefaultSegment(object):
|
|||||||
|
|
||||||
def replace_data(self, container):
|
def replace_data(self, container):
|
||||||
self.rawdata.replace_arrays(container.rawdata)
|
self.rawdata.replace_arrays(container.rawdata)
|
||||||
|
self.update_raw_pointers()
|
||||||
|
|
||||||
def __getstate__(self):
|
def __getstate__(self):
|
||||||
"""Custom jsonpickle state save routine
|
"""Custom jsonpickle state save routine
|
||||||
|
@ -349,29 +349,39 @@ class TestResize(object):
|
|||||||
self.container.can_resize = True
|
self.container.can_resize = True
|
||||||
|
|
||||||
def test_subset(self):
|
def test_subset(self):
|
||||||
|
# check to see data a view of some rawdata will be the same when the
|
||||||
|
# rawdata is resized.
|
||||||
c = self.container
|
c = self.container
|
||||||
assert not c.rawdata.is_indexed
|
assert not c.rawdata.is_indexed
|
||||||
offset = 1000
|
offset = 1000
|
||||||
s = DefaultSegment(c.rawdata[offset:offset + offset], 0)
|
s = DefaultSegment(c.rawdata[offset:offset + offset], 0)
|
||||||
assert not s.rawdata.is_indexed
|
assert not s.rawdata.is_indexed
|
||||||
|
|
||||||
|
# Check that the small view has the same data as its parent
|
||||||
for i in range(offset):
|
for i in range(offset):
|
||||||
assert s[i] == c[i + offset]
|
assert s[i] == c[i + offset]
|
||||||
requested = 8192
|
|
||||||
|
# keep a copy of the old raw data of the subset
|
||||||
oldraw = s.rawdata.copy()
|
oldraw = s.rawdata.copy()
|
||||||
oldid = id(s.rawdata)
|
oldid = id(s.rawdata)
|
||||||
|
|
||||||
|
requested = 8192
|
||||||
oldsize, newsize = c.resize(requested)
|
oldsize, newsize = c.resize(requested)
|
||||||
assert newsize == requested
|
assert newsize == requested
|
||||||
s.replace_data(c)
|
s.replace_data(c) # s should point to the same offset in the resized data
|
||||||
assert id(s.rawdata) == oldid
|
assert id(s.rawdata) == oldid # segment rawdata object should be same
|
||||||
assert id(oldraw.order) == id(s.rawdata.order)
|
assert id(oldraw.order) == id(s.rawdata.order) # order the same
|
||||||
for i in range(offset):
|
for i in range(offset): # check values compared to parent
|
||||||
assert s[i] == c[i + offset]
|
assert s[i] == c[i + offset]
|
||||||
|
|
||||||
|
# check for changes in parent/view reflected so we see that it's
|
||||||
|
# pointing to the same array in memory
|
||||||
newbase = c.rawdata
|
newbase = c.rawdata
|
||||||
newsub = s.rawdata
|
newsub = s.rawdata
|
||||||
print c.rawdata.data
|
print c.rawdata.data[offset:offset+offset]
|
||||||
print s.rawdata.data[:]
|
print s.rawdata.data[:]
|
||||||
s.rawdata.data[:] = 111
|
s.rawdata.data[:] = 111
|
||||||
print c.rawdata.data
|
print c.rawdata.data[offset:offset+offset]
|
||||||
print s.rawdata.data[:]
|
print s.rawdata.data[:]
|
||||||
for i in range(offset):
|
for i in range(offset):
|
||||||
assert s[i] == c[i + offset]
|
assert s[i] == c[i + offset]
|
||||||
@ -411,11 +421,14 @@ if __name__ == "__main__":
|
|||||||
# t.test_indexed()
|
# t.test_indexed()
|
||||||
# t.test_indexed_sub()
|
# t.test_indexed_sub()
|
||||||
# t.test_interleave()
|
# t.test_interleave()
|
||||||
t = TestSegment1()
|
# t = TestSegment1()
|
||||||
t.setup()
|
# t.setup()
|
||||||
t.test_xex()
|
# t.test_xex()
|
||||||
# t.test_copy()
|
# t.test_copy()
|
||||||
# t = TestComments()
|
# t = TestComments()
|
||||||
# t.setup()
|
# t.setup()
|
||||||
# t.test_split_data_at_comment()
|
# t.test_split_data_at_comment()
|
||||||
# t.test_restore_comments()
|
# t.test_restore_comments()
|
||||||
|
t = TestResize()
|
||||||
|
t.setup()
|
||||||
|
t.test_subset()
|
||||||
|
Loading…
Reference in New Issue
Block a user