Exemplo n.º 1
0
    def test_size_of_special(self):
        class CustomWithoutSizeof(object):
            pass

        log = []

        def _size_32(obj):
            log.append(obj)
            return 800

        def _size_64(obj):
            log.append(obj)
            return 1600

        obj = CustomWithoutSizeof()
        self.assertSizeOf(4, obj)
        _scanner.add_special_size('CustomWithoutSizeof', _size_32, _size_64)
        try:
            self.assertSizeOf(200, obj)
        finally:
            _scanner.add_special_size('CustomWithoutSizeof', None, None)
        self.assertEqual([obj], log)
        del log[:]
        self.assertSizeOf(4, obj)
        self.assertEqual([], log)
Exemplo n.º 2
0
 def test_size_of_special_neg1(self):
     # Returning -1 falls back to the regular __sizeof__, etc interface
     class CustomWithoutSizeof(object):
         pass
     log = []
     def _size_neg1(obj):
         log.append(obj)
         return -1
     obj = CustomWithoutSizeof()
     self.assertSizeOf(4, obj)
     _scanner.add_special_size('CustomWithoutSizeof', _size_neg1, _size_neg1)
     try:
         self.assertSizeOf(4, obj)
     finally:
         _scanner.add_special_size('CustomWithoutSizeof', None, None)
     self.assertEqual([obj], log)
Exemplo n.º 3
0
 def test_size_of_special_neg1(self):
     # Returning -1 falls back to the regular __sizeof__, etc interface
     class CustomWithoutSizeof(object):
         pass
     log = []
     def _size_neg1(obj):
         log.append(obj)
         return -1
     obj = CustomWithoutSizeof()
     self.assertSizeOf(4, obj)
     _scanner.add_special_size('CustomWithoutSizeof', _size_neg1, _size_neg1)
     try:
         self.assertSizeOf(4, obj)
     finally:
         _scanner.add_special_size('CustomWithoutSizeof', None, None)
     self.assertEqual([obj], log)
Exemplo n.º 4
0
 def test_size_of_special(self):
     class CustomWithoutSizeof(object):
         pass
     log = []
     def _size_32(obj):
         log.append(obj)
         return 800
     def _size_64(obj):
         log.append(obj)
         return 1600
         
     obj = CustomWithoutSizeof()
     self.assertSizeOf(4, obj)
     _scanner.add_special_size('CustomWithoutSizeof', _size_32, _size_64)
     try:
         self.assertSizeOf(200, obj)
     finally:
         _scanner.add_special_size('CustomWithoutSizeof', None, None)
     self.assertEqual([obj], log)
     del log[:]
     self.assertSizeOf(4, obj)
     self.assertEqual([], log)