o
    ¢øÁfzO  ã                   @   s    d dl mZ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zd dlmZ W n ey=   d dlmZ Y nw G dd„ deƒZG d	d
„ d
eƒZdS )é    )Úcreate_args_parserÚparse_args_rawÚ
parse_argsÚparallel_compiles)Ú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   úf/var/www/html/mig_web/myenv/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)|jtkrOd|vrOdS d	S )
N)Ú
directivesÚcompile_time_envÚoptionsÚexcludes)	Úlanguage_levelÚannotateÚbuildÚbuild_inplaceÚforceÚquietÚlenientÚ
keep_goingÚno_docstringsr   Ú zFor option ©ÚmsgFÚparallelT)ÚlenÚgetattrÚassertEqualr&   r   )r   r   ÚskipÚempty_containersÚare_noneÚ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--directiver1   r   r2   Tr3   r6   r   r   r   Útest_directive_long0   r9   z+TestCythonizeArgsParser.test_directive_longc                 C   óX   |   g d¢¡\}}|  |¡ |  |  |dg¡¡ |  |jd d¡ |  |jd d¡ d S )N)r0   r1   r0   zc_string_type=bytesr   r2   TÚc_string_typeÚbytesr3   r6   r   r   r   Útest_directive_multiple6   ó
   
