a
    ûb>  ã                   @   sp   d dl Z d dlmZ zd dlmZ W n eyB   d dlmZ Y n0 ddlmZ ddlm	Z	 G dd„ deƒZ
dS )	é    N)ÚTestCase)ÚStringIOé   )ÚOptions)Úparse_command_linec                   @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚCmdLineParserTestc                 C   s,   i }t tƒ ¡ D ]\}}|||< q|| _d S ©N)Úvarsr   ÚitemsÚ_options_backup)ÚselfÚbackupÚnameÚvalue© r   úq/Users/vegardjervell/Documents/master/model/venv/lib/python3.9/site-packages/Cython/Compiler/Tests/TestCmdLine.pyÚsetUp   s    
zCmdLineParserTest.setUpc                 C   s:   t ƒ }| j ¡ D ]$\}}tt||ƒ|krtt||ƒ qd S r   )Úobjectr   r
   Úgetattrr   Úsetattr)r   Zno_valuer   Z
orig_valuer   r   r   ÚtearDown   s    zCmdLineParserTest.tearDownc                 C   sÖ   t g d¢ƒ\}}|  |¡ |  |j¡ |  |j¡ |  |j¡ |  |j¡ |  |jdk¡ |  tj	¡ |  tj
¡ |  tj¡ |  |jd¡ t g d¢ƒ\}}|  |¡ |  t|ƒdk¡ |  |j¡ |  |jd¡ d S )N)z-Vz-lz-+z-tú-vr   r   z-pz-Dz-az-3é   )z-fz-2ú
source.pyxé   r   )r   ÚassertFalseÚ
assertTrueÚshow_versionÚuse_listing_fileÚcplusÚ
timestampsÚverboser   Úembed_pos_in_docstringÚ
docstringsÚannotateÚassertEqualZlanguage_levelÚlen©r   ÚoptionsÚsourcesr   r   r   Útest_short_options   s     

z$CmdLineParserTest.test_short_optionsc                 C   sà   t g d¢ƒ\}}|  |¡ |  |j¡ |  |j¡ |  |j¡ |  tjd¡ |  |j	¡ |  |j
dk¡ |  tj¡ |  tj¡ |  tj¡ |  tj¡ |  tj¡ t ddgƒ\}}|  |¡ |  t|ƒdk¡ |  |j	¡ d S )N)z	--versionz--create-listingz--cplusz--embedz--timestampsú	--verboser+   r+   z--embed-positionsz--no-docstringsz
--annotatez	--lenientÚmainr   z--forcer   r   )r   r   r   r   r   r   r%   r   Úembedr    r!   r"   r#   r$   Zerror_on_unknown_namesZerror_on_uninitializedr&   r'   r   r   r   Útest_long_options1   s&    
ÿ

z#CmdLineParserTest.test_long_optionsc                 C   s®   t g d¢ƒ\}}|  |dg¡ |  tjd¡ |  |jg d¢¡ |  |jd¡ |  |jd¡ |  tjd¡ |  tjd¡ |  	tj
¡ |  tjd	¡ |  	|j¡ |  |jd
¡ d S )N)z--embed=huhuz-I/test/include/dir1z --include-dir=/test/include/dir2z--include-dirú/test/include/dir3z--working=/work/dirr   z--output-file=/output/dirz--pre-import=/pre/importz--cleanup=3z--annotate-coverage=cov.xmlz--gdb-outdir=/gdb/outdirz--directive=wraparound=falser   Zhuhu)z/test/include/dir1z/test/include/dir2r/   z	/work/dirz/output/dirz/pre/importr   zcov.xmlz/gdb/outdir)r   r%   r   r-   Zinclude_pathZworking_pathZoutput_fileZ
pre_importZgenerate_cleanup_coder   r$   Zannotate_coverage_xmlZ	gdb_debugÚ
output_dirr'   r   r   r   Útest_options_with_valuesK   s    z*CmdLineParserTest.test_options_with_valuesc                    sP   ‡ fdd„}|dƒ |dƒ |dƒ |dƒ |dƒ |dƒ |dƒ |d	ƒ d S )
Nc                     sJ   t j}tƒ  }t _zˆ  ttt| ƒ¡ W |t _n|t _0 ˆ  | ¡ ¡ d S r   )	ÚsysÚstderrr   ÚassertRaisesÚ
SystemExitr   Úlistr   Úgetvalue)ÚargsZ
old_stderrr3   ©r   r   r   Úerrorf   s    z,CmdLineParserTest.test_errors.<locals>.errorz-1z-Iz--version=-az--version=--annotate=truez	--workingz--verbose=1z	--cleanupr   )r   r:   r   r9   r   Útest_errorse   s    	zCmdLineParserTest.test_errorsN)	Ú__name__Ú
__module__Ú__qualname__r   r   r*   r.   r1   r;   r   r   r   r   r      s   r   )r2   Zunittestr   r   ÚImportErrorÚioÚ r   ZCmdLiner   r   r   r   r   r   Ú<module>   s   