def test_flatsize(failf=None, stdf=None):
    '''Compare the results of **flatsize()** without using ``sys.getsizeof()``
       with the accurate sizes returned by ``sys.getsizeof()``.

       Return the total number of tests and number of unexpected failures.

       Expect differences for sequences as dicts, lists, sets, tuples, etc.
       While this is no proof for the accuracy of **flatsize()** on Python
       builds without ``sys.getsizeof()``, it does provide some evidence that
       function **flatsize()** produces reasonable and usable results.
    '''
    global _getsizeof
    t, g, e = [], _getsizeof, 0
    if g:
        for v in _values(_typedefs):
            t.append(v.type)
            try:  # creating one instance
                if v.type.__module__ not in ('io',):  # avoid 3.0 RuntimeWarning
                    t.append(v.type())
            except Exception:  # ignore errors
                pass
        t.extend(({1:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7, 8:8},
                  [1,2,3,4,5,6,7,8], ['1', '2', '3'], [0] * 100,
                  '12345678', 'x' * 1001,
                  (1,2,3,4,5,6,7,8), ('1', '2', '3'), (0,) * 100,
                  _Slots((1,2,3,4,5,6,7,8)), _Slots(('1', '2', '3')), _Slots((0,) * 100),
                  0, 1 << 8, 1 << 16, 1 << 32, 1 << 64, 1 << 128,
                  complex(0, 1), True, False))
        _getsizeof = None  # zap _getsizeof for flatsize()
        for o in t:
            a = flatsize(o)
            s = sys.getsizeof(o, 0)  # 0 as default #PYCHOK expected
            if a != s:
                if isinstance(o, (dict, list, set, frozenset, tuple, bytes)):
                    # flatsize() approximates length of sequences
                    x = ', expected failure'
                elif (isinstance(o, (type, bool, ABCMeta)) and
                      sys.version_info >= (3, 0)):
                    x = ', expected failure'
                elif isinstance(o, str) and sys.version_info >= (3, 3):
                    x = ', expected failure'
                else:
                    x = ', %r' % _typedefof(o)
                    e += 1
                    if failf:  # report failure
                        failf('%s vs %s for %s: %s',
                              a, s, _nameof(type(o)), _repr(o))
                if stdf:
                   _printf('flatsize() %s vs sys.getsizeof() %s for %s: %s%s',
                            a, s, _nameof(type(o)), _repr(o), x, file=stdf)
        _getsizeof = g  # restore
    return len(t), e
def test_flatsize ( failf = None , stdf = None ) : global _getsizeof t , g , e = [ ] , _getsizeof , 0 if g : for v in _values ( _typedefs ) : t . append ( v . type ) try : if v . type . __module__ not in ( 'io' , ) : t . append ( v . type ( ) ) except Exception : pass t . extend ( ( { 1 : 1 , 2 : 2 , 3 : 3 , 4 : 4 , 5 : 5 , 6 : 6 , 7 : 7 , 8 : 8 } , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] , [ '1' , '2' , '3' ] , [ 0 ] * 100 , '12345678' , 'x' * 1001 , ( 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ) , ( '1' , '2' , '3' ) , ( 0 , ) * 100 , _Slots ( ( 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ) ) , _Slots ( ( '1' , '2' , '3' ) ) , _Slots ( ( 0 , ) * 100 ) , 0 , 1 << 8 , 1 << 16 , 1 << 32 , 1 << 64 , 1 << 128 , complex ( 0 , 1 ) , True , False ) ) _getsizeof = None for o in t : a = flatsize ( o ) s = sys . getsizeof ( o , 0 ) if a != s : if isinstance ( o , ( dict , list , set , frozenset , tuple , bytes ) ) : x = ', expected failure' elif ( isinstance ( o , ( type , bool , ABCMeta ) ) and sys . version_info >= ( 3 , 0 ) ) : x = ', expected failure' elif isinstance ( o , str ) and sys . version_info >= ( 3 , 3 ) : x = ', expected failure' else : x = ', %r' % _typedefof ( o ) e += 1 if failf : failf ( '%s vs %s for %s: %s' , a , s , _nameof ( type ( o ) ) , _repr ( o ) ) if stdf : _printf ( 'flatsize() %s vs sys.getsizeof() %s for %s: %s%s' , a , s , _nameof ( type ( o ) ) , _repr ( o ) , x , file = stdf ) _getsizeof = g return len ( t ) , e
Compare the results of **flatsize()** without using ``sys.getsizeof()``
       with the accurate sizes returned by ``sys.getsizeof()``.

       Return the total number of tests and number of unexpected failures.

       Expect differences for sequences as dicts, lists, sets, tuples, etc.
       While this is no proof for the accuracy of **flatsize()** on Python
       builds without ``sys.getsizeof()``, it does provide some evidence that
       function **flatsize()** produces reasonable and usable results.