o
    ÕjÇN  ã                   @   sx   d dl mZmZmZ d dlmZ d dlmZmZm	Z	 d dl
mZ d dlZd dlmZ G dd„ deƒZG d	d
„ d
eƒZdS )é    )Úcreate_args_parserÚparse_args_rawÚ
parse_args)ÚOptions)Úbackup_OptionsÚrestore_OptionsÚcheck_global_options)ÚTestCaseN)ÚStringIOc                   @   sü  e Z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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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%dGdH„ Z&dIdJ„ Z'dKdL„ Z(dMdN„ Z)dOdP„ Z*dQdR„ Z+dSdT„ Z,dUdV„ Z-dWdX„ Z.dYdZ„ Z/d[d\„ Z0d]d^„ Z1d_d`„ Z2dadb„ Z3dcdd„ Z4dedf„ Z5dgdh„ Z6didj„ Z7dkdl„ Z8dmdn„ Z9dodp„ Z:dqdr„ Z;dsdt„ Z<dudv„ Z=dwdx„ Z>dydz„ Z?d{d|„ Z@d}S )~ÚTestCythonizeArgsParserc                 C   s   t  | ¡ tƒ fdd„| _d S )Nc                 S   s
   t || ƒS ©N)r   )ÚxÚparser© r   úk/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/Cython/Build/Tests/TestCythonizeArgsParser.pyÚ<lambda>   s   
 z/TestCythonizeArgsParser.setUp.<locals>.<lambda>)r	   ÚsetUpr   r   ©Úselfr   r   r   r      s   
zTestCythonizeArgsParser.setUpc                 C   sŒ   g d¢}g d¢}|D ]}t t||ƒƒdkr&||vr&| j|dd| d  dS q
|D ]}t||ƒd urC||vrC| j|dd| d  dS q)dS )	N)Ú
directivesÚcompile_time_envÚoptionsÚexcludes)
Úlanguage_levelÚannotateÚbuildÚbuild_inplaceÚforceÚquietÚlenientÚ
keep_goingÚno_docstringsÚparallelr   Ú zFor option ©ÚmsgFT)ÚlenÚgetattrÚassertEqual)r   r   ÚskipZempty_containersZare_noneZopt_namer   r   r   Úare_default   s   €€z#TestCythonizeArgsParser.are_defaultc                 C   óF   |   ddg¡\}}|  |¡ |  |  |dg¡¡ |  |jd d¡ d S )Nú-Xúcdivision=Truer   Ú	cdivisionT©r   ÚassertFalseÚ
assertTruer*   r(   r   ©r   r   Úargsr   r   r   Útest_directive_short&   ó   
z,TestCythonizeArgsParser.test_directive_shortc                 C   r+   )Nz--directiver-   r   r.   Tr/   r2   r   r   r   Útest_directive_long,   r5   z+TestCythonizeArgsParser.test_directive_longc                 C   óX   |   g d¢¡\}}|  |¡ |  |  |dg¡¡ |  |jd d¡ |  |jd d¡ d S )N)r,   r-   r,   zc_string_type=bytesr   r.   TÚc_string_typeÚbytesr/   r2   r   r   r   Útest_directive_multiple2   ó
   
