B
    18™\ac  ã               @   s‚  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 dlmZmZ yd dlmZ dZW n ek
r¤   dZY nX d dlmZ d dlmZ dd	lmZ dd
lmZ G dd„ dƒZG dd„ deejeddZG dd„ deejeddZG dd„ dejƒZG dd„ dƒZ G dd„ de ejeddZ!G dd„ de ejeddZ"e#dkr~e $¡  dS )é    N)ÚmockÚ
skipUnless)ÚProcessPoolExecutorTF)Úsupport)Úscript_helperé   )Úwithout_source_date_epoch)ÚSourceDateEpochTestMetac               @   sö   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Ze e	e
d	ƒd
¡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 d¡d d!„ ƒZd"d#„ Ze d¡d$d%„ ƒZe d¡e d&¡d'd(„ ƒƒZejdd)d*e d&¡d+d,„ ƒƒZd)S )-ÚCompileallTestsBasec          	   C   sÄ   t  ¡ | _tj | jd¡| _tj 	| j¡| _
t| jdƒ}| d¡ W d Q R X tj | jd¡| _tj 	| j¡| _t | j| j¡ tj | jd¡| _t | j¡ tj | jd¡| _t | j| j¡ d S )Nz_test.pyÚwzx = 123
z	_test2.pyZ_subdirz	_test3.py)ÚtempfileÚmkdtempÚ	directoryÚosÚpathÚjoinÚsource_pathÚ	importlibÚutilÚcache_from_sourceÚbc_pathÚopenÚwriteÚsource_path2Úbc_path2ÚshutilÚcopyfileZsubdirectoryÚmkdirÚsource_path3)ÚselfÚfile© r!   úX/oak/stanford/groups/akundaje/marinovg/programs/Python-3.7.3/Lib/test/test_compileall.pyÚsetUp   s    
zCompileallTestsBase.setUpc             C   s   t  | j¡ d S )N)r   Úrmtreer   )r   r!   r!   r"   ÚtearDown-   s    zCompileallTestsBase.tearDownc          	   C   s8   t j | jd¡| _t| jdƒ}| d¡ W d Q R X d S )Nz_test_bad.pyr   zx (
)r   r   r   r   Úbad_source_pathr   r   )r   r    r!   r!   r"   Úadd_bad_source_file0   s    z'CompileallTestsBase.add_bad_source_filec          	   C   sP   t | jdƒ}| d¡}W d Q R X tt | j¡jƒ}t 	dt
jjd|¡}||fS )NÚrbé   z<4sllr   )r   r   ÚreadÚintr   Ústatr   Úst_mtimeÚstructÚpackr   r   ÚMAGIC_NUMBER)r   r    ÚdataÚmtimeÚcomparer!   r!   r"   Útimestamp_metadata5   s
    z&CompileallTestsBase.timestamp_metadatar,   ztest needs os.stat()c          	   C   sº   t j d¡rt d¡‚t | j¡ | j|  	¡ Ž  t
| jdƒ}| ¡ t|ƒd… }W dQ R X t
| jdƒ}| |¡ | |¡ W dQ R X | j|  	¡ Ž  tj| jddd | j|  	¡ Ž  dS )	zOCheck that compileall recreates bytecode when the new metadata is
        used.ZSOURCE_DATE_EPOCHzSOURCE_DATE_EPOCH is setr(   NÚwbFT)ÚforceÚquiet)r   ÚenvironÚgetÚunittestÚSkipTestÚ
py_compileÚcompiler   ÚassertEqualr4   r   r   r*   Úlenr   ÚassertNotEqualÚ
compileallÚcompile_dirr   Ú
assertTrue)r   Zmetadatar    Zbcr!   r!   r"   Úrecreation_check<   s    

