o
    2g                     @  sj   d Z ddlmZ ddlZddlZddlZddlZddlmZ ddl	m
Z
 ddlmZ G dd dejZdS )	zPTest that C functions used in primitives are declared in a header such as CPy.h.    )annotationsN)PrimitiveDescription)registry)CFunctionDescriptionc                   @  s   e Zd ZdddZdS )TestHeaderInclusionreturnNonec              	     s  t jt jtdd}tt j|d}|  W d    n1 s$w   Y  tt j|d} | 7  W d    n1 sCw   Y  d fd	d
}tj	 tj
	 tj	 fD ]}|D ]}t|trk|g}|D ]}||j qmqaq]tj	 fD ]}|D ]}t|tr|g}|D ]}	|	jd ur||	j qqq}t jt jtdd}
t|
 dD ]'}t|}| }W d    n1 sw   Y  td|D ]}|| qqd S )Nz..zlib-rtzCPy.hzpythonsupport.hnamestrr   r   c                   s6   |  drtd|  d sJ d|  dd S d S )NCPyz\b"z7" is used in mypyc.primitives but not declared in CPy.h)
startswithresearch)r	   header O/home/garg/my-data/venv/lib/python3.10/site-packages/mypyc/test/test_cheader.py
check_name   s   

zJTestHeaderInclusion.test_primitives_included_in_header.<locals>.check_name
primitivesz/*.pyz'c_function_name=["\'](CPy[A-Z_a-z0-9]+))r	   r
   r   r   )ospathjoindirname__file__openreadr   method_call_opsvaluesfunction_ops	unary_ops
isinstancer   c_function_name
binary_opsr   globr   findall)selfbase_dirfr   
old_valuesold_opsold_opr   opsopprimitives_pathfnamcontentr	   r   r   r   "test_primitives_included_in_header   sL   







z6TestHeaderInclusion.test_primitives_included_in_headerN)r   r   )__name__
__module____qualname__r1   r   r   r   r   r      s    r   )__doc__
__future__r   r$   r   r   unittestmypyc.ir.opsr   mypyc.primitivesr   mypyc.primitives.registryr   TestCaser   r   r   r   r   <module>   s    