B
    ž†\>  ã               @   sr   d dl Z d dlmZ yd dlmZ W n  ek
rD   d dlmZ Y nX 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   s0   i }x t tƒ ¡ D ]\}}|||< qW || _d S )N)Úvarsr   ÚitemsÚ_options_backup)ÚselfZbackupÚnameÚvalue© r   ú@lib/python3.7/site-packages/Cython/Compiler/Tests/TestCmdLine.pyÚsetUp   s    zCmdLineParserTest.setUpc             C   s>   t ƒ }x2| j ¡ D ]$\}}tt||ƒ|krtt||ƒ qW d S )N)Úobjectr
   r	   Úgetattrr   Úsetattr)r   Zno_valuer   Z
orig_valuer   r   r   ÚtearDown   s    zCmdLineParserTest.tearDownc             C   sê   t ddddddddddd	gƒ\}}|  |¡ |  |j¡ |  |j¡ |  |j¡ |  |j¡ |  |jd
k¡ |  tj	¡ |  tj
¡ |  tj¡ |  |jd
¡ t dddgƒ\}}|  |¡ |  t|ƒdk¡ |  |j¡ |  |jd¡ d S )Nz-Vz-lz-+z-tz-vz-pz-Dz-az-3é   z-fz-2z
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 ddddddddddd	d
gƒ\}}|  |¡ |  |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 )Nz	--versionz--create-listingz--cplusz--embedz--timestampsz	--verbosez--embed-positionsz--no-docstringsz
--annotatez	--lenientÚmainr   z--forcez
source.pyxr   )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   r   r   Útest_long_options1   s*    


z#CmdLineParserTest.test_long_optionsc             C   sÆ   t ddddddddd	d
dddgƒ\}}|  |dg¡ |  tjd¡ |  |jdddg¡ |  |jd¡ |  |jd¡ |  tjd¡ |  tjd¡ |  	tj
¡ |  tjd¡ |  	|j¡ |  |jd¡ d S )Nz--embed=huhuz-I/test/include/dir1z --include-dir=/test/include/dir2z--include-dirz/test/include/dir3z--working=/work/dirz
source.pyxz--output-file=/output/dirz--pre-import=/pre/importz--cleanup=3z--annotate-coverage=cov.xmlz--gdb-outdir=/gdb/outdirz--directive=wraparound=falseZhuhuz/test/include/dir1z/test/include/dir2z	/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_debugZ
output_dir)r   r#   r$   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                 sD   t j}tƒ  }t _zˆ  ttt| ƒ¡ W d |t _X ˆ  | ¡ ¡ d S )N)	ÚsysÚstderrr   ZassertRaisesÚ
SystemExitr   Úlistr   Úgetvalue)ÚargsZ
old_stderrr+   )r   r   r   Úerrorf   s    z,CmdLineParserTest.test_errors.<locals>.errorz-1z-Iz--version=-az--version=--annotate=truez	--workingz--verbose=1z	--cleanupr   )r   r0   r   )r   r   Útest_errorse   s    	zCmdLineParserTest.test_errorsN)	Ú__name__Ú
__module__Ú__qualname__r   r   r%   r(   r)   r1   r   r   r   r   r      s   r   )r*   Zunittestr   r   ÚImportErrorÚioÚ r   ZCmdLiner   r   r   r   r   r   Ú<module>   s   