z$CompileallTestsBase.recreation_checkc             C   s   |   t dtjjdd¡¡ d S )Nz<4sllr   r   )rD   r.   r/   r   r   r0   )r   r!   r!   r"   Ú
test_mtimeM   s    zCompileallTestsBase.test_mtimec             C   s   |   d¡ d S )Ns       )rD   )r   r!   r!   r"   Útest_magic_numberR   s    z%CompileallTestsBase.test_magic_numberc             C   s  x0| j | jfD ] }yt |¡ W q   Y qX qW |  tj| jddd¡ |  tj 	| j ¡ojtj 	| j¡ ¡ t | j ¡ |  tj
| jddd¡ |  tj 	| j ¡o°tj 	| j¡¡ t | j ¡ t | j¡ |  ¡  |  tj| jddd¡ |  tj
| jddd¡ d S )NFT)r6   r7   é   )r   r   r   ÚunlinkrC   rA   Úcompile_filer   r   ÚisfilerB   r   r'   ÚassertFalser&   )r   Úfnr!   r!   r"   Útest_compile_filesV   s*    

z&CompileallTestsBase.test_compile_filesc          	   C   sh   |   tj | j¡¡ t ¡ }|  t 	t
 | j¡¡¡ W d Q R X |  | ¡ d¡ |  tj | j¡¡ d S )Nz&Compiling ([^WindowsPath|PosixPath].*))rK   r   r   rJ   r   r   Úcaptured_stdoutrC   rA   rI   ÚpathlibÚPathr   ÚassertRegexÚgetvalue)r   Ústdoutr!   r!   r"   Útest_compile_file_pathlikeo   s
    
"z.CompileallTestsBase.test_compile_file_pathlikec             C   sP   |   tj | j¡¡ |  tjt 	| j
¡t 	d¡dd¡ |  tj | j¡¡ d S )NZ	ddir_pathrG   )Zddirr7   )rK   r   r   rJ   r   rC   rA   rI   rO   rP   r   )r   r!   r!   r"   Útest_compile_file_pathlike_ddirw   s
    
z3CompileallTestsBase.test_compile_file_pathlike_ddirc          	   C   st   t jjj| jgd |  tjdd¡ W d Q R X t jjj| jgd$ |  ¡  |  	tjdddd¡ W d Q R X d S )N)r   rG   )r7   FT)Zskip_curdirr6   r7   )
ÚtestZtest_importlibr   Zimport_stater   rC   rA   Zcompile_pathr'   rK   )r   r!   r!   r"   Útest_compile_path~   s    
z%CompileallTestsBase.test_compile_pathc          	   C   sh   t j | jd¡}t j |d¡}t  |¡ t|dƒ W d Q R X t |¡ |  t j 	t j |d¡¡¡ d S )Nr1   r    r   Ú__pycache__)
r   r   r   r   r   r   rA   rI   rK   Úexists)r   Zdata_dirZ	data_filer!   r!   r"   Útest_no_pycache_in_non_package‡   s    


z2CompileallTestsBase.test_no_pycache_in_non_packagec             C   sŽ   dnd\}}t j| jd|d tjj| j|d}|  tj	 
|¡¡ tjj| j|d}|  tj	 
|¡¡ tjj| j|d}|  tj	 
|¡¡ d S )NT)r   r   )r   Ú )r7   Úoptimize)Úoptimization)rA   rB   r   r   r   r   r   rC   r   r   rJ   r   r   )r   r\   ÚoptÚcachedZcached2Zcached3r!   r!   r"   Útest_optimize“   s    


