
    ڏDjIY                         d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZm	Z	 ddl
mZ ddlmZ dd	lmZmZmZ e j$                  j&                  Zd
 Z ed e	e             G d de             Zy)    N)StringIO)TestCase)patchMock   )Options)parse_command_line   )backup_Optionsrestore_Optionscheck_global_optionsc           
          | dt         j                  j                  dd      t         j                  j                  dd      dddddd	f	v ry
t        |       S )N
source.pyx	/work/dirmy_working_pathfile.pyx	file1.pyx	file2.pyx	file3.pyxfoo.pyxbar.pyxT)ospathjoinunpatched_exists)r   s    eC:\Crop_Prediction\Backend\crop-ai-system\venv\Lib\site-packages\Cython/Compiler/Tests/TestCmdLine.pypatched_existsr      sY    
[,/
&5
 
 D!!    zos.path.exists)side_effect)newc                   d   e Zd Zd Zd Zg fdZg fdZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$d# Z%d$ Z&d% Z'd& Z(d' Z)d( Z*d) Z+d* Z,d+ Z-d, Z.d- Z/d. Z0d/ Z1d0 Z2d1 Z3d2 Z4d3 Z5d4 Z6d5 Z7d6 Z8d7 Z9d8 Z:y9):CmdLineParserTestc                 "    t               | _        y N)r   _options_backupselfs    r   setUpzCmdLineParserTest.setUp!   s    -/r   c                 .    t        | j                         y r$   )r   r%   r&   s    r   tearDownzCmdLineParserTest.tearDown$   s    ,,-r   c                 P    | j                  t        | j                  |      d       y )N )assertEqualr   r%   )r'   
white_lists     r   check_default_global_optionsz.CmdLineParserTest.check_default_global_options'   s!    -d.B.BJOQSTr   c                     t        j                  t         j                        }t               }|j                  j                         D ]3  }||vs| j                  t        |||      t        ||      d|z          5 y )Nzerror in option )msg)r   CompilationOptionsdefault_optionsobject__dict__keysr-   getattr)r'   optionsr.   r3   no_valuenames         r   check_default_optionsz'CmdLineParserTest.check_default_options*   s    !44W5L5LM8#,,113 	BD:%  $!A7?\`Cagy  }A  hA   B	Br   c                 6   t        g d      \  }}| j                  |       | j                  |j                         | j                  |j                         | j                  |j
                         | j                  |j                         | j                  |j                  dk\         | j                  t        j                         | j                  t        j                         | j                  t        j                         | j                  |j                  d       t        g d      \  }}| j                  |       | j                  t        |      dk(         | j                  |j                         | j                  |j                  d       y )N)-Vz-lz-+z-t-vr>   r>   z-pz-D-az-3   )z-fz-2r   r
   r   )r	   assertFalse
assertTrueshow_versionuse_listing_filecplus
timestampsverboser   embed_pos_in_docstring
docstringsannotater-   language_levellenr'   r8   sourcess      r   test_short_optionsz$CmdLineParserTest.test_short_options1   s0   - /
  	!,,-001&**+1,-667++,(()//3- /
  	 G)*++,//3r   c                    t        g d      \  }}| j                  |       | j                  |j                         | j                  |j                         | j                  |j
                         | j                  t        j                  d       | j                  |j                         | j                  |j                  dk\         | j                  t        j                         | j                  t        j                         | j                  t        j                         | j                  t        j                         | j                  t        j                         t        ddg      \  }}| j                  |       | j                  t!        |      dk(         | j                  |j                         y )N)z	--versionz--create-listingz--cplus--embed--timestamps	--verboserS   rS   z--embed-positionsz--no-docstrings