z/TestCythonizeArgsParser.test_directive_multiplec                 C   óX   |   ddg¡\}}|  |¡ |  |  |dg¡¡ |  |jd d¡ |  |jd d¡ d S )Nr,   z"cdivision=True,c_string_type=bytesr   r.   Tr8   r9   r/   r2   r   r   r   Útest_directive_multiple_v29   r;   z2TestCythonizeArgsParser.test_directive_multiple_v2c                 C   r+   )Nr,   zcdivision=YeSr   r.   Tr/   r2   r   r   r   Útest_directive_value_yes@   r5   z0TestCythonizeArgsParser.test_directive_value_yesc                 C   r+   )Nr,   zcdivision=nor   r.   Fr/   r2   r   r   r   Útest_directive_value_noF   r5   z/TestCythonizeArgsParser.test_directive_value_noc                 C   óB   |   t¡}|  ddg¡\}}W d   ƒ d S 1 sw   Y  d S )Nr,   zcdivision=sadfasd©ÚassertRaisesÚ
ValueErrorr   ©r   Úcontextr   r3   r   r   r   Útest_directive_value_invalidL   ó   "ÿz4TestCythonizeArgsParser.test_directive_value_invalidc                 C   r@   )Nr,   ÚabracadabrarA   rD   r   r   r   Útest_directive_key_invalidP   rG   z2TestCythonizeArgsParser.test_directive_key_invalidc                 C   r@   )Nr,   r.   rA   rD   r   r   r   Útest_directive_no_valueT   rG   z/TestCythonizeArgsParser.test_directive_no_valuec                 C   sŠ   g d¢}|D ]<\}}dj |t|ƒd}|  d|g¡\}}|  |¡ | j|  |dg¡d| d |dkr5d	}| j|j| |d| d qd S )
N)
)Úauto_pickleT©r8   Ú	bytearray)r8   r9   )r8   ÚstrrL   )r8   Úunicode)Zc_string_encodingÚascii)r   Ú2)r   Ú3)Zset_initial_pathZmy_initial_pathú{key}={value}©ÚkeyÚvaluer,   r   úError for option: r$   rO   rN   )ÚformatrN   r   r0   r1   r*   r(   r   )r   r   rU   rV   Úcmdr   r3   r   r   r   Útest_directives_typesX   s   
ùz-TestCythonizeArgsParser.test_directives_typesc              	   C   sp   g d¢}|D ]/\}}dj |t|ƒd}| jtd| d}|  d|g¡\}}W d   ƒ n1 s0w   Y  qd S )N))rK   é*   )rK   ZNONONO)r8   ZbitesrS   rT   rW   r$   r,   )rX   rN   rB   rC   r   )r   r   rU   rV   rY   rE   r   r3   r   r   r   Útest_directives_wrongo   s   ÿ€þz-TestCythonizeArgsParser.test_directives_wrongc                 C   r+   )Nú-Eú	MYSIZE=10r   ÚMYSIZEé
   ©r   r0   r1   r*   r(   r   r2   r   r   r   Útest_compile_time_env_short|   r5   z3TestCythonizeArgsParser.test_compile_time_env_shortc                 C   r+   )Nz--compile-time-envr^   r   r_   r`   ra   r2   r   r   r   Útest_compile_time_env_long‚   r5   z2TestCythonizeArgsParser.test_compile_time_env_longc                 C   r7   )N)r]   r^   r]   z
ARRSIZE=11r   r_   r`   ÚARRSIZEé   ra   r2   r   r   r   Útest_compile_time_env_multipleˆ   r;   z6TestCythonizeArgsParser.test_compile_time_env_multiplec                 C   r<   )Nr]   zMYSIZE=10,ARRSIZE=11r   r_   r`   rd   re   ra   r2   r   r   r   Ú!test_compile_time_env_multiple_v2   r;   z9TestCythonizeArgsParser.test_compile_time_env_multiple_v2c                 C   r+   )Nú-súdocstrings=Truer   Ú
docstringsT©r   r0   r1   r*   r(   r   r2   r   r   r   Útest_option_short—   r5   z)TestCythonizeArgsParser.test_option_shortc                 C   r+   )Nz--optionri   r   rj   Trk   r2   r   r   r   Útest_option_long   r5   z(TestCythonizeArgsParser.test_option_longc                 C   sX   |   g d¢¡\}}|  |¡ |  |  |dg¡¡ |  |jd d¡ |  |jd d¡ d S )N)rh   ri   rh   zbuffer_max_dims=8r   rj   TÚbuffer_max_dimsrk   r2   r   r   r   Útest_option_multiple£   r;   z,TestCythonizeArgsParser.test_option_multiplec                 C   sX   |   ddg¡\}}|  |¡ |  |  |dg¡¡ |  |jd d¡ |  |jd d¡ d S )Nrh   z!docstrings=True,buffer_max_dims=8r   rj   Trn   rk   r2   r   r   r   Útest_option_multiple_v2ª   r;   z/TestCythonizeArgsParser.test_option_multiple_v2c                 C   r+   )Nrh   zdocstrings=YeSr   rj   Trk   r2   r   r   r   Útest_option_value_yes±   r5   z-TestCythonizeArgsParser.test_option_value_yesc                 C   r+   )Nrh   zdocstrings=4242r   rj   Trk   r2   r   r   r   Útest_option_value_4242·   r5   z.TestCythonizeArgsParser.test_option_value_4242c                 C   r+   )Nrh   zdocstrings=0r   rj   Frk   r2   r   r   r   Útest_option_value_0½   r5   z+TestCythonizeArgsParser.test_option_value_0c                 C   r+   )Nrh   zdocstrings=r   rj   Trk   r2   r   r   r   Útest_option_value_emptystrÃ   r5   z2TestCythonizeArgsParser.test_option_value_emptystrc                 C   r+   )Nrh   zdocstrings=BBr   rj   Trk   r2   r   r   r   Útest_option_value_a_strÉ   r5   z/TestCythonizeArgsParser.test_option_value_a_strc                 C   r+   )Nrh   zdocstrings=nOr   rj   Frk   r2   r   r   r   Útest_option_value_noÏ   r5   z,TestCythonizeArgsParser.test_option_value_noc                 C   óF   |   ddg¡\}}|  |¡ |  |  |dg¡¡ |  |jd d¡ d S )Nrh   rj   r   Trk   r2   r   r   r   Útest_option_no_valueÕ   r5   z,TestCythonizeArgsParser.test_option_no_valuec                 C   rw   )Nrh   rH   r   Trk   r2   r   r   r   Útest_option_any_keyÛ   r5   z+TestCythonizeArgsParser.test_option_any_keyc                 C   ó@   |   dg¡\}}|  |¡ |  |  |dg¡¡ |  |jd¡ d S )Nz-2r   é   ©r   r0   r1   r*   r(   r   r2   r   r   r   Útest_language_level_2á   ó   
z-TestCythonizeArgsParser.test_language_level_2c                 C   rz   )Nz-3r   é   r|   r2   r   r   r   Útest_language_level_3ç   r~   z-TestCythonizeArgsParser.test_language_level_3c                 C   rz   )Nú--3strr   r   r|   r2   r   r   r   Útest_language_level_3strí   r~   z0TestCythonizeArgsParser.test_language_level_3strc                 C   rz   )Nú-ar   Údefault©r   r0   r1   r*   r(   r   r2   r   r   r   Útest_annotate_shortó   r~   z+TestCythonizeArgsParser.test_annotate_shortc                 C   rz   )Nú
--annotater   r„   r…   r2   r   r   r   Útest_annotate_longù   r~   z*TestCythonizeArgsParser.test_annotate_longc                 C   rz   )Nú--annotate-fullcr   Úfullcr…   r2   r   r   r   Útest_annotate_fullcÿ   r~   z+TestCythonizeArgsParser.test_annotate_fullcc                 C   sF   |   ddg¡\}}|  |dg¡ |  |  |dg¡¡ |  |jd¡ d S )Nrƒ   úfoo.pyxr   r„   )r   r(   r1   r*   r   r2   r   r   r   Útest_annotate_and_positional  s   z4TestCythonizeArgsParser.test_annotate_and_positionalc                 C   sR   |   ddg¡\}}|  |¡ |  |  |ddg¡¡ |  |jd¡ |  |jd¡ d S )Nrƒ   r   r   r   r„   r   )r   r0   r1   r*   r(   r   r   r2   r   r   r   Útest_annotate_and_optional  s
   
z2TestCythonizeArgsParser.test_annotate_and_optionalc                 C   óD   |   ddg¡\}}|  |¡ |  |  |dg¡¡ |  d|jv ¡ d S )Nz-xú*.pyxr   ©r   r0   r1   r*   r   r2   r   r   r   Útest_exclude_short  ó   
z*TestCythonizeArgsParser.test_exclude_shortc                 C   r   )Nú	--excluder   r   r‘   r2   r   r   r   Útest_exclude_long  r“   z)TestCythonizeArgsParser.test_exclude_longc                 C   sF   |   g d¢¡\}}|  |¡ |  |  |dg¡¡ |  |jddg¡ d S )N)r”   r   r”   ú*.pyr   r   r–   )r   r0   r1   r*   r(   r   r2   r   r   r   Útest_exclude_multiple  r5   z-TestCythonizeArgsParser.test_exclude_multiplec                 C   rz   )Nz-br   T©r   r0   r1   r*   r(   r   r2   r   r   r   Útest_build_short$  r~   z(TestCythonizeArgsParser.test_build_shortc                 C   rz   )Nz--buildr   Tr˜   r2   r   r   r   Útest_build_long*  r~   z'TestCythonizeArgsParser.test_build_longc                 C   rz   )Nú-ir   T©r   r0   r1   r*   r(   r   r2   r   r   r   Útest_inplace_short0  r~   z*TestCythonizeArgsParser.test_inplace_shortc                 C   rz   )Nz	--inplacer   Trœ   r2   r   r   r   Útest_inplace_long6  r~   z)TestCythonizeArgsParser.test_inplace_longc                 C   óB   |   ddg¡\}}|  |¡ |  |  |dg¡¡ |  |jd¡ d S )Nz-jÚ42r"   r[   ©r   r0   r1   r*   r(   r"   r2   r   r   r   Útest_parallel_short<  ó   
z+TestCythonizeArgsParser.test_parallel_shortc                 C   rŸ   )Nz
--parallelr    r"   r[   r¡   r2   r   r   r   Útest_parallel_longB  r£   z*TestCythonizeArgsParser.test_parallel_longc                 C   rz   )Nú-fr   T©r   r0   r1   r*   r(   r   r2   r   r   r   Útest_force_shortH  r~   z(TestCythonizeArgsParser.test_force_shortc                 C   rz   )Nz--forcer   Tr¦   r2   r   r   r   Útest_force_longN  r~   z'TestCythonizeArgsParser.test_force_longc                 C   rz   )Nz-qr   T©r   r0   r1   r*   r(   r   r2   r   r   r   Útest_quite_shortT  r~   z(TestCythonizeArgsParser.test_quite_shortc                 C   rz   )Nz--quietr   Tr©   r2   r   r   r   Útest_quite_longZ  r~   z'TestCythonizeArgsParser.test_quite_longc                 C   s@   |   dg¡\}}|  |  |dg¡¡ |  |¡ |  |jd¡ d S )Nú	--lenientr   T)r   r1   r*   r0   r(   r   r2   r   r   r   Útest_lenient_long`  s   
z)TestCythonizeArgsParser.test_lenient_longc                 C   rz   )Nz-kr    T©r   r0   r1   r*   r(   r    r2   r   r   r   Útest_keep_going_shortf  r~   z-TestCythonizeArgsParser.test_keep_going_shortc                 C   rz   )Nz--keep-goingr    Tr®   r2   r   r   r   Útest_keep_going_longl  r~   z,TestCythonizeArgsParser.test_keep_going_longc                 C   rz   )Nú--no-docstringsr!   T)r   r0   r1   r*   r(   r!   r2   r   r   r   Útest_no_docstrings_longr  r~   z/TestCythonizeArgsParser.test_no_docstrings_longc                 C   sX   |   ddg¡\}}|  t|ƒd¡ |  |d d¡ |  |d d¡ |  |  |g ¡¡ d S )Nú	file1.pyxú	file2.pyxr{   r   é   )r   r(   r&   r1   r*   r2   r   r   r   Útest_file_namex  s
   z&TestCythonizeArgsParser.test_file_namec                 C   sF   |   ddg¡\}}|  |dg¡ |  |jd¡ |  |  |dg¡¡ d S )Nr›   úfile.pyxTr   ©r   r(   r   r1   r*   r2   r   r   r   Útest_option_first  ó   z)TestCythonizeArgsParser.test_option_firstc                 C   sV   |   g d¢¡\}}|  |dg¡ |  |jd¡ |  |jd¡ |  |  |ddg¡¡ d S )N)r›   r·   rƒ   r·   Tr„   r   r   )r   r(   r   r   r1   r*   r2   r   r   r   Útest_file_inbetween…  s
   z+TestCythonizeArgsParser.test_file_inbetweenc                 C   sF   |   ddg¡\}}|  |dg¡ |  |jd¡ |  |  |dg¡¡ d S )Nr·   r›   Tr   r¸   r2   r   r   r   Útest_option_trailingŒ  rº   z,TestCythonizeArgsParser.test_option_trailingc                 C   sH   |   g d¢¡\}}|  |ddg¡ |  |jd¡ |  |  |dg¡¡ d S )N)r³   rƒ   r´   r³   r´   r„   r   ©r   r(   r   r1   r*   ©r   r   Úsourcesr   r   r   Útest_interspersed_positional’  ó   z4TestCythonizeArgsParser.test_interspersed_positionalc                 C   sH   |   g d¢¡\}}|  |g d¢¡ |  |jd¡ |  |  |dg¡¡ d S )N)r³   rƒ   r´   rƒ   ú	file3.pyx)r³   r´   rÂ   r„   r   r½   r¾   r   r   r   Útest_interspersed_positional2›  rÁ   z5TestCythonizeArgsParser.test_interspersed_positional2c                 C   sX   |   g d¢¡\}}|  |g d¢¡ |  |jd¡ |  |jd¡ |  |  |ddg¡¡ d S )N)r¥   Úf1Úf2rƒ   Úf3Úf4rƒ   Úf5)rÄ   rÅ   rÆ   rÇ   rÈ   r„   Tr   r   )r   r(   r   r   r1   r*   r¾   r   r   r   Útest_interspersed_positional3¤  s
   z5TestCythonizeArgsParser.test_interspersed_positional3c                 C   sJ   t j}tƒ  }t _z|  t| jdg¡ W |t _n|t _w |  | ¡ ¡ d S )Nz--unknown-option)ÚsysÚstderrr
   rB   Ú