z!CompileallTestsBase.test_optimizec          	   C   sn   |   tj | j¡¡ t ¡ }t t	 
| j¡¡ W d Q R X | ¡  ¡ d }|  |d¡ |  tj | j¡¡ d S )Nr   z$Listing ([^WindowsPath|PosixPath].*))rK   r   r   rJ   r   r   rN   rA   rB   rO   rP   r   rR   Ú
splitlinesrQ   rC   )r   rS   Úliner!   r!   r"   Útest_compile_dir_pathlike¢   s    
z-CompileallTestsBase.test_compile_dir_pathlikez&concurrent.futures.ProcessPoolExecutorc             C   s"   t j| jddd |  |j¡ d S )NTé   )r7   Úworkers)rA   rB   r   rC   Úcalled)r   Ú	pool_mockr!   r!   r"   Útest_compile_pool_calledª   s    z,CompileallTestsBase.test_compile_pool_calledc          	   C   s,   |   td¡ tj| jdd W d Q R X d S )Nz%workers must be greater or equal to 0éÿÿÿÿ)re   )ÚassertRaisesRegexÚ
ValueErrorrA   rB   r   )r   r!   r!   r"   Ú!test_compile_workers_non_positive¯   s    z5CompileallTestsBase.test_compile_workers_non_positivec             C   s,   t j| jddd |  |jd d d ¡ d S )NTr   )r7   re   r   Zmax_workers)rA   rB   r   r>   Ú	call_args)r   rg   r!   r!   r"   Útest_compile_workers_cpu_count´   s    z2CompileallTestsBase.test_compile_workers_cpu_countzcompileall.compile_filec             C   s,   t j| jdd |  |j¡ |  |j¡ d S )NT)r7   )rA   rB   r   rK   rf   rC   )r   Úcompile_file_mockrg   r!   r!   r"   Útest_compile_one_worker¹   s    z+CompileallTestsBase.test_compile_one_workerN)Únewc             C   s"   t j| jddd |  |j¡ d S )NTrd   )r7   re   )rA   rB   r   rC   rf   )r   ro   r!   r!   r"   Ú$test_compile_missing_multiprocessingÀ   s    z8CompileallTestsBase.test_compile_missing_multiprocessing)Ú__name__Ú
__module__Ú__qualname__r#   r%   r'   r4   r:   r   Úhasattrr   rD   rE   rF   rM   rT   rU   rW   rZ   r`   rc   r   Úpatchrh   rl   rn   rp   rr   r!   r!   r!   r"   r
      s*   	r
   c               @   s   e Zd ZdS )ÚCompileallTestsWithSourceEpochN)rs   rt   ru   r!   r!   r!   r"   rx   Ç   s   rx   )Ú	metaclassZsource_date_epochc               @   s   e Zd ZdS )Ú!CompileallTestsWithoutSourceEpochN)rs   rt   ru   r!   r!   r!   r"   rz   Î   s   rz   c               @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚEncodingTestzTIssue 6716: compileall should escape source code when printing errors
    to stdout.c          	   C   sP   t  ¡ | _tj | jd¡| _t| jddd}| d¡ | d¡ W d Q R X d S )Nz_test.pyr   zutf-8)Úencodingz# -*- coding: utf-8 -*-
u   print u"â‚¬"
)	r   r   r   r   r   r   r   r   r   )r   r    r!   r!   r"   r#   Ù   s
    

zEncodingTest.setUpc             C   s   t  | j¡ d S )N)r   r$   r   )r   r!   r!   r"   r%   à   s    zEncodingTest.tearDownc             C   s8   z*t j}tjt ¡ ddt _t | j¡ W d |t _X d S )NÚascii)r|   )ÚsysrS   ÚioÚTextIOWrapperÚBytesIOrA   rB   r   )r   Úorig_stdoutr!   r!   r"   Ú
test_errorã   s
    zEncodingTest.test_errorN)rs   rt   ru   Ú__doc__r#   r%   rƒ   r!   r!   r!   r"   r{   Õ   s   r{   c               @   st  e Zd ZdZe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dd„ ƒZdd„ ZxJddg fdddgfdddgfgD ]&\ZZZeefd d!„Zeeƒ d"e < qŽW d#d$„ Zd%d&„ Zed'd(„ ƒZd)d*„ Z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#d?d@„ Z$dAdB„ Z%dCdD„ Z&dEdF„ Z'e(e)dGƒdHdI„ ƒZ*e+ ,dJ¡dKdL„ ƒZ-dMS )NÚCommandLineTestsBasezTest compileall's CLI.c             C   s¸   x¬t tjjtjƒD ]”}d}t |¡d }|d }zXy8| ¡ sH| ¡  d}| 	d¡}| 