z/TestCythonizeArgsParser.test_directive_multiplec                 C   óX   |   ddg¡\}}|  |¡ |  |  |dg¡¡ |  |jd d¡ |  |jd d¡ d S )Nr0   z"cdivision=True,c_string_type=bytesr   r2   Tr<   r=   r3   r6   r   r   r   Útest_directive_multiple_v2=   r?   z2TestCythonizeArgsParser.test_directive_multiple_v2c                 C   r/   )Nr0   zcdivision=YeSr   r2   Tr3   r6   r   r   r   Útest_directive_value_yesD   r9   z0TestCythonizeArgsParser.test_directive_value_yesc                 C   r/   )Nr0   zcdivision=nor   r2   Fr3   r6   r   r   r   Útest_directive_value_noJ   r9   z/TestCythonizeArgsParser.test_directive_value_noc                 C   óB   |   t¡}|  ddg¡\}}W d   ƒ d S 1 sw   Y  d S )Nr0   zcdivision=sadfasd©ÚassertRaisesÚ
ValueErrorr   ©r   Úcontextr   r7   r   r   r   Útest_directive_value_invalidP   ó   "ÿz4TestCythonizeArgsParser.test_directive_value_invalidc                 C   rD   )Nr0   ÚabracadabrarE   rH   r   r   r   Útest_directive_key_invalidT   rK   z2TestCythonizeArgsParser.test_directive_key_invalidc                 C   rD   )Nr0   r2   rE   rH   r   r   r   Útest_directive_no_valueX   rK   z/TestCythonizeArgsParser.test_directive_no_valuec                 C   s–   dddddddddd	d
dœ}|  ¡ D ]6\}}dj|t|ƒd}|  d|g¡\}}|  |¡ | j|  |dg¡d| d | j|j| |d| d qd S )NTÚ	bytearrayr=   ÚstrÚunicodeÚasciié   é   Ú3strÚmy_initial_path)Úauto_pickler<   r<   r<   r<   r<   Úc_string_encodingr   r   r   Úset_initial_pathú{key}={value}©ÚkeyÚvaluer0   r   úError for option: r$   )	ÚitemsÚformatrP   r   r4   r5   r.   r)   r   )r   r   r\   r]   Úcmdr   r7   r   r   r   Útest_directives_types\   s&   õ
ûz-TestCythonizeArgsParser.test_directives_typesc              	   C   sx   ddddœ}|  ¡ D ]/\}}dj|t|ƒd}| jtd| d}|  d	|g¡\}}W d   ƒ n1 s4w   Y  q
d S )
Né*   ÚNONONOÚbites)rW   rW   r<   rZ   r[   r^   r$   r0   )r_   r`   rP   rF   rG   r   )r   r   r\   r]   ra   rI   r   r7   r   r   r   Útest_directives_wrongq   s   ýÿ€þz-TestCythonizeArgsParser.test_directives_wrongc                 C   r/   )Nú-Eú	MYSIZE=10r   ÚMYSIZEé
   ©r   r4   r5   r.   r)   r   r6   r   r   r   Útest_compile_time_env_short~   r9   z3TestCythonizeArgsParser.test_compile_time_env_shortc                 C   r/   )Nz--compile-time-envrh   r   ri   rj   rk   r6   r   r   r   Útest_compile_time_env_long„   r9   z2TestCythonizeArgsParser.test_compile_time_env_longc                 C   r;   )N)rg   rh   rg   z
ARRSIZE=11r   ri   rj   ÚARRSIZEé   rk   r6   r   r   r   Útest_compile_time_env_multipleŠ   r?   z6TestCythonizeArgsParser.test_compile_time_env_multiplec                 C   r@   )Nrg   zMYSIZE=10,ARRSIZE=11r   ri   rj   rn   ro   rk   r6   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   r4   r5   r.   r)   r   r6   r   r   r   Útest_option_short™   r9   z)TestCythonizeArgsParser.test_option_shortc                 C   r/   )Nz--optionrs   r   rt   Tru   r6   r   r   r   Útest_option_longŸ   r9   z(TestCythonizeArgsParser.test_option_longc                 C   sX   |   g d¢¡\}}|  |¡ |  |  |dg¡¡ |  |jd d¡ |  |jd d¡ d S )N)rr   rs   rr   zbuffer_max_dims=8r   rt   TÚbuffer_max_dimsru   r6   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 )Nrr   z!docstrings=True,buffer_max_dims=8r   rt   Trx   ru   r6   r   r   r   Útest_option_multiple_v2¬   r?   z/TestCythonizeArgsParser.test_option_multiple_v2c                 C   r/   )Nrr   zdocstrings=YeSr   rt   Tru   r6   r   r   r   Útest_option_value_yes³   r9   z-TestCythonizeArgsParser.test_option_value_yesc                 C   r/   )Nrr   zdocstrings=4242r   rt   Tru   r6   r   r   r   Útest_option_value_4242¹   r9   z.TestCythonizeArgsParser.test_option_value_4242c                 C   r/   )Nrr   zdocstrings=0r   rt   Fru   r6   r   r   r   Útest_option_value_0¿   r9   z+TestCythonizeArgsParser.test_option_value_0c                 C   r/   )Nrr   zdocstrings=r   rt   Tru   r6   r   r   r   Útest_option_value_emptystrÅ   r9   z2TestCythonizeArgsParser.test_option_value_emptystrc                 C   r/   )Nrr   zdocstrings=BBr   rt   Tru   r6   r   r   r   Útest_option_value_a_strË   r9   z/TestCythonizeArgsParser.test_option_value_a_strc                 C   r/   )Nrr   zdocstrings=nOr   rt   Fru   r6   r   r   r   Útest_option_value_noÑ   r9   z,TestCythonizeArgsParser.test_option_value_noc                 C   óF   |   ddg¡\}}|  |¡ |  |  |dg¡¡ |  |jd d¡ d S )Nrr   rt   r   Tru   r6   r   r   r   Útest_option_no_value×   r9   z,TestCythonizeArgsParser.test_option_no_valuec                 C   r   )Nrr   rL   r   Tru   r6   r   r   r   Útest_option_any_keyÝ   r9   z+TestCythonizeArgsParser.test_option_any_keyc                 C   ó@   |   dg¡\}}|  |¡ |  |  |dg¡¡ |  |jd¡ d S )Nz-2r   rS   ©r   r4   r5   r.   r)   r   r6   r   r   r   Útest_language_level_2ã   ó   
z-TestCythonizeArgsParser.test_language_level_2c                 C   r„   )Nz-3r   rT   r…   r6   r   r   r   Útest_language_level_3é   r‡   z-TestCythonizeArgsParser.test_language_level_3c                 C   r„   )Nú--3strr   rU   r…   r6   r   r   r   Útest_language_level_3strï   r‡   z0TestCythonizeArgsParser.test_language_level_3strc                 C   r„   )Nú-ar   Údefault©r   r4   r5   r.   r)   r   r6   r   r   r   Útest_annotate_shortõ   r‡   z+TestCythonizeArgsParser.test_annotate_shortc                 C   r„   )Nú
--annotater   rŒ   r   r6   r   r   r   Útest_annotate_longû   r‡   z*TestCythonizeArgsParser.test_annotate_longc                 C   r„   )Nú--annotate-fullcr   Úfullcr   r6   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)   r5   r.   r   r6   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Œ   rU   )r   r4   r5   r.   r)   r   r   r6   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   r4   r5   r.   r   r6   r   r   r   Útest_exclude_short  ó   
z*TestCythonizeArgsParser.test_exclude_shortc                 C   r—   )Nú	--excluder˜   r   r™   r6   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   r4   r5   r.   r)   r   r6   r   r   r   Útest_exclude_multiple   r9   z-TestCythonizeArgsParser.test_exclude_multiplec                 C   r„   )Nz-br   T©r   r4   r5   r.   r)   r   r6   r   r   r   Útest_build_short&  r‡   z(TestCythonizeArgsParser.test_build_shortc                 C   r„   )Nz--buildr   Tr    r6   r   r   r   Útest_build_long,  r‡   z'TestCythonizeArgsParser.test_build_longc                 C   r„   )Nú-ir   T©r   r4   r5   r.   r)   r   r6   r   r   r   Útest_inplace_short2  r‡   z*TestCythonizeArgsParser.test_inplace_shortc                 C   r„   )Nz	--inplacer   Tr¤   r6   r   r   r   Útest_inplace_long8  r‡   z)TestCythonizeArgsParser.test_inplace_longc                 C   óB   |   ddg¡\}}|  |¡ |  |  |dg¡¡ |  |jd¡ d S )Nz-jÚ42r&   rc   ©r   r4   r5   r.   r)   r&   r6   r   r   r   Útest_parallel_short>  ó   
z+TestCythonizeArgsParser.test_parallel_shortc                 C   r§   )Nz
--parallelr¨   r&   rc   r©   r6   r   r   r   Útest_parallel_longD  r«   z*TestCythonizeArgsParser.test_parallel_longc                 C   r„   )Nú-fr   T©r   r4   r5   r.   r)   r   r6   r   r   r   Útest_force_shortJ  r‡   z(TestCythonizeArgsParser.test_force_shortc                 C   r„   )Nz--forcer   Tr®   r6   r   r   r   Útest_force_longP  r‡   z'TestCythonizeArgsParser.test_force_longc                 C   r„   )Nz-qr   T©r   r4   r5   r.   r)   r   r6   r   r   r   Útest_quite_shortV  r‡   z(TestCythonizeArgsParser.test_quite_shortc                 C   r„   )Nz--quietr   Tr±   r6   r   r   r   Útest_quite_long\  r‡   z'TestCythonizeArgsParser.test_quite_longc                 C   s@   |   dg¡\}}|  |  |dg¡¡ |  |¡ |  |jd¡ d S )Nú	--lenientr    T)r   r5   r.   r4   r)   r    r6   r   r   r   Útest_lenient_longb  s   
z)TestCythonizeArgsParser.test_lenient_longc                 C   r„   )Nz-kr!   T©r   r4   r5   r.   r)   r!   r6   r   r   r   Útest_keep_going_shorth  r‡   z-TestCythonizeArgsParser.test_keep_going_shortc                 C   r„   )Nz--keep-goingr!   Tr¶   r6   r   r   r   Útest_keep_going_longn  r‡   z,TestCythonizeArgsParser.test_keep_going_longc                 C   r„   )Nú--no-docstringsr"   T)r   r4   r5   r.   r)   r"   r6   r   r   r   Útest_no_docstrings_longt  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.pyxrS   r   é   )r   r)   r'   r5   r.   r6   r   r   r   Útest_file_namez  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   r5   r.   r6   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   r5   r.   r6   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À   r6   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   r5   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   r5   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   rF   Ú
SystemExitr   r5   Úgetvalue)r   Ú
old_stderrrÓ   r   r   r   Útest_wrong_option°  s   
ÿz)TestCythonizeArgsParser.test_wrong_optionN)AÚ__name__Ú
__module__Ú__qualname__r   r.   r8   r:   r>   rA   rB   rC   rJ   rM   rN   rb   rf   rl   rm   rp   rq   rv   rw   ry   rz   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È   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   Ú
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ß   r6   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¹   Frt   )r   r)   r   rt   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Û   )ÚCython.Build.Cythonizer   r   r   r   ÚCython.Compilerr   ÚCython.Compiler.Tests.Utilsr   r   r	   Úunittestr
   rÒ   r   ÚImportErrorÚior   rÛ   r   r   r   r   Ú<module>   s    ÿ   -