o
    ¯N iÇ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   ú^/home/ubuntu/.local/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   Ú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--directiver0   r   r1   Tr2   r5   r   r   r   Útest_directive_long,   r8   z+TestCythonizeArgsParser.test_directive_longc                 C   óX   |   g d¢¡\}}|  |¡ |  |  |dg¡¡ |  |jd d¡ |  |jd d¡ d S )N)r/   r0   r/   zc_string_type=bytesr   r1   TÚc_string_typeÚbytesr2   r5   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   r1   Tr;   r<   r2   r5   r   r   r   Útest_directive_multiple_v29   r>   z2TestCythonizeArgsParser.test_directive_multiple_v2c                 C   r.   )Nr/   zcdivision=YeSr   r1   Tr2   r5   r   r   r   Útest_directive_value_yes@   r8   z0TestCythonizeArgsParser.test_directive_value_yesc                 C   r.   )Nr/   zcdivision=nor   r1   Fr2   r5   r   r   r   Útest_directive_value_noF   r8   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   r6   r   r   r   Útest_directive_value_invalidL   ó   "ÿz4TestCythonizeArgsParser.test_directive_value_invalidc                 C   rC   )Nr/   ÚabracadabrarD   rG   r   r   r   Útest_directive_key_invalidP   rJ   z2TestCythonizeArgsParser.test_directive_key_invalidc                 C   rC   )Nr/   r1   rD   rG   r   r   r   Útest_directive_no_valueT   rJ   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©r;   Ú	bytearray)r;   r<   )r;   ÚstrrO   )r;   Úunicode)Úc_string_encodingÚascii)r   Ú2)r   Ú3)Úset_initial_pathÚmy_initial_pathú{key}={value}©ÚkeyÚvaluer/   r   úError for option: r$   rR   rQ   )ÚformatrQ   r   r3   r4   r-   r(   r   )r   r   r[   r\   Úcmdr   r6   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))rN   é*   )rN   ÚNONONO)r;   ÚbitesrY   rZ   r]   r$   r/   )r^   rQ   rE   rF   r   )r   r   r[   r\   r_   rH   r   r6   r   r   r   Útest_directives_wrongo   s   ÿ€þz-TestCythonizeArgsParser.test_directives_wrongc                 C   r.   )Nú-Eú	MYSIZE=10r   ÚMYSIZEé
   ©r   r3   r4   r-   r(   r   r5   r   r   r   Útest_compile_time_env_short|   r8   z3TestCythonizeArgsParser.test_compile_time_env_shortc                 C   r.   )Nz--compile-time-envrf   r   rg   rh   ri   r5   r   r   r   Útest_compile_time_env_long‚   r8   z2TestCythonizeArgsParser.test_compile_time_env_longc                 C   r:   )N)re   rf   re   z
