170
171
# back to the original size
171
172
self.assertSizeOf(4, CustomSize(-1), has_gc=True)
174
def test_size_of_special(self):
175
class CustomWithoutSizeof(object):
185
obj = CustomWithoutSizeof()
186
self.assertSizeOf(4, obj)
187
_scanner.add_special_size('CustomWithoutSizeof', _size_32, _size_64)
189
self.assertSizeOf(200, obj)
191
_scanner.add_special_size('CustomWithoutSizeof', None, None)
192
self.assertEqual([obj], log)
194
self.assertSizeOf(4, obj)
195
self.assertEqual([], log)
197
def test_size_of_special_neg1(self):
198
# Returning -1 falls back to the regular __sizeof__, etc interface
199
class CustomWithoutSizeof(object):
205
obj = CustomWithoutSizeof()
206
self.assertSizeOf(4, obj)
207
_scanner.add_special_size('CustomWithoutSizeof', _size_neg1, _size_neg1)
209
self.assertSizeOf(4, obj)
211
_scanner.add_special_size('CustomWithoutSizeof', None, None)
212
self.assertEqual([obj], log)
214
def test_size_of_zlib_compress_obj(self):
215
# zlib compress objects allocate a lot of extra buffers, we want to
216
# track that. Note that we are approximating it, because we don't
217
# actually inspect the C attributes. But it is a closer approximation
218
# than not doing this.
219
c = zlib.compressobj()
220
self.assertTrue(_scanner.size_of(c) > 256000)
221
self.assertEqual(0, _scanner.size_of(c) % _scanner._word_size)
223
def test_size_of_zlib_decompress_obj(self):
224
d = zlib.decompressobj()
225
self.assertTrue(_scanner.size_of(d) > 30000)
226
self.assertEqual(0, _scanner.size_of(d) % _scanner._word_size)
174
229
def _string_to_json(s):