B
    u9a/                 @   s   d dl Z d dlZd dlmZmZ d dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd aG dd de jZejjG dd de jZdd Zed	kre  dS )
    N)assert_python_okassert_python_failurec               @   s,  e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zejjdd Zdd Zdd  Zd!d" Zeeed#d$d%d& Zejjd'd( Zd)d* Zejjd+d, Z d-d. Z!d/d0 Z"d1d2 Z#d3d4 Z$d5d6 Z%d7d8 Z&d9d: Z'd;d< Z(d=d> Z)ejjd?d@ Z*dAdB Z+eejj,dCee- e./dDkdEdFdG Z0e1ej2ej3kdHdIdJ Z4djdLdMZ5dNdO Z6dkdPdQZ7dRdS Z8dTdU Z9dVdW Z:dXdY Z;ejjdZd[ Z<eeed\d]d^d_ Z=ejj>d`da Z?eeedbdcddde Z@dfdg ZAdhdi ZBdKS )lSysModuleTestc             C   s   t j| _t j| _t j| _d S )N)sysstdoutorig_stdoutstderrorig_stderrdisplayhookorig_displayhook)self r   /usr/lib/python3.7/test_sys.pysetUp   s    zSysModuleTest.setUpc             C   s&   | j t_| jt_| jt_tj	  d S )N)
r   r   r   r	   r   r   r
   testsupportZreap_children)r   r   r   r   tearDown   s    zSysModuleTest.tearDownc             C   s   dd l }t }|t_tj}| t| t|dr6|`	|d  | 
| d | t|d  |d | 
| d | 
|j	d t`| t|d d S )Nr   _ *   z42
)builtinsioStringIOr   r   __displayhook__assertRaises	TypeErrorhasattrr   assertEqualgetvalue
assertTrueRuntimeError)r   r   outZdhr   r   r   test_original_displayhook!   s    
z'SysModuleTest.test_original_displayhookc             C   s"   t `tddd}| tt| d S )N42z<string>single)r   r
   compiler   r    eval)r   coder   r   r   test_lost_displayhook6   s    z#SysModuleTest.test_lost_displayhookc             C   s,   dd }|t _tddd}| tt| d S )Nc             S   s   t d S )N)
ValueError)objr   r   r   baddisplayhook<   s    z=SysModuleTest.test_custom_displayhook.<locals>.baddisplayhookr#   z<string>r$   )r   r
   r%   r   r)   r&   )r   r+   r'   r   r   r   test_custom_displayhook;   s    z%SysModuleTest.test_custom_displayhookc          
   C   st   t  }|t_tj}| t| ytdW n. tk
rZ } z|t   W d d }~X Y nX | 	|
 d d S )Nr   zValueError: 42
)r   r   r   r   __excepthook__r   r   r)   exc_infor   r   endswith)r   errZehexcr   r   r   test_original_excepthookB   s    z&SysModuleTest.test_original_excepthookc          	   C   s<   t jd}tddd W d Q R X | d| k d S )Nr      1zETypeError: print_exception(): Exception expected for value, str found)r   r   Zcaptured_outputr   
excepthookr   r   )r   r   r   r   r   test_excepthookP   s    zSysModuleTest.test_excepthookc          	      s    ttjdd   t}t  W d Q R X  |jj tdd\}}} 	|d  	|d  	|d   t}td W d Q R X  	|jjd   t}td W d Q R X  	|jjd   t}td W d Q R X  	|jjd   t}td W d Q R X  	|jjd t
dd	\}}} 	|d
  	|d  	|d  fdd}|dd |dd |dddd d S )Nr   z-czimport sys; sys.exit()r       )r   exit)      zraise SystemExit(47)/   c                sR   t d| f|\}}} |d  |d  ||dt|t|f  d S )Nz-cr3   r7   z%s doesn't start with %s)r   r   r   
startswithascii)r'   expectedZenv_varsrcr!   r0   )r   r   r   check_exit_message   s
    z3SysModuleTest.test_exit.<locals>.check_exit_messagez?import sys; sys.stderr.write("unflushed,"); sys.exit("message")s   unflushed,messagez)import sys; sys.exit("surrogates:\uDCFF")s   surrogates:\udcffzimport sys; sys.exit("h\xe9")s   hzlatin-1)PYTHONIOENCODING)r   r   r   r8   
SystemExitassertIsNone	exceptionr'   r   r   r   )r   cmr?   r!   r0   r@   r   )r   r   	test_exitY   sD    	zSysModuleTest.test_exitc             C   s$   |  ttjd | t t d S )Nr   )r   r   r   getdefaultencodingassertIsInstancestr)r   r   r   r   test_getdefaultencoding   s    z%SysModuleTest.test_getdefaultencodingc          	   C   sh   t  V t d | ttj t }x.ddd|fD ]}t| | t | q8W W d Q R X d S )Nignorer   d   x   )	warningscatch_warningssimplefilterr   r   r   setcheckintervalgetcheckintervalr   )r   orignr   r   r   test_setcheckinterval   s    


