o
    GXîhÅ  ã                   @   s˜   	 d dl Zd dlZd dlZd dlmZ d dlZd dlZd dlZe 	¡ s(e 
d¡‚eeeeƒƒƒZej ed¡ZG dd„ dejƒZedkrJe ¡  dS dS )é    N)Údirnamez'test irrelevant for an installed PythonZParserc                   @   s\   e Zd Zed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S )ÚTestAsdlParserc                 C   s‚   t j dt¡ tj dtj td¡¡}tj	 
d|¡}tj	 |¡}| |¡ || _| j tj td¡¡| _|  | j | j¡d¡ d S )Nr   Úasdlzasdl.pyzPython.asdlzModule validation failed)ÚsysÚpathÚinsertÚ
parser_dirÚ	importlibÚ	machineryÚSourceFileLoaderÚosÚjoinÚutilÚspec_from_loaderÚmodule_from_specÚexec_moduler   ÚparseÚmodÚ
assertTrueÚcheck)ÚclsÚloaderÚspecÚmodule© r   ú?/opt/python-3.10.19/usr/lib/python3.10/test/test_asdl_parser.pyÚ
setUpClass   s   ÿ
zTestAsdlParser.setUpClassc                 C   s   t jd= d S )Nr   )r   r   )r   r   r   r   ÚtearDownClass%   s   zTestAsdlParser.tearDownClassc                 C   s   t j| _t j| _| jj| _d S ©N)r   r   r   Útypes©Úselfr   r   r   ÚsetUp)   s   zTestAsdlParser.setUpc                 C   s>   |   | jjd¡ |  d| j¡ |  d| j¡ |  d| j¡ d S )NÚPythonÚstmtÚexprr   )ÚassertEqualr   ÚnameZassertInr   r    r   r   r   Útest_module/   s   zTestAsdlParser.test_modulec                 C   sb   | j j}|  |d | jj¡ |  |d j| jj¡ |  | jd | jj¡ |  | jd | jj¡ d S )Nr   ZwithitemÚalias)	r   ÚdfnsÚassertIsInstancer   ZTypeÚvalueZSumr   ZProduct)r!   Zdefsr   r   r   Útest_definitions5   s
   zTestAsdlParser.test_definitionsc                 C   s   | j d }|  t|ƒd¡ d S )Nr)   z½Product([Field(identifier, name), Field(identifier, asname, opt=True)], [Field(int, lineno), Field(int, col_offset), Field(int, end_lineno, opt=True), Field(int, end_col_offset, opt=True)]))r   r&   Ústr)r!   r)   r   r   r   Útest_product=   s
   
þzTestAsdlParser.test_productc                 C   sx   | j d }|  t|jƒd¡ |  t|jd ƒd¡ |  t|jd ƒd¡ |  t|jd ƒd¡ |  t|jd	 ƒd
¡ d S )Nr$   é   r   zField(int, lineno)é   zField(int, col_offset)é   z Field(int, end_lineno, opt=True)é   z$Field(int, end_col_offset, opt=True))r   r&   ÚlenÚ
attributesÚrepr)r!   r$   r   r   r   Útest_attributesE   s   
zTestAsdlParser.test_attributesc                 C   s   | j d }|  t|j ƒd¡ |  t|jƒd¡ |j d }|  || jj¡ |  t|jƒd¡ |jd }|  |jd¡ |  |j	d¡ |  
|j¡ |jd }|  |jd¡ |  |j	d	¡ |  
|j¡ |jd
 }|  |jd¡ |  |j	d¡ |  |j¡ |  
|j¡ d S )NZexcepthandlerr1   r0   r   r3   r%   ÚtypeZ
identifierr'   r2   r$   Úbody)r   r&   r4   r5   r+   r   ZConstructorÚfieldsr8   r'   r   ÚoptZassertFalseÚseq)r!   ZehandlerÚconsZf0Úf1Úf2r   r   r   Útest_constructor_fieldsM   s&   




z&TestAsdlParser.test_constructor_fieldsc                 C   s@   G dd„ d| j jƒ}|ƒ }| | jd ¡ |  |jg d¢¡ d S )Nc                       s<   e Zd Z‡ fdd„Zdd„ Zdd„ Zdd„ Zd	d
„ Z‡  ZS )z2TestAsdlParser.test_visitor.<locals>.CustomVisitorc                    s   t ƒ  ¡  g | _d S r   )ÚsuperÚ__init__Únames_with_seqr    ©Ú	__class__r   r   rB   h   s   

z;TestAsdlParser.test_visitor.<locals>.CustomVisitor.__init__c                 S   ó   |j D ]}|  |¡ qd S r   )r*   Úvisit)r!   r   Zdfnr   r   r   ÚvisitModulel   ó   
ÿz>TestAsdlParser.test_visitor.<locals>.CustomVisitor.visitModulec                 S   s   |   |j¡ d S r   )rG   r,   )r!   r8   r   r   r   Ú	visitTypep   s   z<TestAsdlParser.test_visitor.<locals>.CustomVisitor.visitTypec                 S   rF   r   )r   rG   )r!   ÚsumÚtr   r   r   ÚvisitSums   rI   z;TestAsdlParser.test_visitor.<locals>.CustomVisitor.visitSumc                 S   s$   |j D ]}|jr| j |j¡ qd S r   )r:   r<   rC   Úappendr'   )r!   r=   Úfr   r   r   ÚvisitConstructorw   s
   
€þzCTestAsdlParser.test_visitor.<locals>.CustomVisitor.visitConstructor)	Ú__name__Ú
__module__Ú__qualname__rB   rH   rJ   rM   rP   Ú__classcell__r   r   rD   r   ÚCustomVisitorg   s    rU   r   )ÚModulerV   ZInteractiveÚFunctionType)r   ZVisitorBaserG   r   r&   rC   )r!   rU   Úvr   r   r   Útest_visitorf   s   ÿzTestAsdlParser.test_visitorN)rQ   rR   rS   Úclassmethodr   r   r"   r(   r-   r/   r7   r@   rY   r   r   r   r   r      s    

r   Ú__main__)Úimportlib.machineryr	   Úimportlib.utilr   Zos.pathr   r   Z	sysconfigZunittestZis_python_buildZSkipTestÚ__file__Zsrc_baser   r   r   ZTestCaser   rQ   Úmainr   r   r   r   Ú<module>   s     
nÿ