d¡ W d Q R X W n tk
r„   d}P Y nX W d t t|ƒ¡ |r¤| ¡  X qW d}|| _d S )NFrX   ztest.tryTr   z# for test_compileall)Úfilterr   r   Úisdirr~   rO   rP   Úis_dirr   r   r   ÚOSErrorr   rH   ÚstrÚrmdirÚ_sys_path_writable)Úclsr   Zdirectory_createdr   r    Zsys_path_writabler!   r!   r"   Ú
setUpClassï   s$    zCommandLineTestsBase.setUpClassc             C   s   | j st d¡‚d S )Nz(not all entries on sys.path are writable)rŒ   r:   r;   )r   r!   r!   r"   Ú_skip_if_sys_path_not_writable  s    z3CommandLineTestsBase._skip_if_sys_path_not_writablec             C   s   t  ¡ d|•S )Nú-Sú-mrA   )r   r‘   rA   )r   Ú!optim_args_from_interpreter_flags)r   Úargsr!   r!   r"   Ú_get_run_args
  s    z"CommandLineTestsBase._get_run_argsc             O   s(   t j|  |¡|Ž\}}}|  d|¡ |S )Nó    )r   Úassert_python_okr”   r>   )r   r“   Úenv_varsÚrcÚoutÚerrr!   r!   r"   ÚassertRunOK  s    z CommandLineTestsBase.assertRunOKc             O   s"   t j|  |¡|Ž\}}}|||fS )N)r   Úassert_python_failurer”   )r   r“   r—   r˜   r™   rš   r!   r!   r"   ÚassertRunNotOK  s    z#CommandLineTestsBase.assertRunNotOKc             C   s"   t j |¡}|  tj |¡¡ d S )N)r   r   r   rC   r   r   rY   )r   rL   r   r!   r!   r"   ÚassertCompiled  s    z#CommandLineTestsBase.assertCompiledc             C   s"   t j |¡}|  tj |¡¡ d S )N)r   r   r   rK   r   r   rY   )r   rL   r   r!   r!   r"   ÚassertNotCompiled  s    z&CommandLineTestsBase.assertNotCompiledc             C   sr   t  ¡ | _|  tj| j¡ tj | jd¡| _	t 
| j	¡ tj | j	d¡| _t | j	dd¡| _t | j	dd¡| _d S )NZfoorX   Ú__init__r[   Zbar)r   r   r   Ú
addCleanupr   r$   r   r   r   Úpkgdirr   Úpkgdir_cachedirr   Úmake_scriptÚinitfnÚbarfn)r   r!   r!   r"   r#   "  s    
zCommandLineTestsBase.setUpc             C   sL   |   ¡  t | jdd¡}| j| jd |  |¡ |  | j¡ |  | j¡ d S )NÚbazr[   )Ú
PYTHONPATH)	r   r   r¤   r   r›   rž   rŸ   r¥   r¦   )r   Úbazfnr!   r!   r"   Útest_no_args_compiles_path,  s    
z/CommandLineTestsBase.test_no_args_compiles_pathc             C   sª   |   ¡  t | jdd¡}| j| jd tj |¡}t 	|t
 