ARRSIZE=11r   rg   rh   ÚARRSIZEé   ri   r5   r   r   r   Útest_compile_time_env_multipleˆ   r>   z6TestCythonizeArgsParser.test_compile_time_env_multiplec                 C   r?   )Nre   zMYSIZE=10,ARRSIZE=11r   rg   rh   rl   rm   ri   r5   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   r3   r4   r-   r(   r   r5   r   r   r   Útest_option_short—   r8   z)TestCythonizeArgsParser.test_option_shortc                 C   r.   )Nz--optionrq   r   rr   Trs   r5   r   r   r   Útest_option_long   r8   z(TestCythonizeArgsParser.test_option_longc                 C   sX   |   g d¢¡\}}|  |¡ |  |  |dg¡¡ |  |jd d¡ |  |jd d¡ d S )N)rp   rq   rp   zbuffer_max_dims=8r   rr   TÚbuffer_max_dimsrs   r5   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 )Nrp   z!docstrings=True,buffer_max_dims=8r   rr   Trv   rs   r5   r   r   r   Útest_option_multiple_v2ª   r>   z/TestCythonizeArgsParser.test_option_multiple_v2c                 C   r.   )Nrp   zdocstrings=YeSr   rr   Trs   r5   r   r   r   Útest_option_value_yes±   r8   z-TestCythonizeArgsParser.test_option_value_yesc                 C   r.   )Nrp   zdocstrings=4242r   rr   Trs   r5   r   r   r   Útest_option_value_4242·   r8   z.TestCythonizeArgsParser.test_option_value_4242c                 C   r.   )Nrp   zdocstrings=0r   rr   Frs   r5   r   r   r   Útest_option_value_0½   r8   z+TestCythonizeArgsParser.test_option_value_0c                 C   r.   )Nrp   zdocstrings=r   rr   Trs   r5   r   r   r   Útest_option_value_emptystrÃ   r8   z2TestCythonizeArgsParser.test_option_value_emptystrc                 C   r.   )Nrp   zdocstrings=BBr   rr   Trs   r5   r   r   r   Útest_option_value_a_strÉ   r8   z/TestCythonizeArgsParser.test_option_value_a_strc                 C   r.   )Nrp   zdocstrings=nOr   rr   Frs   r5   r   r   r   Útest_option_value_noÏ   r8   z,TestCythonizeArgsParser.test_option_value_noc                 C   óF   |   ddg¡\}}|  |¡ |  |  |dg¡¡ |  |jd d¡ d S )Nrp   rr   r   Trs   r5   r   r   r   Útest_option_no_valueÕ   r8   z,TestCythonizeArgsParser.test_option_no_valuec                 C   r   )Nrp   rK   r   Trs   r5   r   r   r   Útest_option_any_keyÛ   r8   z+TestCythonizeArgsParser.test_option_any_keyc                 C   ó@   |   dg¡\}}|  |¡ |  |  |dg¡¡ |  |jd¡ d S )Nz-2r   é   ©r   r3   r4   r-   r(   r   r5   r   r   r   Útest_language_level_2á   ó   
z-TestCythonizeArgsParser.test_language_level_2c                 C   r‚   )Nz-3r   é   r„   r5   r   r   r   Útest_language_level_3ç   r†   z-TestCythonizeArgsParser.test_language_level_3c                 C   r‚   )Nú--3strr   r‡   r„   r5   r   r   r   Útest_language_level_3strí   r†   z0TestCythonizeArgsParser.test_language_level_3strc                 C   r‚   )Nú-ar   Údefault©r   r3   r4   r-   r(   r   r5   r   r   r   Útest_annotate_shortó   r†   z+TestCythonizeArgsParser.test_annotate_shortc                 C   r‚   )Nú
--annotater   rŒ   r   r5   r   r   r   Útest_annotate_longù   r†   z*TestCythonizeArgsParser.test_annotate_longc                 C   r‚   )Nú--annotate-fullcr   Úfullcr   r5   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(   r4   r-   r   r5   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   r3   r4   r-   r(   r   r   r5   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   r3   r4   r-   r   r5   r   r   r   Útest_exclude_short  ó   
z*TestCythonizeArgsParser.test_exclude_shortc                 C   r—   )Nú	--excluder˜   r   r™   r5   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   r3   r4   r-   r(   r   r5   r   r   r   Útest_exclude_multiple  r8   z-TestCythonizeArgsParser.test_exclude_multiplec                 C   r‚   )Nz-br   T©r   r3   r4   r-   r(   r   r5   r   r   r   Útest_build_short$  r†   z(TestCythonizeArgsParser.test_build_shortc                 C   r‚   )Nz--buildr   Tr    r5   r   r   r   Útest_build_long*  r†   z'TestCythonizeArgsParser.test_build_longc                 C   r‚   )Nú-ir   T©r   r3   r4   r-   r(   r   r5   r   r   r   Útest_inplace_short0  r†   z*TestCythonizeArgsParser.test_inplace_shortc                 C   r‚   )Nz	--inplacer   Tr¤   r5   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"   ra   ©r   r3   r4   r-   r(   r"   r5   r   r   r   Útest_parallel_short<  ó   
z+TestCythonizeArgsParser.test_parallel_shortc                 C   r§   )Nz
--parallelr¨   r"   ra   r©   r5   r   r   r   Útest_parallel_longB  r«   z*TestCythonizeArgsParser.test_parallel_longc                 C   r‚   )Nú-fr   T©r   r3   r4   r-   r(   r   r5   r   r   r   Útest_force_shortH  r†   z(TestCythonizeArgsParser.test_force_shortc                 C   r‚   )Nz--forcer   Tr®   r5   r   r   r   Útest_force_longN  r†   z'TestCythonizeArgsParser.test_force_longc                 C   r‚   )Nz-qr   T©r   r3   r4   r-   r(   r   r5   r   r   r   Útest_quite_shortT  r†   z(TestCythonizeArgsParser.test_quite_shortc                 C   r‚   )Nz--quietr   Tr±   r5   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   r4   r-   r3   r(   r   r5   r   r   r   Útest_lenient_long`  s   
z)TestCythonizeArgsParser.test_lenient_longc                 C   r‚   )Nz-kr    T©r   r3   r4   r-   r(   r    r5   r   r   r   Útest_keep_going_shortf  r†   z-TestCythonizeArgsParser.test_keep_going_shortc                 C   r‚   )Nz--keep-goingr    Tr¶   r5   r   r   r   Útest_keep_going_longl  r†   z,TestCythonizeArgsParser.test_keep_going_longc                 C   r‚   )Nú--no-docstringsr!   T)r   r3   r4   r-   r(   r!   r5   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&   r4   r-   r5   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   r4   r-   r5   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   r4   r-   r5   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À   r5   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   r4   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   r4   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
   rE   Ú
SystemExitr   r4   Úgetvalue)r   Ú
old_stderrrÓ   r   r   r   Útest_wrong_option®  s   
ÿz)TestCythonizeArgsParser.test_wrong_optionN)AÚ__name__Ú
__module__Ú__qualname__r   r-   r7   r9   r=   r@   rA   rB   rI   rL   rM   r`   rd   rj   rk   rn   ro   rt   ru   rw   rx   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      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ß   r5   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¹   Frr   )r   r(   r   rr   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   ÚCython.Compilerr   ÚCython.Compiler.Tests.Utilsr   r   r   Úunittestr	   rÒ   Úior
   r   rÛ   r   r   r   r   Ú<module>   s       /