--annotatez	--lenientmainr@   z--forcer   r
   )r	   rA   rB   rC   rD   rE   r-   r   embedrF   rG   rH   rI   rJ   error_on_unknown_nameserror_on_uninitializedrL   rM   s      r   test_long_optionsz#CmdLineParserTest.test_long_optionsH   sE   - /
 
 	!,,-001&/**+1,-667++,(()778778-|/
  	 G)*++,r   c                    t        g d      \  }}| j                  |dg       | j                  t        j                  d       | j                  |j                  g d       | j                  |j
                  d       | j                  |j                  d       | j                  t        j                  d       | j                  t        j                  d       | j                  t        j                         | j                  t        j                  d	       | j                  |j                         | j                  |j                  d
       | j                  |j                  d   d       | j                  |j                  d       y )N)--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=falsez--shared=foo.sharedr   huhu)z/test/include/dir1z/test/include/dir2r\   r   z/output/dirz/pre/importr@   zcov.xmlz/gdb/outdir
wraparoundFz
foo.shared)r	   r-   r   rV   include_pathworking_pathoutput_file
pre_importgenerate_cleanup_coderB   rJ   annotate_coverage_xml	gdb_debug
output_dircompiler_directivesshared_utility_qualified_namerM   s      r   test_options_with_valuesz*CmdLineParserTest.test_options_with_valuesb   s.   - /
  	<.1/--/qr--{;,,m<++];66:(()66	B))*++];44\BEJ>>Mr   c                     t        ddg      \  }}| j                  |dg       | j                  t        j                  d       y )NrQ   r   rU   r	   r-   r   rV   rM   s      r   test_embed_before_positionalz.CmdLineParserTest.test_embed_before_positional   sD    -/
  	<.1/r   c                     t        g d      \  }}| j                  |dg       | j                  t        j                  d       y )N)rQ   r[   r   r   r]   rk   rM   s      r   test_two_embedsz!CmdLineParserTest.test_two_embeds   >    - /
  	<.1/r   c                     t        g d      \  }}| j                  |dg       | j                  t        j                  d       y )N)r[   rQ   r   r   rU   rk   rM   s      r   test_two_embeds2z"CmdLineParserTest.test_two_embeds2   ro   r   c                 b    t        ddg      \  }}| j                  t        j                         y )Nr[   r   )r	   rA   r   rJ   rM   s      r   test_no_annotatez"CmdLineParserTest.test_no_annotate   s1    -L/
  	))*r   c                 d    t        ddg      \  }}| j                  t        j                  d       y )Nr?   r   defaultr	   r-   r   rJ   rM   s      r   test_annotate_shortz%CmdLineParserTest.test_annotate_short   s4    -/
  	))95r   c                 d    t        ddg      \  }}| j                  t        j                  d       y )NrT   r   ru   rv   rM   s      r   test_annotate_longz$CmdLineParserTest.test_annotate_long   s4    -/
  	))95r   c                 d    t        ddg      \  }}| j                  t        j                  d       y )N--annotate-fullcr   fullcrv   rM   s      r   test_annotate_fullcz%CmdLineParserTest.test_annotate_fullc   s4    -/
  	))73r   c                     t        g d      \  }}| j                  |j                  d       | j                          | j	                  |dg       y )N)z-wr   r   r   r`   )r	   r-   r`   r/   r;   rM   s      r   test_short_wzCmdLineParserTest.test_short_w   sN    - /
  	--/@A))+""7^,<=r   c                     t        g d      \  }}| j                  |j                  d       | j                          | j	                  |dg       y )N)z-o	my_outputr   r   ra   )r	   r-   ra   r/   r;   rM   s      r   test_short_ozCmdLineParserTest.test_short_o   sL    - /
  	,,k:))+""7]O<r   c                     t        g d      \  }}| j                  t        j                  d       | j	                  dg       | j                  |       y )N)z-zmy_preimportr   r   rb   )r	   r-   r   rb   r/   r;   rM   s      r   test_short_zzCmdLineParserTest.test_short_z   sL    - /
  	++^<))<.9""7+r   c                     t        ddg      \  }}| j                  t        j                  d       | j	                  dg       | j                  |       y )Nz--convert-ranger   Tconvert_range)r	   r-   r   r   r/   r;   rM   s      r   test_convert_rangez$CmdLineParserTest.test_convert_range   sS    -/
  	..5))?*;<""7+r   c                     t        ddg      \  }}| j                  |j                  d       | j                          | j	                  |dg       y )Nz--line-directivesr   Temit_linenums)r	   r-   r   r/   r;   rM   s      r   test_line_directivesz&CmdLineParserTest.test_line_directives   sS    -/
  	..5))+""7_,=>r   c                     t        ddg      \  }}| j                  |j                  d       | j                          | j	                  |dg       y )Nz--no-c-in-tracebackr   Fc_line_in_traceback)r	   r-   r   r/   r;   rM   s      r   test_no_c_in_tracebackz(CmdLineParserTest.test_no_c_in_traceback   sT    -!/
  	44e<))+""7-B,CDr   c                     t        ddg      \  }}| j                  |j                  d       | j                  |j                  t        j
                         | j                          | j                  |ddg       y )N--gdbr   Tre   rf   r	   r-   re   rf   r   curdirr/   r;   rM   s      r   test_gdbzCmdLineParserTest.test_gdb   so    -/
  	**D1++RYY7))+""7[,,GHr   c                     t        ddg      \  }}| j                  |j                  d       | j                          | j	                  |dg       y )Nz--3strr   3rK   )r	   r-   rK   r/   r;   rM   s      r   	test_3strzCmdLineParserTest.test_3str   sT    -/
  	//5))+""7-=,>?r   c                     t        ddg      \  }}| j                  |j                  d       | j                          | j	                  |dg       y )Nz--capi-reexport-cincludesr   Tcapi_reexport_cincludes)r	   r-   r   r/   r;   rM   s      r   test_capi_reexport_cincludesz.CmdLineParserTest.test_capi_reexport_cincludes   sT    -'/
  	88$?))+""7-F,GHr   c                     t        ddg      \  }}| j                  t        j                  d       | j	                  dg       | j                  |       y )Nz--fast-failr   T	fast_fail)r	   r-   r   r   r/   r;   rM   s      r   test_fast_failz CmdLineParserTest.test_fast_fail  sR    -/
  	**D1));-8""7+r   c                     t        ddg      \  }}| j                  t        j                  d       | j	                  dg       | j                  |       y )Nz--cimport-from-pyxr   Tcimport_from_pyx)r	   r-   r   r   r/   r;   rM   s      r   test_cimport_from_pyxz'CmdLineParserTest.test_cimport_from_pyx  sT    - /
  	1148))+=*>?""7+r   c                     t        ddg      \  }}| j                  t        j                  d       | j	                  dg       | j                  |       y )Nz-Werrorr   Twarning_errorsr	   r-   r   r   r/   r;   rM   s      r   test_WerrorzCmdLineParserTest.test_Werror  sT    -/
  	//6))+;*<=""7+r   c                     t        ddg      \  }}| j                  t        j                  d       | j	                  dg       | j                  |       y )Nz--warning-errorsr   Tr   r   rM   s      r   test_warning_errorsz%CmdLineParserTest.test_warning_errors  sT    -/
  	//6))+;*<=""7+r   c                     t        ddg      \  }}| j                  |j                  t        j                         | j                          | j                  |dg       y )Nz-Wextrar   rg   r	   r-   rg   r   extra_warningsr/   r;   rM   s      r   test_WextrazCmdLineParserTest.test_Wextra(  sZ    -/
  	44g6L6LM))+""7-B,CDr   c                     t        ddg      \  }}| j                  |j                  t        j                         | j                          | j                  |dg       y )N--warning-extrar   rg   r   rM   s      r   test_warning_extraz$CmdLineParserTest.test_warning_extra1  sZ    -/
  	44g6L6LM))+""7-B,CDr   c                     t        ddg      \  }}| j                  t        j                  d       | j	                  dg       | j                  |       y )Nz--old-style-globalsr   Told_style_globals)r	   r-   r   r   r/   r;   rM   s      r   test_old_style_globalsz(CmdLineParserTest.test_old_style_globals:  sT    -!/
  	22D9))+>*?@""7+r   c                     t        g d      \  }}| j                  |j                  d   d       | j                  |j                  d   d       | j                          | j	                  |dg       y )N)-Xcdivision=Truer   c_string_type=bytesr   	cdivisionTc_string_typebytesrg   r	   r-   rg   r/   r;   r'   r8   sources      r   test_directive_multiplez)CmdLineParserTest.test_directive_multipleC  sm    , .
 
 	44[A4H44_EwO))+""7-B,CDr   c                     t        g d      \  }}| j                  |j                  d   d       | j                  |j                  d   d       | j                          | j	                  |dg       y )N)r   z"cdivision=True,c_string_type=bytesr   r   Tr   r   rg   r   r   s      r   test_directive_multiple_v2z,CmdLineParserTest.test_directive_multiple_v2N  sm    , .
  	44[A4H44_EwO))+""7-B,CDr   c                     t        g d      \  }}| j                  |j                  d   d       | j                          | j	                  |dg       y )N)r   zcdivision=YeSr   r   Trg   r   r   s      r   test_directive_value_yesz*CmdLineParserTest.test_directive_value_yesX  sR    , .
  	44[A4H))+""7-B,CDr   c                     t        g d      \  }}| j                  |j                  d   d       | j                          | j	                  |dg       y )N)r   zcdivision=nor   r   Frg   r   r   s      r   test_directive_value_noz)CmdLineParserTest.test_directive_value_noa  sR    , .
  	44[A5I))+""7-B,CDr   c                 >    | j                  t        t        g d       y )N)r   zcdivision=sadfasdr   assertRaises
ValueErrorr	   r&   s    r   test_directive_value_invalidz.CmdLineParserTest.test_directive_value_invalidj      *&8 ;
 	r   c                 >    | j                  t        t        g d       y )N)r   abracadabrar   r   r&   s    r   test_directive_key_invalidz,CmdLineParserTest.test_directive_key_invalidp  r   r   c                 >    | j                  t        t        g d       y )N)r   r   r   r   r&   s    r   test_directive_no_valuez)CmdLineParserTest.test_directive_no_valuev  r   r   c                     t        g d      \  }}| j                  |j                  d   d       | j                          | j	                  |dg       y )N)-E	MYSIZE=10r   MYSIZE
   compile_time_envr	   r-   r   r/   r;   r   s      r   test_compile_time_env_shortz-CmdLineParserTest.test_compile_time_env_short|  R    , .
  	11(;R@))+""7-?,@Ar   c                     t        g d      \  }}| j                  |j                  d   d       | j                          | j	                  |dg       y )N)z--compile-time-envr   r   r   r   r   r   r   s      r   test_compile_time_env_longz,CmdLineParserTest.test_compile_time_env_long  r   r   c                     t        g d      \  }}| j                  |j                  d   d       | j                  |j                  d   d       | j                          | j	                  |dg       y )N)r   r   r   z
ARRSIZE=11r   r   r   ARRSIZE   r   r   r   s      r   test_compile_time_env_multiplez0CmdLineParserTest.test_compile_time_env_multiple  m    , .
  	11(;R@11)<bA))+""7-?,@Ar   c                     t        g d      \  }}| j                  |j                  d   d       | j                  |j                  d   d       | j                          | j	                  |dg       y )N)r   zMYSIZE=10,ARRSIZE=11r   r   r   r   r   r   r   r   s      r   !test_compile_time_env_multiple_v2z3CmdLineParserTest.test_compile_time_env_multiple_v2  r   r   c                 J    t        ddg      \  }}| j                  |dg       y )Nr=   r   r	   r-   rM   s      r   test_option_firstz#CmdLineParserTest.test_option_first  s(    -tZ.@A:,/r   c                 J    t        g d      \  }}| j                  |dg       y )N)r=   r   r?   r   r   rM   s      r   test_file_inbetweenz%CmdLineParserTest.test_file_inbetween  s$    -.FG:,/r   c                 J    t        ddg      \  }}| j                  |dg       y )Nr   r=   r   rM   s      r   test_option_trailingz&CmdLineParserTest.test_option_trailing  s(    -z4.@A:,/r   c                 L    t        g d      \  }}| j                  |g d       y )N)r   r=   r   r?   r   )r   r   r   r   rM   s      r   test_multiple_filesz%CmdLineParserTest.test_multiple_files  s)    - /
 
 	"IJr   c                     t        g d      \  }}ddlm} dD ]-  }| j                  t	        ||      |dv        t        ||d       / y )N)z--debug-disposal-codez--debug-coercionr   r   )
DebugFlags)debug_disposal_codedebug_temp_allocdebug_coercion)r   r   )r	   Cython.Compilerr   r-   r7   setattr)r'   r8   rN   r   r:   s        r   test_debug_flagsz"CmdLineParserTest.test_debug_flags  sS    - /
  	/Q 	)DWZ6@i8ijJa(	)r   c                     t        g d      \  }}| j                  |j                  d       | j                  |j                  t        j
                         | j                          | j                  |ddg       y )N)--gdb-outdir=my_dirr   r   Tre   rf   r   rM   s      r   test_gdb_overwrites_gdb_outdirz0CmdLineParserTest.test_gdb_overwrites_gdb_outdir  si    - /
  	**D1++RYY7))+""7[,,GHr   c                     t        g d      \  }}| j                  |j                  d       | j                  |j                  d       | j	                          | j                  |ddg       y )N)r   r   r   Tmy_dirre   rf   )r	   r-   re   rf   r/   r;   rM   s      r   test_gdb_firstz CmdLineParserTest.test_gdb_first  se    - /
  	**D1++X6))+""7[,,GHr   c                     t        g d      \  }}| j                  t        j                  d       | j                  t        j                  d       | j                  ddg       | j                  |       y )N)r{   --annotate-coverage=my.xmlr   Tmy.xmlrJ   rd   r	   r-   r   rJ   rd   r/   r;   rM   s      r   #test_coverage_overwrites_annotationz5CmdLineParserTest.test_coverage_overwrites_annotation  sf    - /
  	))4066A)):7N*OP""7+r   c                     t        g d      \  }}| j                  t        j                  d       | j                  t        j                  d       | j                  ddg       | j                  |       y )N)r   r{   r   r|   r   rJ   rd   r   rM   s      r   test_coverage_firstz%CmdLineParserTest.test_coverage_first  sf    - /
  	))7366A)):7N*OP""7+r   c                     t        g d      \  }}| j                  t        j                  d       | j	                  dg       | j                  |       y )N)rT   r{   r   r|   rJ   r	   r-   r   rJ   r/   r;   rM   s      r    test_annotate_first_fullc_secondz2CmdLineParserTest.test_annotate_first_fullc_second  sL    - /
  	))73)):,7""7+r   c                     t        g d      \  }}| j                  t        j                  d       | j	                  dg       | j                  |       y )N)r{   rT   r   ru   rJ   r   rM   s      r   test_annotate_fullc_firstz+CmdLineParserTest.test_annotate_fullc_first  sL    - /
  	))95)):,7""7+r   c                     t        g d      \  }}| j                  t        |j                        t        t        j
                        dz          | j                          | j                  |dg       y )N)r   r   r   r   r   r   r
   rg   )r	   rB   rL   rg   r   r   r/   r;   rM   s      r   !test_warning_extra_dont_overwritez3CmdLineParserTest.test_warning_extra_dont_overwrite  sb    - /
  	G778#g>T>T:UXY:YZ))+""7-B,CDr   c                 :   t        dg      \  }}| j                  |j                  d        | j                          | j	                  |       t        g d      \  }}| j                  |j                  d       | j                          | j	                  |dg       y )Nr   )--module-namefoo.barr   r  module_name)r	   r-   r  r/   r;   rM   s      r   test_module_namez"CmdLineParserTest.test_module_name  s    -/
  	,,d3))+""7+- /
  	,,i8))+""7]O<r   c                 ~    t        dg      \  }}| j                  |g        | j                  |j                  d       y )Nz--generate-shared=foo/shared.czfoo/shared.c)r	   r-   shared_c_file_pathrM   s      r   test_generate_sharedz&CmdLineParserTest.test_generate_shared  sA    -,/
  	"%33^Dr   c                 6    d fd	} |dgd        |dgd        |dgd        |dgd	        |d
gd        |dgd        |dgd        |ddgd        |ddgd        |ddgd        |g dd        |g dd        |ddgd        |dgd       y ) Nc                    t         j                  }t               x}t         _        	 j                  t        t
        t        |              |t         _        |j                         }dj                  |j                               }j                  |j                  d      d|z         j                  d|v d|z         |r-j                  t        j                  ||      |d|d       y y # |t         _        w xY w)NzMessage "{}"zusage: z %s does not start with "usage :"z	: error: z%s does not contain ": error :"z does not match search "")sysstderrr   r   
SystemExitr	   listgetvalueformatstriprB   
startswithresearch)argsregex
old_stderrr  r1   err_msgr'   s         r   errorz,CmdLineParserTest.test_errors.<locals>.error  s    J"**,FSZ(!!*.@$t*M'
//#C$++CIIK8GOOCNN95>HJOOK3.=GI		% 5!(%!12  (
s   $C1 1C>z-1zunknown option -1z-Iz0argument -I/--include-dir: expected one argumentz--version=-az5argument -V/--version: ignored explicit argument '-a'z--version=--annotate=truezBargument -V/--version: ignored explicit argument '--annotate=true'z	--workingz,argument -w/--working: expected one argumentz--verbose=1z4argument -v/--verbose: ignored explicit argument '1'z	--cleanupz)argument --cleanup: expected one argumentz --debug-disposal-code-wrong-namer   z/unknown option --debug-disposal-code-wrong-namer  r   zNeed at least one source filer  )r  r  r   r   z5Only one source file allowed when using --module-name)r  r  rR   r   z*Cannot use --module-name with --timestampsz--generate-shared=shared.cz4Source file not allowed when using --generate-sharedz--generate-sharedz1argument --generate-shared: expected one argumentr$    )r'   r  s   ` r   test_errorszCmdLineParserTest.test_errors  s    	2$ 	tf!	#tf@	B~E	G*+"	# 	{m<	>}oD	F{m9	;1;??	A	*-	/	*-	/@E	GE:	<+Y7D	F"#A	Cr   N);__name__
__module____qualname__r(   r*   r/   r;   rO   rY   ri   rl   rn   rq   rs   rw   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   r   r  r  r
  r  r  r   r   r"   r"      s;   0. 79 U 9; B4.-4N:000+664>=,,?EI@I,,,,EE,	EEEEBBBB000K)II,,,,	E=E/Cr   r"   )r   r  r  ior   unittestr   unittest.mockr   r   r,   r   CmdLiner	   Utilsr   r   r   r   existsr   r   r"   r  r   r   <module>r(     sd    	 
 	   %  ( H H77>> "  Tn=>jC jC ?jCr   