z#SysModuleTest.test_setcheckintervalc          	   C   s   |  ttj |  ttjd |  ttjd |  ttjd t }| |dk | z4x.ddd|fD ]}t| | t | qfW W d t| X d S )Nag      g        g      ?gh㈵>g?g      @)r   r   r   setswitchintervalr)   getswitchintervalr   ZassertAlmostEqual)r   rS   rT   r   r   r   test_switchinterval   s    
z!SysModuleTest.test_switchintervalc             C   s^   |  ttjd t }|  ttj |  ttjd td | t d t| d S )Nr   ii'  )r   r   r   getrecursionlimitsetrecursionlimitr)   r   )r   oldlimitr   r   r   test_recursionlimit   s    
z!SysModuleTest.test_recursionlimitc          	      s   t tdrt r| d t } fdd zPxJdD ]B}yt| W n tk
r`   w8Y nX | t  | t  q8W W d t| X d S )Ngettracez(fatal error if run with a trace functionc                  s
      d S )Nr   r   )fr   r   r_      s    z5SysModuleTest.test_recursionlimit_recovery.<locals>.f)
      2   K   rL      i  )r   r   r^   ZskipTestrZ   r[   RecursionErrorr   )r   r\   depthr   )r_   r   test_recursionlimit_recovery   s    

z*SysModuleTest.test_recursionlimit_recoveryc          	      sz   ddl m   fddt }zDtd x4dD ],}|dkrL|d }n|d	 d
 }|| q6W W d t| X d S )Nr   )get_recursion_depthc          	      sP     }|| krB t}t| W d Q R X t|jd n
| | d S )Nz\cannot set the recursion limit to [0-9]+ at the recursion depth [0-9]+: the limit is too low)r   re   r   r[   ZassertRegexrI   rD   )rf   limitZrecursion_depthrE   )rh   r   set_recursion_limit_at_depthr   r   rj      s    zZSysModuleTest.test_setrecursionlimit_recursion_depth.<locals>.set_recursion_limit_at_depthi  )r`   ra   rb   rc   rL         rl   rb         )	_testcapirh   r   rZ   r[   )r   r\   ri   rf   r   )rh   r   rj   r   &test_setrecursionlimit_recursion_depth   s    


z4SysModuleTest.test_setrecursionlimit_recursion_depthc          	   C   sv   t d}tj X xPdD ]H}tjtjd|| gtj	d}|
 d }| |j|j | d| qW W d Q R X d S )Nz
            import sys

            def f():
                try:
                    f()
                except RecursionError:
                    f()

            sys.setrecursionlimit(%d)
            f())rb   i  z-c)r   r3   s6   Fatal Python error: Cannot recover from stack overflow)textwrapdedentr   r   ZSuppressCrashReport
subprocessPopenr   
executablePIPEcommunicater   
returncodeassertIn)r   r'   isubr0   r   r   r   test_recursionlimit_fatalerror   s    


