381
381
self.assertRaises(RuntimeError, iterator.next)
383
def get_platform_size(self):
384
"""Try to determine if we are on 32-bit or 64-bit architecture."""
385
sizeof = getattr(sys, 'getsizeof', None)
386
if sizeof is not None:
388
# A python Int is 3 longs
395
383
def test__sizeof__(self):
396
384
# SimpleSet needs a custom sizeof implementation, because it allocates
397
385
# memory that Python cannot directly see (_table).
398
# The size of a SimpleSet object is (in 32/64-bit objects)
407
# Default size is 1024 pointers
386
# Too much variability in platform sizes for us to give a fixed size
387
# here. However without a custom implementation, __sizeof__ would give
388
# us only the size of the object, and not its table. We know the table
389
# is at least 4bytes*1024entries in size.
408
390
obj = self.module.SimpleSet()
411
plat_size = self.get_platform_size()
412
if plat_size is None:
413
# We should either be 64-bit or 32-bit, but I don't know which
414
if s != n_words * 8 and s != n_words * 4:
415
self.fail("SimpleSet.__sizeof__() returned %s which is not"
416
" a 32-bit or 64-bit multiple of %s words"
419
self.assertEqual(n_words * plat_size, s)
391
self.assertTrue(obj.__sizeof__() > 4096)