¡ d fd ¡ t |¡j}| j| jd t |¡j}|  ||¡ | jd| jd t |¡j}|  ||¡ d S )Nr§   r[   )r¨   é<   rG   z-f)r   r   r¤   r   r›   r   r   r   r   ÚutimeÚtimer,   r-   r>   r@   )r   r©   Úpycpathr2   Úmtime2r!   r!   r"   Ú test_no_args_respects_force_flag5  s    z5CommandLineTestsBase.test_no_args_respects_force_flagc             C   sR   |   ¡  t | jdd¡ | j| jd}|  d|¡ | jd| jd}|  d|¡ d S )Nr§   r[   )r¨   s   Listing z-q)r   r   r¤   r   r›   ÚassertInÚassertNotIn)r   Únoisyr7   r!   r!   r"   Ú test_no_args_respects_quiet_flagG  s    z5CommandLineTestsBase.test_no_args_respects_quiet_flagZnormalÚpycr\   z	opt-1.pycz-OZdoubleoptimizez	opt-2.pycz-OOc                s~   t j|ddd| jg Ž  |  tj | j¡¡ t‡ fdd„dD ƒƒ}|  	tt 
| j¡ƒ|¡ |  ‡ fdd„t 
| j¡D ƒ¡ d S )	Nz-mrA   z-qc             3   s   | ]}|  tjjˆ ¡V  qd S )N)Úformatr~   ÚimplementationÚ	cache_tag)Ú.0Úbase)Úextr!   r"   ú	<genexpr>[  s   z)CommandLineTestsBase.f.<locals>.<genexpr>)z__init__.{}.{}z	bar.{}.{}c                s   g | ]}|  ˆ ¡r|‘qS r!   )Úendswith)r¹   rL   )r»   r!   r"   ú
<listcomp>_  s    z*CommandLineTestsBase.f.<locals>.<listcomp>)r   r–   r¢   rC   r   r   rY   r£   Úsortedr>   ÚlistdirrK   )r   r»   ÚswitchÚexpectedr!   )r»   r"   ÚfV  s    
zCommandLineTestsBase.fZtest_pep3147_paths_c             C   sP   |   dd| j¡ |  tj | j¡¡ tddddgƒ}|  tt 	| j¡ƒ|¡ d S )Nz-bz-qz__init__.pyz__init__.pyczbar.pyzbar.pyc)
r›   r¢   rK   r   r   rY   r£   r¿   r>   rÀ   )r   rÂ   r!   r!   r"   Útest_legacy_pathsc  s
    z&CommandLineTestsBase.test_legacy_pathsc             C   s|   |   d| j¡ |  tj | j¡¡ tj | jd¡}|  tj |¡¡ |   d| j¡ |  tj | j¡¡ |  tj |¡¡ d S )Nz-qrX   )	r›   r¢   rC   r   r   rY   r£   r   rK   )r   Zcachecachedirr!   r!   r"   Útest_multiple_runsm  s    z'CommandLineTestsBase.test_multiple_runsc             C   s”   |   d| j¡ tj | j¡}t |t ¡ d fd ¡ t 	|¡j
}|   d| j¡ t 	|¡j
}|  ||¡ |   dd| j¡ t 	|¡j
}|  ||¡ d S )Nz-qr«   rG   z-f)r›   r¢   r   r   r   r¦   r   r¬   r­   r,   r-   r>   r@   )r   r®   r2   r¯   r!   r!   r"   Ú
test_forcez  s    zCommandLineTestsBase.test_forcec             C   s’   t j | jd¡}t  |¡ t |dd¡}t |dd¡}|  dd| j¡ |  |¡ |  	t j 
t j |d¡¡¡ |  d| j¡ |  |¡ |  |¡ d S )NÚspamr    r[   Úhamz-qz-lrX   )r   r   r   r¢   r   r   r¤   r›   rŸ   rK   rY   rž   )r   Ú
subpackageÚ	subinitfnÚhamfnr!   r!   r"   Útest_recursion_controlŠ  s    


z+CommandLineTestsBase.test_recursion_controlc       	      C   sZ  t j | jd¡}t j |d¡}t j |d¡}x|||fD ]}t |¡ q8W t j |d¡}t |dd¡}t |dd¡}t |dd¡}|  dd| j¡ |  |¡ |  	t j 
t j |d	¡¡¡ |  dd
| j¡ |  |¡ |  |¡ |  |¡ |  dd| j¡ |  |¡ |  |¡ |  |¡ |  |¡ |  dd| j¡ |  |¡ |  |¡ |  |¡ |  |¡ d S )NrÇ   rÈ   Zeggsz__init__.pyr[   Zeggz-qz-r 0rX   z-r 1z-r 2z-r 5)r   r   r   r¢   r   Zmake_pkgr¤   r›   rŸ   rK   rY   rž   )	r   rÉ   Zsubpackage2Zsubpackage3ÚpkgrÊ   rË   ZspamfnZeggfnr!   r!   r"   Útest_recursion_limit–  s6    










z)CommandLineTestsBase.test_recursion_limitc             C   s6   |   | j¡}|   d| j¡}|  d|¡ |  d|¡ d S )Nz-qr•   )r›   r¢   r@   r>   )r   r³   r7   r!   r!   r"   Ú
test_quiet¸  s    zCommandLineTestsBase.test_quietc             C   sT   t  | jdd¡ |  d| j¡\}}}|  d| j¡\}}}|  d|¡ |  d|¡ d S )NÚcrunchyfrogz
bad(syntaxz-qz-qqr•   )r   r¤   r¢   r   r@   r>   )r   Ú_r7   Zsilentr!   r!   r"   Útest_silent¾  s
    z CommandLineTestsBase.test_silentc             C   s.   |   ddd| j¡ |  | j¡ |  | j¡ d S )Nz-qz-xz