z,SysModuleTest.test_recursionlimit_fatalerrorc             C   sv  t jtd t }| t|d | |d t | |d t | |d t | |d t | |d t	 | 
ttj|d | |jt | |jt | |jt | |jt | |jt	 | |jt | |jt | |jt | |jt | |d |j | |d |j | |d |j | |d |j | |d |j t \}}}}}d S )Ngetwindowsversion   r   r3      rm   rn   )r   r   get_attributer   r}   r   lenrH   intrI   r   
IndexErroroperatorgetitemmajorminorZbuildplatformZservice_packZservice_pack_minorZservice_pack_majorZ
suite_maskZproduct_type)r   vZmajminZbuildnoZplatZcsdr   r   r   test_getwindowsversion  s0    z$SysModuleTest.test_getwindowsversionc             C   s   |  ttjtd d S )Nr   )r   r   r   call_tracingtype)r   r   r   r   test_call_tracing4  s    zSysModuleTest.test_call_tracingsetdlopenflagsztest needs sys.setdlopenflags()c             C   sf   |  ttd | ttjd t }| ttj t|d  | t |d  t| d S )Ngetdlopenflagsr   r3   )r   r   r   r   r   r   r   r   )r   Zoldflagsr   r   r   test_dlopenflags7  s    zSysModuleTest.test_dlopenflagsc             C   sd   |  ttj td }d a| td |d  b| td | ttdr`| t t	 d S )Nr3   gettotalrefcount)
r   r   r   getrefcountrT   r   r   rH   r   r   )r   cr   r   r   test_refcountB  s    

zSysModuleTest.test_refcountc             C   s>   |  ttjdd |  ttjd | tjjt j	k d S )Nr   i 5w)
r   r   r   	_getframer)   r   r   test_getframe__code__f_code)r   r   r   r   r   R  s
    zSysModuleTest.test_getframec                sv  dd l dd l}   g fdd} fddj|d}|     | td d }t	 }x$|D ]}| 
|t | |d qW  }| || | || ||}| |t k ||}||}	x0t|	D ]\}
\}}}}|dkrP qW | d	 | |d
 |	|
d  \}}}}| |d | |ddg   |  d S )Nr   c                  s
      d S )Nr   r   )g456r   r   f123g  s    z/SysModuleTest.test_current_frames.<locals>.f123c                  s"           d S )N)append	get_identsetwaitr   )	entered_gleave_gthread_info	threadingr   r   r   j  s    z/SysModuleTest.test_current_frames.<locals>.g456)targetr3   r   z)didn't find f123() on thread's call stackzg456()r   zleave_g.wait()zentered_g.set())r   	tracebackZEventZThreadstartr   r   r   r   _current_framesrH   r   assertGreaterr   ry   popr   r   extract_stack	enumerateZfailr   join)r   r   r   tZ	thread_iddtidZmain_idframestackrz   filenamelinenofuncnameZ
sourceliner   )r   r   r   r   r   r   test_current_frames[  sB    




z!SysModuleTest.test_current_framesc             C   s   |  tjt |  tjt | tjd |  tjt	 |  tj
t |  tjt |  tjt |  tjt | ttjd | tjjd | ttjd | tjjd dk | tjjdk | ttjjt | ttjjt |  tjt | ttjd | tjjdtjj  x@tddD ]2}| t|tjjd tjjdd	tjj q8W |  tjj t |  tjj!t |  tjj"t t#$d
}tjj%dkr.| tjj&ddh | tjj'dddh |dkr| tjj%d n0|dkr| tjj%d n| tjj%ddh n| |d | (tjj)d | tjj)d |  tj*t |  tj+t | tj+d |  tj,t |  tj-t |  tj.t |  tj/t tj0}|  |d d  t	 | t|d |  |d t |  |d t |  |d t | |d d |  |d t |  |j1t |  |j2t |  |j3t | |j4d |  |j5t | |d |j1 | |d |j2 | |d |j3 | |d |j4 | |d |j5 | |dk |  tj6t | tj6d tj,7ds|  tj8t d S )N)littleZbig   r   r~   r   r3   	   rL   z'sys.hash_info.modulus {} is a non-primeZPy_HASH_ALGORITHM>   	siphash24fnv    @      r   r      i rm   )alphabeta	candidatefinalrn   )r3   r   r   )Zshortlegacywin)9rH   r   api_versionr   argvlistry   	byteorderbuiltin_module_namestuple	copyrightrI   exec_prefixbase_exec_prefixru   r   r   
float_inforadixint_infor   bits_per_digitsizeof_digitr   
hexversion	hash_info
assertLessmoduluswidthrangepowformatinfnanimag	sysconfigZget_config_var	algorithm	hash_bits	seed_bitsassertGreaterEqualcutoffmaxsize
maxunicoder   prefixbase_prefixversionversion_infor   r   microreleaselevelserialfloat_repr_styler<   abiflags)r   xZalgovir   r   r   test_attributes  s    


zSysModuleTest.test_attributesc             C   s6   t j}| t|d | |jd | |jd d S )Nrm   )ntZpthreadZsolarisN)Z	semaphorez
mutex+condN)r   r   r   r   ry   namelock)r   infor   r   r   test_thread_info  s    zSysModuleTest.test_thread_infoc             C   s   |  tjjtjj d S )N)r   r   
__stdout__encoding
__stderr__)r   r   r   r   
test_43581  s    zSysModuleTest.test_43581c             C   s~   t d7 a | ttj dtt  }| t||k |  }| t||k G dd dt}| ttj|d d S )Nr3   znever interned beforec               @   s   e Zd Zdd ZdS )z$SysModuleTest.test_intern.<locals>.Sc             S   s   dS )N{   r   )r   r   r   r   __hash__  s    z-SysModuleTest.test_intern.<locals>.S.__hash__N)__name__
__module____qualname__r   r   r   r   r   S  s   r   abc)numrunsr   r   r   internrI   r   swapcase)r   ss2r   r   r   r   test_intern  s    zSysModuleTest.test_internc             C   s   |  tj d}xJ|D ]B}|  ttj|| |dkr:tnt}| tttj||| qW |  t	tj | t
tjt
| | tjjdddh d S )N)debuginspectinteractiveoptimizedont_write_bytecodeno_user_siteno_siteignore_environmentverbosebytes_warningquiethash_randomizationisolateddev_mode	utf8_moder  r   r3   r   )r   r   flagsr   boolr   r   r   getattrreprr   ry   r  )r   Zattrsattr	attr_typer   r   r   test_sys_flags  s    
zSysModuleTest.test_sys_flagsc          	   C   sH   t |}| t |  W d Q R X | t || W d Q R X d S )N)r   r   r   __new__)r   Zsys_attrr  r   r   r   assert_raise_on_new_sys_type  s
    z*SysModuleTest.assert_raise_on_new_sys_typec             C   s   |  tj d S )N)r  r   r  )r   r   r   r   test_sys_flags_no_instantiation%  s    z-SysModuleTest.test_sys_flags_no_instantiationc             C   s   |  tj d S )N)r  r   r   )r   r   r   r   &test_sys_version_info_no_instantiation(  s    z4SysModuleTest.test_sys_version_info_no_instantiationc             C   s    t jtd | t  d S )Nr}   )r   r   r   r   r  r}   )r   r   r   r   +test_sys_getwindowsversion_no_instantiation+  s    z9SysModuleTest.test_sys_getwindowsversion_no_instantiationc             C   s   t   d S )N)r   _clear_type_cache)r   r   r   r   test_clear_type_cache0  s    z#SysModuleTest.test_clear_type_cachec             C   s  t tj}d|d< tjtjddgtj|d}| d 	 }dtj
 d}| || d|d< tjtjddgtj|d}| d 	 }| |d	 d
|d< tjtjddgtjtj|d}| \}}| |d | d| | d| d|d< tjtjddgtjtj|d}| \}}| |d | d| | d| d|d< tjtjddgtj|d}| d 	 }| |d d S )Ncp424rA   z-czprint(chr(0xa2)))r   envr      ¢zascii:replace   ?r=   )r   r   r&  r7   s   UnicodeEncodeError:s   '\xa2'zascii:z:surrogateescapezprint(chr(0xdcbd))   )dictosenvironrs   rt   r   ru   rv   rw   striplinesepencoder   ry   )r   r&  pr!   r>   r0   r   r   r   test_ioencoding4  sB    
zSysModuleTest.test_ioencodingz*requires OS support of non-ASCII encodingsFz$requires FS encoding to match localec             C   s^   t tj}d|d< tjtjddtjj	 gtj
|d}| d  }| |ttjj	 d S )Nr   rA   z-cz	print(%a))r   r&  r   )r*  r+  r,  rs   rt   r   ru   r   r   FS_NONASCIIrv   rw   r-  r   fsencode)r   r&  r0  r!   r   r   r   test_ioencoding_nonascii_  s    

z&SysModuleTest.test_ioencoding_nonasciizTest is not venv-compatiblec          	   C   s   |  tjtjtj tjtjtj}tj	dddgtjtj
|d}| d }| d}|  | |dttjdd	g d S )
NZnonexistentz-czEimport sys; print(sys.executable.encode("ascii", "backslashreplace")))ru   r   cwdr   ASCIIzb''r=   backslashreplace)r   r+  pathabspathr   ru   dirnamerealpathrs   rt   rv   rw   r-  decoder   ry   r  r/  )r   Z
python_dirr0  r   ru   r   r   r   test_executablem  s    zSysModuleTest.test_executableNc             C   s(   |  | t| |r$| || d S )N)ZassertIsNotNonecodecslookupr   )r   fs_encodingr>   r   r   r   check_fsencoding  s    

zSysModuleTest.check_fsencodingc             C   s,   t  }t jdkrd}nd }| || d S )Ndarwinzutf-8)r   getfilesystemencodingr   rA  )r   r@  r>   r   r   r   test_getfilesystemencoding  s
    
z(SysModuleTest.test_getfilesystemencodingc       
      C   s   t j }||d< d|d< dd}tjd|g}|r>|d |d k	rP||d< n|dd  tj	|tj
tj|d	d
}| \}}	|S )NLC_ALL0ZPYTHONCOERCECLOCALE
)z
import syszdef dump(name):z    std = getattr(sys, name)z(    print("%s: %s" % (name, std.errors))zdump("stdin")zdump("stdout")zdump("stderr")z-cz-IrA   T)r   r   r&  Zuniversal_newlines)r+  r,  copyr   r   ru   r   r   rs   rt   rv   ZSTDOUTrw   )
r   localer  r   r&  r'   argsr0  r   r   r   r   r   c_locale_get_error_handler  s$    


z(SysModuleTest.c_locale_get_error_handlerc             C   s   | j |dd}| |d | j |dd}| |d | j |dd}| |d | j |d	d}| |d | j |d
d}| |d | j |dd}| |d d S )NT)r  zHstdin: surrogateescape
stdout: surrogateescape
stderr: backslashreplace
z:ignore)r   z6stdin: ignore
stdout: ignore
stderr: backslashreplace
z	iso8859-1z6stdin: strict
stdout: strict
stderr: backslashreplace
z
iso8859-1::r   )rK  r   )r   rI  r!   r   r   r   check_locale_surrogateescape  s$    z*SysModuleTest.check_locale_surrogateescapec             C   s   |  d d S )NC)rM  )r   r   r   r   test_c_locale_surrogateescape  s    z+SysModuleTest.test_c_locale_surrogateescapec             C   s   |  d d S )NZPOSIX)rM  )r   r   r   r   !test_posix_locale_surrogateescape  s    z/SysModuleTest.test_posix_locale_surrogateescapec             C   s   ddddd}|  ttjd |  ttjd |  ttjd |  ttjd	 tjj}| |d d
 |j|jf |jd> |jd> B |jd> B ||j	 d> B |j
d> B }| tjj| | tjjtjj  d S )Nr`   r         )r   r   r   r   r   r   r   	cache_tagr         r   rn   r   )r   r   r   implementationr   r   r   r   r   r   r   r   r   lower)r   Zlevelsr   r   r   r   r   test_implementation  s    *
z!SysModuleTest.test_implementationc             C   sB   ddl m} ddg}|| \}}}| d| | ttjd d S )Nr   )r   z-cz#import sys; sys._debugmallocstats()s   free PyDictObjectsT)test.support.script_helperr   ry   r   r   r   _debugmallocstats)r   r   rJ  retr!   r0   r   r   r   test_debugmallocstats  s
    z#SysModuleTest.test_debugmallocstatsgetallocatedblocksz0sys.getallocatedblocks unavailable on this buildc          
   C   s  ydd l }W n tk
