17
17
array creation. If it does, this call empties that cache. Implement this
18
18
as a no-op if ``get_data()`` does not cache.
19
19
* ``img[something]`` generates an informative TypeError
20
+ * ``img.in_memory`` is True for an array image, and for a proxy image that is
21
+ cached, but False otherwise.
20
22
"""
21
23
from __future__ import division , print_function , absolute_import
22
24
@@ -172,7 +174,11 @@ def validate_data(self, imaker, params):
172
174
assert_false (isinstance (img .dataobj , np .ndarray ))
173
175
proxy_data = np .asarray (img .dataobj )
174
176
proxy_copy = proxy_data .copy ()
177
+ # Not yet cached, proxy image: in_memory is False
178
+ assert_false (img .in_memory )
175
179
data = img .get_data ()
180
+ # Data now cached
181
+ assert_true (img .in_memory )
176
182
assert_false (proxy_data is data )
177
183
# changing array data does not change proxy data, or reloaded data
178
184
data [:] = 42
@@ -182,9 +188,12 @@ def validate_data(self, imaker, params):
182
188
assert_array_equal (img .get_data (), 42 )
183
189
# until we uncache
184
190
img .uncache ()
191
+ # Which unsets in_memory
192
+ assert_false (img .in_memory )
185
193
assert_array_equal (img .get_data (), proxy_copy )
186
194
else : # not proxy
187
195
assert_true (isinstance (img .dataobj , np .ndarray ))
196
+ assert_true (img .in_memory )
188
197
non_proxy_data = np .asarray (img .dataobj )
189
198
data = img .get_data ()
190
199
assert_true (non_proxy_data is data )
@@ -196,9 +205,11 @@ def validate_data(self, imaker, params):
196
205
# Unache has no effect
197
206
img .uncache ()
198
207
assert_array_equal (img .get_data (), 42 )
199
- # Read only
208
+ # dataobj is read only
200
209
fake_data = np .zeros (img .shape ).astype (img .get_data_dtype ())
201
210
assert_raises (AttributeError , setattr , img , 'dataobj' , fake_data )
211
+ # So is in_memory
212
+ assert_raises (AttributeError , setattr , img , 'in_memory' , False )
202
213
203
214
def validate_data_deprecated (self , imaker , params ):
204
215
# Check _data property still exists, but raises warning
0 commit comments