B
    u9al  ã               @   s„   d dl Z d dlmZ d dlZd dlZd dlZd dlZe d¡Zej	 
ej	 e¡dddd¡ZdZG dd	„ d	e jƒZed
kr€e  ¡  dS )é    N)Úsupportz	symbol.pyz..ZIncludez
graminit.hzsymbol_test.pyc               @   s<   e Zd Zdd„ Zdd„ Zdd„ Ze e 	¡ d¡dd	„ ƒZ
d
S )ÚTestSymbolGenerationc          	   C   sj   t |ƒ}| ¡ }W d Q R X t |dƒ:}| |d | d¡d … ¡ | || d¡d … ¡ W d Q R X d S )NÚwz#--start constants--
é   z#--end constants--
)ÚopenÚ	readlinesÚ
writelinesÚindex)ÚselfZsource_fileZ	dest_fileÚfpÚlines© r   ú!/usr/lib/python3.7/test_symbol.pyÚ$_copy_file_without_generated_symbols   s
    
z9TestSymbolGeneration._copy_file_without_generated_symbolsc             C   s0   t jtjt||gt jd}| ¡ d }|j|fS )N)Ústderrr   )Ú
subprocessÚPopenÚsysÚ
executableÚSYMBOL_FILEÚPIPEZcommunicateÚ
returncode)r
   Zgrammar_fileZtarget_symbol_py_fileÚprocr   r   r   r   Ú_generate_symbols   s    z&TestSymbolGeneration._generate_symbolsc          	   C   sH   t |ƒ}| ¡ }W d Q R X t |ƒ}| ¡ }W d Q R X |  ||¡ d S )N)r   r   ÚassertEqual)r
   Zfile1Zfile2r   Zlines1Zlines2r   r   r   Úcompare_files    s
    

z"TestSymbolGeneration.compare_filesz+test only works from source build directoryc             C   sX   t j}|  t j|¡ |  t|¡ |  t|¡\}}|  d|¡ |  d|¡ |  	t|¡ d S )Nó    r   )
r   ZTESTFNZ
addCleanupÚunlinkr   r   r   ÚGRAMMAR_FILEr   r   )r
   ÚoutputZexitcoder   r   r   r   Ú!test_real_grammar_and_symbol_file'   s    z6TestSymbolGeneration.test_real_grammar_and_symbol_fileN)Ú__name__Ú
__module__Ú__qualname__r   r   r   ÚunittestZ
skipUnlessÚ	sysconfigZis_python_buildr    r   r   r   r   r      s
   
r   Ú__main__)r$   Ztestr   Úosr   r%   r   Zfindfiler   ÚpathÚjoinÚdirnameÚ__file__r   ZTEST_PY_FILEZTestCaser   r!   Úmainr   r   r   r   Ú<module>   s   
'