r(   t }Y n>X y| }W n& tk
r\ } zd}W d d }~X Y n
X |dk}t }| t	|t
 |r| |d n| |d y| |t  W n tk
r   Y nX t  t }| || t  t }| |t|d |d  d S )Nr   T)ZpymallocZpymalloc_debugrb   )ro   ImportErrorr   with_pymallocZpymem_getallocatorsnamer    r   r]  assertIsr   r   r   r   r   r   AttributeErrorgcZcollectZassertLessEqualry   r   )r   ro   r_  Z
alloc_namer1   rV   br   r   r   r   test_getallocatedblocks  s0    z%SysModuleTest.test_getallocatedblocksc             C   s8   |  t d d}td|\}}}| | d d S )NFa  if 1:
            import sys

            class AtExit:
                is_finalizing = sys.is_finalizing
                print = print

                def __del__(self):
                    self.print(self.is_finalizing(), flush=True)

            # Keep a reference in the __main__ module namespace, so the
            # AtExit destructor will be called at Python exit
            ref = AtExit()
        z-cs   True)r`  r   is_finalizingr   r   rstrip)r   r'   r?   r   r   r   r   r   test_is_finalizing$  s    z SysModuleTest.test_is_finalizinggetandroidapilevelzneed sys.getandroidapilevel()c             C   s$   t  }| |t | |d d S )Nr   )r   rh  rH   r   r   )r   levelr   r   r   test_getandroidapilevel:  s    z%SysModuleTest.test_getandroidapilevelc                s   d  fdd}dddddg}|d	| |d
| |d|d d |dd    |d|d d |d
d    |d|d g |d|d g |dd> | |dd> |d g |d | d S )Nzif 1:
            import sys
            def f1():
                1 / 0
            def f2():
                f1()
            sys.tracebacklimit = %r
            f2()
        c                s<   t jtjd |  gt jd}| d }| | d S )Nz-c)r   r3   )rs   rt   r   ru   rv   rw   r   
splitlines)tracebacklimitr>   r0  r!   )r'   r   r   r   checkK  s    
z4SysModuleTest.test_sys_tracebacklimit.<locals>.checks"   Traceback (most recent call last):s&     File "<string>", line 8, in <module>s      File "<string>", line 6, in f2s      File "<string>", line 4, in f1s#   ZeroDivisionError: division by zeror`   rm   r   r3   r   i  r   )r   rm  r   r   )r'   r   r   test_sys_tracebacklimitA  s     	

