Esempio n. 1
0
 def _print_functions(self,
                      obj,
                      name=None,
                      align=8,
                      detail=MAX,
                      code=False,
                      limit=MAX,
                      opt='',
                      **unused):
     if name:
         self._printf('%sasizeof functions for %s ... %s', os.linesep, name,
                      opt)
     self._printf('%s(): %s', ' basicsize', asizeof.basicsize(obj))
     self._printf('%s(): %s', ' itemsize', asizeof.itemsize(obj))
     self._printf('%s(): %r', ' leng', asizeof.leng(obj))
     self._printf('%s(): %s', ' refs', _repr(asizeof.refs(obj)))
     self._printf('%s(): %s', ' flatsize',
                  asizeof.flatsize(obj, align=align))  # , code=code
     self._printf(
         '%s(): %s', ' asized',
         asizeof.asized(obj,
                        align=align,
                        detail=detail,
                        code=code,
                        limit=limit))
Esempio n. 2
0
 def _print_functions(self, obj, name=None, align=8, detail=MAX, code=False, limit=MAX,
                           opt='', **unused):
     if name:
         self._printf('%sasizeof functions for %s ... %s', os.linesep, name, opt)
     self._printf('%s(): %s', ' basicsize', asizeof.basicsize(obj))
     self._printf('%s(): %s', ' itemsize',  asizeof.itemsize(obj))
     self._printf('%s(): %r', ' leng',      asizeof.leng(obj))
     self._printf('%s(): %s', ' refs',     _repr(asizeof.refs(obj)))
     self._printf('%s(): %s', ' flatsize',  asizeof.flatsize(obj, align=align))  # , code=code
     self._printf('%s(): %s', ' asized',           asizeof.asized(obj, align=align, detail=detail, code=code, limit=limit))
Esempio n. 3
0
        def test_flatsize(self):
            '''Test asizeof.flatsize()
            '''
            l = ["spam", 2, 3, 4, "eggs", 6, 7, 8]
            for _type in (list, tuple, set, frozenset):
                data = _type(l)
                bsz = asizeof.basicsize(data)
                isz = asizeof.itemsize(data)
                lng = asizeof.leng(data)
                fsz = asizeof.flatsize(data)
                self.assertEqual(fsz, bsz + (lng * isz), (fsz, bsz, lng, isz))

            self.assertRaises(ValueError, asizeof.flatsize, l, **{'align': 3})
Esempio n. 4
0
        def test_flatsize(self):
            '''Test asizeof.flatsize()
            '''
            l = ["spam", 2, 3, 4, "eggs", 6, 7, 8]
            for _type in (list, tuple, set, frozenset):
                data = _type(l)
                bsz = asizeof.basicsize(data)
                isz = asizeof.itemsize(data)
                lng = asizeof.leng(data)
                fsz = asizeof.flatsize(data)
                self.assertEqual(fsz, bsz + (lng * isz), (fsz, bsz, lng, isz))

            self.assertRaises(ValueError, asizeof.flatsize, l, **{'align': 3})
Esempio n. 5
0
    def test_long(self):
        '''Test int and long examples'''
        try:
            _L5d  = long(1) << 64
            _L17d = long(1) << 256
            t = '<int>/<long>'
        except NameError:
            _L5d  = 1 << 64
            _L17d = 1 << 256
            t = '<int>'

        self._printf('%sasizeof(%s, align=%s, limit=%s) ... %s', os.linesep, t, 0, 0, '-int')
        for o in (1024, 1000000000,
                  1.0, 1.0e100, 1024, 1000000000,
                  self.MAX, 1 << 32, _L5d, -_L5d, _L17d, -_L17d):
            self._printf(" asizeof(%s) is %s (%s + %s * %s)", _repr(o), asizeof.asizeof(o, align=0, limit=0),
                                                         asizeof.basicsize(o), asizeof.leng(o), asizeof.itemsize(o))
Esempio n. 6
0
    def test_long(self):
        '''Test int and long examples'''
        try:
            _L5d  = long(1) << 64
            _L17d = long(1) << 256
            t = '<int>/<long>'
        except NameError:
            _L5d  = 1 << 64
            _L17d = 1 << 256
            t = '<int>'

        self._printf('%sasizeof(%s, align=%s, limit=%s) ... %s', os.linesep, t, 0, 0, '-int')
        for o in (1024, 1000000000,
                  1.0, 1.0e100, 1024, 1000000000,
                  self.MAX, 1 << 32, _L5d, -_L5d, _L17d, -_L17d):
            self._printf(" asizeof(%s) is %s (%s + %s * %s)", _repr(o), asizeof.asizeof(o, align=0, limit=0),
                                                         asizeof.basicsize(o), asizeof.leng(o), asizeof.itemsize(o))
Esempio n. 7
0
    def test_leng(self):
        '''Test asizeof.leng()
        '''
        l = [1,2,3,4]
        s = "spam"
        self.assert_(asizeof.leng(l) >= len(l), asizeof.leng(l))
        self.assertEqual(asizeof.leng(tuple(l)), len(l))
        self.assert_(asizeof.leng(set(l)) >= len(set(l)))
        self.assert_(asizeof.leng(s) >= len(s))

        # Python 3.0 ints behave like Python 2.x longs. leng() reports
        # None for old ints and >=1 for new ints/longs.
        self.assert_(asizeof.leng(42) in [None, 1], asizeof.leng(42))
        base = 2
        try:
            base = long(base)
        except NameError: # Python3.0
            pass
        self.assertEqual(asizeof.leng(base**8-1), 1)
        self.assertEqual(asizeof.leng(base**16-1), 1)
        self.assert_(asizeof.leng(base**32-1) >= 1)
        self.assert_(asizeof.leng(base**64-1) >= 2)
Esempio n. 8
0
    def test_leng(self):
        '''Test asizeof.leng()
        '''
        l = [1, 2, 3, 4]
        s = "spam"
        self.assert_(asizeof.leng(l) >= len(l), asizeof.leng(l))
        self.assertEqual(asizeof.leng(tuple(l)), len(l))
        self.assert_(asizeof.leng(set(l)) >= len(set(l)))
        self.assert_(asizeof.leng(s) >= len(s))

        # Python 3.0 ints behave like Python 2.x longs. leng() reports
        # None for old ints and >=1 for new ints/longs.
        self.assert_(asizeof.leng(42) in [None, 1], asizeof.leng(42))
        base = 2
        try:
            base = long(base)
        except NameError:  # Python3.0
            pass
        self.assertEqual(asizeof.leng(base**8 - 1), 1)
        self.assertEqual(asizeof.leng(base**16 - 1), 1)
        self.assert_(asizeof.leng(base**32 - 1) >= 1)
        self.assert_(asizeof.leng(base**64 - 1) >= 2)