SystemExitr   r1   Úgetvalue)r   Z
old_stderrrË   r   r   r   Útest_wrong_option®  s   
ÿz)TestCythonizeArgsParser.test_wrong_optionN)AÚ__name__Ú
__module__Ú__qualname__r   r*   r4   r6   r:   r=   r>   r?   rF   rI   rJ   rZ   r\   rb   rc   rf   rg   rl   rm   ro   rp   rq   rr   rs   rt   ru   rv   rx   ry   r}   r€   r‚   r†   rˆ   r‹   r   rŽ   r’   r•   r—   r™   rš   r   rž   r¢   r¤   r§   r¨   rª   r«   r­   r¯   r°   r²   r¶   r¹   r»   r¼   rÀ   rÃ   rÉ   rÎ   r   r   r   r   r      s~    		
r   c                   @   sP   e Zd Zdd„ Zdd„ Zg fdd„Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dS )ÚTestParseArgsc                 C   s   t ƒ | _d S r   )r   Ú_options_backupr   r   r   r   r   »  s   zTestParseArgs.setUpc                 C   s   t | jƒ d S r   )r   rÓ   r   r   r   r   ÚtearDown¾  s   zTestParseArgs.tearDownc                 C   s   |   t| j|ƒd¡ d S )Nr#   )r(   r   rÓ   )r   Z
white_listr   r   r   Úcheck_default_global_optionsÁ  s   z*TestParseArgs.check_default_global_optionsc                 C   s*   t ddgƒ\}}|  |jd¡ |  ¡  d S )NrŒ   r›   T)r   r(   r   rÕ   r2   r   r   r   Útest_build_set_for_inplaceÄ  s   z(TestParseArgs.test_build_set_for_inplacec                 C   sL   t ddgƒ\}}|  |dg¡ |  tjd¡ |  tjd¡ |  ddg¡ d S )NrŒ   r¬   FÚerror_on_unknown_namesÚerror_on_uninitialized)r   r(   r   r×   rØ   rÕ   r¾   r   r   r   Útest_lenientÉ  s
   zTestParseArgs.test_lenientc                 C   ó<   t ddgƒ\}}|  |dg¡ |  tjd¡ |  dg¡ d S )NrŒ   r‡   r„   r   ©r   r(   r   r   rÕ   r¾   r   r   r   Útest_annotateÐ  ó   zTestParseArgs.test_annotatec                 C   rÚ   )NrŒ   r‰   rŠ   r   rÛ   r¾   r   r   r   r‹   Ö  rÝ   z!TestParseArgs.test_annotate_fullcc                 C   rÚ   )NrŒ   r±   Frj   )r   r(   r   rj   rÕ   r¾   r   r   r   Útest_no_docstringsÜ  rÝ   z TestParseArgs.test_no_docstringsN)rÏ   rÐ   rÑ   r   rÔ   rÕ   rÖ   rÙ   rÜ   r‹   rÞ   r   r   r   r   rÒ   º  s    rÒ   )ZCython.Build.Cythonizer   r   r   ZCython.Compilerr   ZCython.Compiler.Tests.Utilsr   r   r   Zunittestr	   rÊ   Úior
   r   rÒ   r   r   r   r   Ú<module>   s       /