z%SysModuleTest.test_sys_tracebacklimitc             C   s    |  ttjtttj d S )N)r   r   r   	meta_pathr   )r   r   r   r   test_no_duplicates_in_meta_pathb  s    z-SysModuleTest.test_no_duplicates_in_meta_path)N)FN)Cr   r   r   r   r   r"   r(   r,   r2   r6   rF   rJ   rU   rY   r]   rg   r   r   cpython_onlyrp   r|   r   r   unittestZ
skipUnlessr   r   r   Zrefcount_testr   r   Zreap_threadsr   r   r   r   r  r  r  r   r!  r"  r$  r1  r2  rC  rI  getpreferredencodingr4  ZskipIfr   r   r=  rA  rD  rK  rM  rO  rP  rX  r\  rd  Zrequires_type_collectingrg  rj  ro  rq  r   r   r   r   r      sl   	B		#
	AQ	+


&(!r   c                   sd   e Zd Zdd ZejjZdd Zdd Zdd Z	 fd	d
Z
dd Zdd Zdd Zdd Z  ZS )
SizeofTestc             C   s*   t d| _tjj| _dd l}|j| _	d S )NPr   )
structcalcsizerv  r   r   r   	longdigitro   ZSIZEOF_PYGC_HEADgc_headsize)r   ro   r   r   r   r   i  s    
zSizeofTest.setUpc             C   sH   t jj}| j}| td|d| j  | tg |d|  d S )NTr   Pn)r   r   calcvobjsizerz  r   r   	getsizeofry  )r   vsizeZgc_header_sizer   r   r   test_gc_head_sizeq  s    zSizeofTest.test_gc_head_sizec          	   C   sD  G dd d}|  ttj|  G dd d}|  ttj|  dg}| t| || G dd d}|  ttj|  | t| || G dd	 d	t}| t|tjtj| j	  |  t
 t|tjd
  W d Q R X |  t t|d W d Q R X |  tt