ba[^\\/]*$)r›   r¢   rŸ   r¦   rž   r¥   )r   r!   r!   r"   Útest_regexpÅ  s    z CommandLineTestsBase.test_regexpc             C   sv   t j | jd¡}t  |¡ t |dd¡}t |dd¡}|  d| j|¡ |  	| j
¡ |  	| j¡ |  	|¡ |  	|¡ d S )NZfoo2r    r[   Úbar2z-q)r   r   r   r   r   r   r¤   r›   r¢   rž   r¥   r¦   )r   Zpkgdir2Zinit2fnÚbar2fnr!   r!   r"   Útest_multiple_dirsÊ  s    

z'CommandLineTestsBase.test_multiple_dirsc             C   s8   t  | jdd¡ |  ddd| j¡\}}}|  |d¡ d S )NrÐ   z
bad(syntaxz-qz-dÚdinsdales   File "dinsdale)r   r¤   r¢   r   rQ   )r   r˜   r™   rš   r!   r!   r"   Útest_d_compile_errorÕ  s    z)CommandLineTestsBase.test_d_compile_errorc             C   s„   t  | jdd¡}|  ddd| j¡ t  | jdd¡}tj |¡}t |tj	 
| jd¡¡ t |¡ t j|d	d
\}}}|  |d¡ d S )Nr§   zraise Exceptionz-qz-dr×   Úbingz
import bazzbaz.pycF)Z
__isolateds   File "dinsdale)r   r¤   r¢   r›   r   r   r   r   Úrenamer   r   Úremoverœ   rQ   )r   r©   rL   rµ   r˜   r™   rš   r!   r!   r"   Útest_d_runtime_errorÚ  s    
z)CommandLineTestsBase.test_d_runtime_errorc             C   sZ   |   dtj | jd¡| j¡\}}}|  |d¡ |  |d¡ |  tj 	t
j | j¡¡¡ d S )Nz-iÚ
nosuchfiles   rror.*nosuchfiles	   Traceback)r   r   r   r   r   r¢   rQ   ÚassertNotRegexrK   rY   r   r   r   r£   )r   r˜   r™   rš   r!   r!   r"   Útest_include_bad_fileä  s    z*CommandLineTestsBase.test_include_bad_filec          	   C   sà   t  | jdd¡}t  | jdd¡}t  | jdd¡}t  | jdd¡}ttj | jd¡dƒ>}| tj | jd¡tj	 ¡ | tj | jd	¡tj	 ¡ W d Q R X |  
d
tj | jd¡|¡ |  |¡ |  |¡ |  |¡ |  |¡ d S )NÚf1r[   Úf2Úf3Úf4Úl1r   zf1.pyzf2.pyz-i)r   r¤   r¢   r   r   r   r   r   r   Úlinesepr›   rž   rŸ   )r   rà   rá   râ   rã   rä   r!   r!   r"   Útest_include_file_with_argì  s    &


z/CommandLineTestsBase.test_include_file_with_argc          	   C   sÂ   t  | jdd¡}t  | jdd¡}t  | jdd¡}t  | jdd¡}ttj | jd¡dƒ"}| tj | jd¡tj	 ¡ W d Q R X |  
d	tj | jd¡¡ |  |¡ |  |¡ |  |¡ |  |¡ d S )
Nrà   r[   rá   râ   rã   rä   r   zf2.pyz-i)r   r¤   r¢   r   r   r   r   r   r   rå   r›   rŸ   rž   )r   rà   rá   râ   rã   rä   r!   r!   r"   Útest_include_file_no_argú  s    &


z-CommandLineTestsBase.test_include_file_no_argc             C   s¦   t  | jdd¡}t  | jdd¡}t  | jdd¡}t  | jdd¡}t j|  d¡ddg Ž }|j |tj  	d	¡¡ t  
|¡ |  |¡ |  |¡ |  |¡ |  |¡ d S )
Nrà   r[   rá   râ   rã   r!   z-iú-r}   )r   r¤   r¢   Zspawn_pythonr”   Ústdinr   r   rå   ÚencodeZkill_pythonrŸ   rž   )r   rà   rá   râ   rã   Úpr!   r!   r"   Útest_include_on_stdin  s    



