~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test__simple_set.py

  • Committer: John Arbash Meinel
  • Date: 2010-08-02 19:20:30 UTC
  • mto: This revision was merged to the branch mainline in revision 5369.
  • Revision ID: john@arbash-meinel.com-20100802192030-p5ofsyvopbog4xj3
Simplify the test to better cope with platform and version variation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
380
380
        obj.discard(k2)
381
381
        self.assertRaises(RuntimeError, iterator.next)
382
382
 
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:
387
 
            int_size = sizeof(1)
388
 
            # A python Int is 3 longs
389
 
            # 1: PyType *
390
 
            # 2: refcnt
391
 
            # 3: long val
392
 
            return int_size / 3
393
 
        return None
394
 
 
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)
399
 
        # 1: PyType *
400
 
        # 2: refcnt
401
 
        # 3: vtable *
402
 
        # 4: _used
403
 
        # 5: _fill
404
 
        # 6: _mask
405
 
        # 7: _table*
406
 
        # (_mask+1) pointers
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()
409
 
        n_words = 7 + 1024
410
 
        s = obj.__sizeof__()
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"
417
 
                          % (s, n_words))
418
 
        else:
419
 
            self.assertEqual(n_words * plat_size, s)
 
391
        self.assertTrue(obj.__sizeof__() > 4096)