f t|tj d
  W d Q R X d S )Nc               @   s   e Zd Zdd ZdS )z)SizeofTest.test_errors.<locals>.BadSizeofc             S   s   t d S )N)r)   )r   r   r   r   
__sizeof__|  s    z4SizeofTest.test_errors.<locals>.BadSizeof.__sizeof__N)r   r   r   r  r   r   r   r   	BadSizeof{  s   r  c               @   s   e Zd Zdd ZdS )z-SizeofTest.test_errors.<locals>.InvalidSizeofc             S   s   d S )Nr   )r   r   r   r   r    s    z8SizeofTest.test_errors.<locals>.InvalidSizeof.__sizeof__N)r   r   r   r  r   r   r   r   InvalidSizeof  s   r  sentinelc               @   s   e Zd Zdd ZdS )z+SizeofTest.test_errors.<locals>.FloatSizeofc             S   s   dS )Ng      @r   )r   r   r   r   r    s    z6SizeofTest.test_errors.<locals>.FloatSizeof.__sizeof__N)r   r   r   r  r   r   r   r   FloatSizeof  s   r  c               @   s   e Zd Zdd ZdS )z.SizeofTest.test_errors.<locals>.OverflowSizeofc             S   s   t | S )N)r   )r   r   r   r   r    s    z9SizeofTest.test_errors.<locals>.OverflowSizeof.__sizeof__N)r   r   r   r  r   r   r   r   OverflowSizeof  s   r  r3   rn  )r   r)   r   r}  r   r`  r   r   r   rz  OverflowError)r   r  r  r  r  r  r   r   r   test_errorsz  s$    zSizeofTest.test_errorsc             C   sF   t jj}| td|d| j  | tdd|d| j  d S )NTr   rn  )r   r   r|  r   r   r}  ry  )r   sizer   r   r   test_default  s    zSizeofTest.test_defaultc       '   	      sh	  t j}tjjtjj}j  d|dj   td ddd g}x*|D ]"}t	|} ||d|
   qPW  tt	 d  d|d	d
   d|d	d  dd } | jd d fdd}|| jd ||jd dd }||jd|d	   tdd
d  tjd dd l}	 |	jjd dd l}
 |
jjd  tjd  i jd  i d|d d d|d   d
dd d!dd"d#dd$} |d|d d% d&|d    i  d  i  d  i  d  ti d'  ti  d'  ti  d'  ti  d' G d(d) d)t} |jd  t d*  t dddddd+  t!dddddd+  t"ddd
dd+  t#d dd l$}dd l%}|&|j'j(} |d,  t)g d-  t*dd  t+dd.  t,j-|dj.tt,j-   dd l/}d/}|0 }t|j1j2}t|j1j3}|j1j4|j1j5 | | d
 } ||d0|d1  d |d   d2d3 } |d4 G  fd5d6d6}d7d8 } | d9  td:d; dd l6} |7ddd g d
dd gd<d=d>gg}x*|D ]"} ||d?t|j.   qW  tg d;  t*g d  d|d  d
|dj   d@|dj  dt,j8j9 } t||ddj    t|d d
 |ddj    t|d |dd j    t:dA  d d  t;d  t d G  fdBd)d)t} tt<d
dC  t*dd  t<d
d  t<dDd d}g t<d&t<dEg}dF|d  dG }x|D ]}t|}|dkrTd
}|d }|}x||krx|d
> }qbW |dkr t=||  t>|| n4 t=||||d    t>||||d   q:W  tt= dH  t?ddI  t@tdI  dJ|d  dK|dd j.   dL}tAt,dMrR|dN7 }||} t| ||dO }G dPdQ dQt} |||dR d d|d    | jddj.   | } d
 | _B | _C | _D | _E | _F | _G | _H| _I |||dR d% d&|d    | jdd&j.   dSdTdUdVdWdXg}dY}!|!dZ }"|"d }#x|D ]}tJtK|}$|$d[k r|!t| d
 }%n\|$d\k r|"t| d
 }%n<|$d]k rЈ|"dt|d
   }%n|"d!t|d
   }% ||% q\W tLd^} ||"d!  tM|d_d`  ||"d! d!  dd lN}& |&Otda  |&Ptda d S )bNTr   Z4Pr7      ui Zn2PiZnPrT   r3   s
   xxxxxxxxxxr   c                 s   d  fdd} | S )Nr   c                  s    S )Nr   r   )r   r   r   inner  s    z<SizeofTest.test_objecttypes.<locals>.get_cell.<locals>.innerr   )r  r   )r   r   get_cell  s    z-SizeofTest.test_objecttypes.<locals>.get_cellr   rv  c                s     t| | d S )N)r   r   r}  )rV   Zexpected_size)r   r   r   check_code_size  s    z4SizeofTest.test_objecttypes.<locals>.check_code_sizeZ6i13Pc                s    fdd}|S )Nc                  s    S )Nr   r   )r   r   r   r    s    z=SizeofTest.test_objecttypes.<locals>.get_cell2.<locals>.innerr   )r   r  r   )r   r   	get_cell2  s    z.SizeofTest.test_objecttypes.<locals>.get_cell2Z2dZ3PPZ3P2PZ2PZnQ2PZ2nP2nr   r~   Zn2Pr   rm   rn         )r3   r   rm   rn   r~   r  r  r   rU  r`   ZP2nPnc               @   s   e Zd ZdS )z&SizeofTest.test_objecttypes.<locals>.CN)r   r   r   r   r   r   r   rN    s    rN  Z5Pbz	5Pb 2P2nPZ32B2iBZn3Pr      Z	5P2c4P3icZ3ic               S   s   d S )Nr   r   r   r   r   func
  r7   z)SizeofTest.test_objecttypes.<locals>.funcZ12Pc                   s@   e Zd Zedd Zedd Z ed  ed dS )z&SizeofTest.test_objecttypes.<locals>.cc               S   s   d S )Nr   r   r   r   r   foo  s    z*SizeofTest.test_objecttypes.<locals>.c.fooc             S   s   d S )Nr   )clsr   r   r   bar  s    z*SizeofTest.test_objecttypes.<locals>.c.barZPPN)r   r   r   staticmethodr  classmethodr  r   )rm  r  r   r   r     s   r   c               s   s
   dV  d S )Nr3   r   r   r   r   r   get_gen  r7   z,SizeofTest.test_objecttypes.<locals>.get_genZPb2PPP4Pr  ZlPr4   23r{  rn  ZPnPPPc                   s@   e Zd Zdd Zdd Zdd ZeeeedZ ed d	S )
z&SizeofTest.test_objecttypes.<locals>.Cc             S   s   | j S )N)_C__x)r   r   r   r   getx=  r7   z+SizeofTest.test_objecttypes.<locals>.C.getxc             S   s
   || _ d S )N)r  )r   valuer   r   r   setx>  r7   z+SizeofTest.test_objecttypes.<locals>.C.setxc             S   s   | ` d S )N)r  )r   r   r   r   delx?  r7   z+SizeofTest.test_objecttypes.<locals>.C.delxr   Z4PiN)r   r   r   r  r  r  propertyr   r   )rm  r  r   r   rN  <  s
   Z4li rb   Z3nPZ2nPZP3n3Pr   )r3   r   rm   ZP2n15Pl4Pn9Pn11PIPZ	getcountsZ3n2PZ3P36P3P10P2P4Pc               @   s   e Zd ZdS )z2SizeofTest.test_objecttypes.<locals>.newstyleclassN)r   r   r   r   r   r   r   newstyleclassw  s    r  Z2nP2n0PZd1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111ud   ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿuP   ĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀu,  ￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿ux   𐀀𐀀𐀀𐀀𐀀𐀀𐀀𐀀𐀀𐀀𐀀𐀀𐀀𐀀𐀀𐀀𐀀𐀀𐀀𐀀𐀀𐀀𐀀𐀀𐀀𐀀𐀀𐀀𐀀𐀀u  􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿􏿿ZnnbPZnPnr      i   i @  z<stdin>r&   Z2Pn2P)Qrw  rx  r   r   calcobjsizer|  check_sizeofry  r   	bytearray	__alloc__iter__closure__r   complexrI   rW  datetimeZ	timedeltaZdayscollectionsdefaultdictdefault_factoryr   __add____iter__keysvaluesitemsobject__dict__BaseExceptionUnicodeEncodeErrorUnicodeDecodeErrorUnicodeTranslateErrorEllipsisr>  Zencodings.iso8859_3charmap_build	iso8859_3decoding_tabler   reversedfloatr   r   rv  r	  Zcurrentframer   co_cellvarsco_freevarsco_stacksize
