B
    u9aac  ã               @   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ÚshutilZcopyfileZsubdirectoryÚmkdirÚsource_path3)ÚselfÚfile© r    ú%/usr/lib/python3.7/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ÚmtimeZ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.ÚSOURCE_DATE_EPOCHzSOURCE_DATE_EPOCH is setr'   NÚwbFT)ÚforceÚquiet)r   ÚenvironÚgetÚunittestÚSkipTestÚ
py_compileÚcompiler   ÚassertEqualr2   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   )rC   r-   r.   r   r   r/   )r   r    r    r!   Ú
test_mtimeM   s    zCompileallTestsBase.test_mtimec             C   s   |   d¡ d S )Ns       )rC   )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)r5   r6   é   )r   r   r   ÚunlinkrB   r@   Úcompile_filer   r   ÚisfilerA   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].*))rJ   r   r   rI   r   r   Úcaptured_stdoutrB   r@   rH   Ú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_pathrF   )Úddirr6   )rJ   r   r   rI   r   rB   r@   rH   rN   rO   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   rF   )r6   FT)Úskip_curdirr5   r6   )
ÚtestZtest_importlibr   Zimport_stater   rB   r@   Úcompile_pathr&   rJ   )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 )Nr0   r   r   Ú__pycache__)
r   r   r   r   r   r   r@   rH   rJ   Ú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r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 )NF)r   r   )r   Ú T)r6   Úoptimize)Úoptimization)r@   rA   r   r   r   r   r   rB   r   r   rI   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].*))rJ   r   r   rI   r   r   rM   r@   rA   rN   rO   r   rQ   Ú
splitlinesrP   rB   )r   rR   Ú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é   )r6   Úworkers)r@   rA   r   rB   Ú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éÿÿÿÿ)rg   )ZassertRaisesRegexÚ
ValueErrorr@   rA   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   )r6   rg   r   Úmax_workers)r@   rA   r   r=   Ú	call_args)r   ri   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)r6   )r@   rA   r   rJ   rh   rB   )r   Úcompile_file_mockri   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 )NTrf   )r6   rg   )r@   rA   r   rB   rh   )r   rq   r    r    r!   Ú$test_compile_missing_multiprocessingÀ   s    z8CompileallTestsBase.test_compile_missing_multiprocessing)Ú__name__Ú
__module__Ú__qualname__r"   r$   r&   r2   r9   r   Úhasattrr   rC   rD   rE   rL   rS   rU   rY   r\   rb   re   r   Úpatchrj   rm   rp   rr   rt   r    r    r    r!   r
      s*   	r
   c               @   s   e Zd ZdS )ÚCompileallTestsWithSourceEpochN)ru   rv   rw   r    r    r    r!   rz   Ç   s   rz   )Ú	metaclassZsource_date_epochc               @   s   e Zd ZdS )Ú!CompileallTestsWithoutSourceEpochN)ru   rv   rw   r    r    r    r!   r|   Î   s   r|   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~   )ÚsysrR   ÚioÚTextIOWrapperÚBytesIOr@   rA   r   )r   Zorig_stdoutr    r    r!   Ú
test_errorã   s
    zEncodingTest.test_errorN)ru   rv   rw   Ú__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 )NFrZ   ztest.tryTr   z# for test_compileall)Úfilterr   r   Úisdirr€   rN   rO   Úis_dirr   r   r   ÚOSErrorr   rG   Ú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   r9   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ú-mr@   )r‘   r’   r@   )r   Z!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   rB   r   r   r[   )r   rK   r   r    r    r!   ÚassertCompiled  s    z#CommandLineTestsBase.assertCompiledc             C   s"   t j |¡}|  tj |¡¡ d S )N)r   r   r   rJ   r   r   r[   )r   rK   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foorZ   Ú__init__r]   Zbar)r   r   r   Z
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§   é<   rF   z-f)r   r   r£   r   r›   r   r   r   r   ÚutimeÚtimer+   r,   r=   r?   )r   r¨   Úpycpathr1   Ú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›   ZassertInZassertNotIn)r   Únoisyr6   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-mr@   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¶   rK   )r¸   r    r!   ú
<listcomp>_  s    z*CommandLineTestsBase.f.<locals>.<listcomp>)r   r–   r¡   rB   r   r   r[   r¢   Úsortedr=   ÚlistdirrJ   )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¡   rJ   r   r   r[   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-qrZ   )	r›   r¡   rB   r   r   r[   r¢   r   rJ   )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ª   rF   z-f)r›   r¡   r   r   r   r¥   r   r«   r¬   r+   r,   r=   r?   )r   r­   r1   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-lrZ   )r   r   r   r¡   r   r   r£   r›   rŸ   rJ   r[   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 0rZ   z-r 1z-r 2z-r 5)r   r   r   r¡   r   Zmake_pkgr£   r›   rŸ   rJ   r[   rž   )	r   rÆ   Zsubpackage2Zsubpackage3Z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°   r6   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   Ú_r6   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   rP   )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œ   rP   )r   r¨   rK   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¡   rP   ZassertNotRegexrJ   r[   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¥   rP   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›   rP   )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²   Úfpr0   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]   rf   zfoo{}r    z-jÚ0)r   r£   r   Úranger   r   r   r³   r   Úappendr›   rž   )r   rÑ   ÚfilesÚsuffixr¡   rK   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)rs   rk   rg   )r   ry   r€   Ú
executabler   r@   ÚmainrB   rh   r=   ro   )r   rA   r    r    r!   Útest_workers_available_cores=  s
    z1CommandLineTestsBase.test_workers_available_coresN).ru   rv   rw   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   ry   rù   r    r    r    r!   r†   ì   sL   
	


"
	r†   c               @   s   e Zd ZdS )Ú CommmandLineTestsWithSourceEpochN)ru   rv   rw   r    r    r    r!   rþ   F  s   rþ   c               @   s   e Zd ZdS )ÚCommmandLineTestsNoSourceEpochN)ru   rv   rw   r    r    r    r!   rÿ   M  s   rÿ   Ú__main__)%r€   r@   Úimportlib.utilr   Ztest.test_importlib.utilrW   r   rN   r;   r   r-   r   r¬   r9   r   r   r   Úconcurrent.futuresr   rý   ÚImportErrorr   Ztest.supportr   Ztest_py_compiler   r	   r
   ZTestCaserz   r|   r}   r†   rþ   rÿ   ru   rø   r    r    r    r!   Ú<module>   s\   
 +  \