z*CommandLineTestsBase.test_include_on_stdinc             C   s\   t  | jdd¡}|  d| j|| j¡\}}}|  |d¡ |  |¡ |  | j¡ |  | j¡ d S )NrÙ   zsyntax(errorrÝ   s   rror)	r   r¤   r¢   r   r¥   r¦   rQ   rŸ   rž   )r   Zbingfnr˜   r™   rš   r!   r!   r"   Ú!test_compiles_as_much_as_possible  s    

z6CommandLineTestsBase.test_compiles_as_much_as_possiblec             C   s   |   d¡}|  |d¡ d S )NZbadfilenames   Can't list 'badfilename')r›   rQ   )r   r™   r!   r!   r"   Ú!test_invalid_arg_produces_message  s    
z6CommandLineTestsBase.test_invalid_arg_produces_messagec          	   C   s¼   t  | jdd¡ tj tj | jd¡¡}|  	d| j¡ t
|dƒ}| ¡ }W d Q R X |  t |dd… d¡d	¡ |  	d
| j¡ t
|dƒ}| ¡ }W d Q R X |  t |dd… d¡d¡ d S )Nrà   r[   zf1.pyz --invalidation-mode=checked-hashr(   é   é   Úlittleé   z"--invalidation-mode=unchecked-hashr   )r   r¤   r¢   r   r   r   r   r   r   r›   r   r*   r>   r+   Ú
from_bytes)r   rµ   Úfpr1   r!   r!   r"   Útest_pyc_invalidation_mode!  s    z/CommandLineTestsBase.test_pyc_invalidation_modezrequires multiprocessingc             C   sž   t  | jdd¡}g }xRtdƒD ]F}tj | jd |¡¡}t |¡ t  |dd¡}| 	t  |dd¡¡ qW |  
| jdd¡ |  |¡ x|D ]}|  |¡ qˆW d S )NrÔ   r[   rd   zfoo{}r    z-jÚ0)r   r¤   r   Úranger   r   r   r¶   r   Úappendr›   rž   )r   rÕ   ÚfilesÚsuffixr¢   rL   r    r!   r!   r"   Útest_workers.  s    


z!CommandLineTestsBase.test_workerszcompileall.compile_dirc          	   C   sR   t jdtj| jdgd0 t ¡  |  |j¡ |  	|j
d d d ¡ W d Q R X d S )Nzsys.argvz-j0)rq   ri   re   )r   rw   r~   Ú
executabler   rA   ÚmainrC   rf   r>   rm   )r   rB   r!   r!   r"   Útest_workers_available_cores=  s
    z1CommandLineTestsBase.test_workers_available_coresN).rs   rt   ru   r„   ÚclassmethodrŽ   r   r”   r›   r   rž   rŸ   r#   rª   r   r°   r´   Únamer»   rÁ   rÃ   ÚlocalsrÄ   rÅ   rÆ   rÌ   rÎ   rÏ   rÒ   rÓ   rÖ   rØ   rÜ   rß   ræ   rç   rì   rí   rî   rõ   r   Ú_have_multiprocessingrû   r   rw   rþ   r!   r!   r!   r"   r…   ì   sL   
	


"
	r…   c               @   s   e Zd ZdS )Ú CommmandLineTestsWithSourceEpochN)rs   rt   ru   r!   r!   r!   r"   r  F  s   r  c               @   s   e Zd ZdS )ÚCommmandLineTestsNoSourceEpochN)rs   rt   ru   r!   r!   r!   r"   r  M  s   r  Ú__main__)%r~   rA   Úimportlib.utilr   Ztest.test_importlib.utilrV   r   rO   r<   r   r.   r   r­   r:   r   r   r   Zconcurrent.futuresr   r  ÚImportErrorr   Ztest.supportr   Ztest_py_compiler   r	   r
   ÚTestCaserx   rz   r{   r…   r  r  rs   rý   r!   r!   r!   r"   Ú<module>   s\   
 +  \