co_nlocalsrefinditerr   r   rs  NotImplementedr   r   	frozensetslicesuperr   rV   rc  r   r   er_   ghordmaxchrr%   weakrefrefproxy)'r   rx  r~  ZsamplesZsampler   r  r  r  r  r  ZlongdictrN  r>  	encodingsr	  ZCO_MAXBLOCKSZncellsZnfreesextrasr  r   r  r  ZPyLong_BASEZPySet_MINSIZEr  ZminusedZtmpZnewsizeZfmtr  oZasciifieldsZcompactfieldsZunicodefieldsZmaxcharLr  )	__class__)rm  r   r  r   test_objecttypes  s$   
&& "
"$ 	

 
 
"0"



zSizeofTest.test_objecttypesc             C   sH   t |t| }t|r2t|s2|| j7 }| t || d S )N)r   r}  rw  rx  rb  Z
is_trackedrz  r   )r   r*   baseZextrar>   r   r   r   check_slots  s    
zSizeofTest.check_slotsc       	      C   s   | j }G dd dt}|| t d G dd dt}||g ddg id G dd	 d	t}|| g d G d
d dt}|| t d G dd dt}|| t d ddlm} G dd d|}||g d|g dd d S )Nc               @   s   e Zd ZdZdS )z!SizeofTest.test_slots.<locals>.BA)rV   rc  r   N)r   r   r   	__slots__r   r   r   r   BA  s   r  r  c               @   s   e Zd ZdZdS )z SizeofTest.test_slots.<locals>.D)rV   rc  r   N)r   r   r   r  r   r   r   r   D  s   r  )r   r   c               @   s   e Zd ZdZdS )z SizeofTest.test_slots.<locals>.L)rV   rc  r   N)r   r   r   r  r   r   r   r   r    s   r  c               @   s   e Zd ZdZdS )z SizeofTest.test_slots.<locals>.S)rV   rc  r   N)r   r   r   r  r   r   r   r   r     s   r   c               @   s   e Zd ZdZdS )z!SizeofTest.test_slots.<locals>.FS)rV   rc  r   N)r   r   r   r  r   r   r   r   FS  s   r  r   )OrderedDictc               @   s   e Zd ZdZdS )z!SizeofTest.test_slots.<locals>.OD)rV   rc  r   N)r   r   r   r  r   r   r   r   OD  s   r  )r  r  r*  r   r   r  r  r  )	r   rm  r  r  r  r   r  r  r  r   r   r   
test_slots  s    zSizeofTest.test_slotsc             C   s   t jj}t jj}| j}dd l}|| |d ytW n6 tk
rn   t	 d }|d k	rj|||d Y nX |tj
|d| jttj
   d S )Nr   rv  r   Z2P2ir   )r   r   r  r|  r  _astZASTr   r   r.   r  rv  r   )r   r  r~  rm  r  tbr   r   r   test_pythontypes  s    zSizeofTest.test_pythontypesc             C   s   t  }| |j | |j dd }t j|d t  }| |j| | |d | | |jd  | |d d  dd }t j|d t  }| |j| | |d | | |j| | |d | t j|  t  }| |j | |j d S )Nc              W   s   d S )Nr   )rV   r   r   r   <lambda>  r7   z0SizeofTest.test_asyncgen_hooks.<locals>.<lambda>)	firstiterr   r3   c              W   s   d S )Nr   )rV   r   r   r   r    r7   )	finalizer)r   get_asyncgen_hooksrC   r  r  set_asyncgen_hooksr`  )r   oldr  Zhooksr  Zcurr   r   r   test_asyncgen_hooks  s*    
zSizeofTest.test_asyncgen_hooks)r   r   r   r   r   r   r  r  r  r  r  r  r  r  r  __classcell__r   r   )r  r   ru  f  s   	  ru  c               C   s   t jtt d S )N)r   r   Zrun_unittestr   ru  r   r   r   r   	test_main  s    r  __main__)rs  Ztest.supportr   rY  r   r   r   r   r+  rw  rs   rq   rN   r   r>  rb  r   rI  r   r  ZTestCaser   r   rr  ru  r  r   r   r   r   r   <module>   s8         X
   