
    hV                         S SK r S SKrS SKrS SKJr  S SKJr  S SKJrJ	r	  SSK
Jr  SSKJr  SS	KJrJrJr  \ R$                  R&                  rS
 r\" S\	" \S9S9 " S S\5      5       rg)    N)StringIO)TestCase)patchMock   )Options)parse_command_line   )backup_Optionsrestore_Optionscheck_global_optionsc           
          U S[         R                  R                  SS5      [         R                  R                  SS5      SSSSSS	4	;   a  g
[        U 5      $ )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    [/var/www/fran/franai/venv/lib/python3.13/site-packages/Cython/Compiler/Tests/TestCmdLine.pypatched_existsr      sY    
[,/
&5
 
 D!!    zos.path.exists)side_effect)newc                   p   \ rS rSrS rS r/ 4S jr/ 4S jrS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS r S r!S  r"S! r#S" r$S# r%S$ r&S% r'S& r(S' r)S( r*S) r+S* r,S+ r-S, r.S- r/S. r0S/ r1S0 r2S1 r3S2 r4S3 r5S4 r6S5 r7S6 r8S7 r9S8 r:S9 r;S:r<g;)<CmdLineParserTest   c                 "    [        5       U l        g N)r   _options_backupselfs    r   setUpCmdLineParserTest.setUp!   s    -/r   c                 .    [        U R                  5        g r%   )r   r&   r'   s    r   tearDownCmdLineParserTest.tearDown$   s    ,,-r   c                 P    U R                  [        U R                  U5      S5        g )N )assertEqualr   r&   )r(   
white_lists     r   check_default_global_options.CmdLineParserTest.check_default_global_options'   s!    -d.B.BJOQSTr   c                     [         R                  " [         R                  5      n[        5       nUR                  R                  5        H1  nXR;  d  M
  U R                  [        XU5      [        X55      SU-   S9  M3     g )Nzerror in option )msg)r   CompilationOptionsdefault_optionsobject__dict__keysr0   getattr)r(   optionsr1   r7   no_valuenames         r   check_default_options'CmdLineParserTest.check_default_options*   sq    !44W5L5LM8#,,113D%  !A7?Cagy  }A  hA   B 4r   c                 2   [        / SQ5      u  pU R                  U5        U R                  UR                  5        U R                  UR                  5        U R                  UR
                  5        U R                  UR                  5        U R                  UR                  S:  5        U R                  [        R                  5        U R                  [        R                  5        U R                  [        R                  5        U R                  UR                  S5        [        / SQ5      u  pU R                  U5        U R                  [        U5      S:H  5        U R                  UR                  5        U R                  UR                  S5        g )N)-Vz-lz-+z-t-vrC   rC   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annotater0   language_levellenr(   r<   sourcess      r   test_short_options$CmdLineParserTest.test_short_options1   s,   - /
  	!,,-001&**+1,-667++,(()//3- /
  	 G)*++,//3r   c                 ~   [        / SQ5      u  pU R                  U5        U R                  UR                  5        U R                  UR                  5        U R                  UR
                  5        U R                  [        R                  S5        U R                  UR                  5        U R                  UR                  S:  5        U R                  [        R                  5        U R                  [        R                  5        U R                  [        R                  5        U R                  [        R                  5        U R                  [        R                  5        [        SS/5      u  pU R                  U5        U R                  [!        U5      S:H  5        U R                  UR                  5        g )N)z	--versionz--create-listingz--cplus--embed--timestamps	--verboserY   rY   z--embed-positionsz--no-docstrings
--annotatez	--lenientmainrE   z--forcer   r
   )r	   rF   rG   rH   rI   rJ   r0   r   embedrK   rL   rM   rN   rO   error_on_unknown_nameserror_on_uninitializedrQ   rR   s      r   test_long_options#CmdLineParserTest.test_long_optionsH   sA   - /
 
 	!,,-001&/**+1,-667++,(()778778-|/
  	 G)*++,r   c                    [        / SQ5      u  pU R                  US/5        U R                  [        R                  S5        U R                  UR                  / SQ5        U R                  UR
                  S5        U R                  UR                  S5        U R                  [        R                  S5        U R                  [        R                  S5        U R                  [        R                  5        U R                  [        R                  S	5        U R                  UR                  5        U R                  UR                  S
5        U R                  UR                  S   S5        U R                  UR                  S5        g )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/dir2rc   r   z/output/dirz/pre/importrE   zcov.xmlz/gdb/outdir
wraparoundFz
foo.shared)r	   r0   r   r\   include_pathworking_pathoutput_file
pre_importgenerate_cleanup_coderG   rO   annotate_coverage_xml	gdb_debug
output_dircompiler_directivesshared_utility_qualified_namerR   s      r   test_options_with_values*CmdLineParserTest.test_options_with_valuesb   s,   - /
  	<.1/--/qr--{;,,m<++];66:(()66	B))*++];44\BEJ>>Mr   c                     [        SS/5      u  pU R                  US/5        U R                  [        R                  S5        g )NrW   r   r[   r	   r0   r   r\   rR   s      r   test_embed_before_positional.CmdLineParserTest.test_embed_before_positional   sB    -/
  	<.1/r   c                     [        / SQ5      u  pU R                  US/5        U R                  [        R                  S5        g )N)rW   rb   r   r   rd   rs   rR   s      r   test_two_embeds!CmdLineParserTest.test_two_embeds   <    - /
  	<.1/r   c                     [        / SQ5      u  pU R                  US/5        U R                  [        R                  S5        g )N)rb   rW   r   r   r[   rs   rR   s      r   test_two_embeds2"CmdLineParserTest.test_two_embeds2   ry   r   c                 `    [        SS/5      u  pU R                  [        R                  5        g )Nrb   r   )r	   rF   r   rO   rR   s      r   test_no_annotate"CmdLineParserTest.test_no_annotate   s/    -L/
  	))*r   c                 b    [        SS/5      u  pU R                  [        R                  S5        g )NrD   r   defaultr	   r0   r   rO   rR   s      r   test_annotate_short%CmdLineParserTest.test_annotate_short   s2    -/
  	))95r   c                 b    [        SS/5      u  pU R                  [        R                  S5        g )NrZ   r   r   r   rR   s      r   test_annotate_long$CmdLineParserTest.test_annotate_long   s2    -/
  	))95r   c                 b    [        SS/5      u  pU R                  [        R                  S5        g )N--annotate-fullcr   fullcr   rR   s      r   test_annotate_fullc%CmdLineParserTest.test_annotate_fullc   s2    -/
  	))73r   c                     [        / SQ5      u  pU R                  UR                  S5        U R                  5         U R	                  US/5        g )N)z-wr   r   r   rg   )r	   r0   rg   r2   r?   rR   s      r   test_short_wCmdLineParserTest.test_short_w   sL    - /
  	--/@A))+""7^,<=r   c                     [        / SQ5      u  pU R                  UR                  S5        U R                  5         U R	                  US/5        g )N)z-o	my_outputr   r   rh   )r	   r0   rh   r2   r?   rR   s      r   test_short_oCmdLineParserTest.test_short_o   sJ    - /
  	,,k:))+""7]O<r   c                     [        / SQ5      u  pU R                  [        R                  S5        U R	                  S/5        U R                  U5        g )N)z-zmy_preimportr   r   ri   )r	   r0   r   ri   r2   r?   rR   s      r   test_short_zCmdLineParserTest.test_short_z   sJ    - /
  	++^<))<.9""7+r   c                     [        SS/5      u  pU R                  [        R                  S5        U R	                  S/5        U R                  U5        g )Nz--convert-ranger   Tconvert_range)r	   r0   r   r   r2   r?   rR   s      r   test_convert_range$CmdLineParserTest.test_convert_range   sQ    -/
  	..5))?*;<""7+r   c                     [        SS/5      u  pU R                  UR                  S5        U R                  5         U R	                  US/5        g )Nz--line-directivesr   Temit_linenums)r	   r0   r   r2   r?   rR   s      r   test_line_directives&CmdLineParserTest.test_line_directives   sQ    -/
  	..5))+""7_,=>r   c                     [        SS/5      u  pU R                  UR                  S5        U R                  5         U R	                  US/5        g )Nz--no-c-in-tracebackr   Fc_line_in_traceback)r	   r0   r   r2   r?   rR   s      r   test_no_c_in_traceback(CmdLineParserTest.test_no_c_in_traceback   sR    -!/
  	44e<))+""7-B,CDr   c                     [        SS/5      u  pU R                  UR                  S5        U R                  UR                  [        R
                  5        U R                  5         U R                  USS/5        g )N--gdbr   Trl   rm   r	   r0   rl   rm   r   curdirr2   r?   rR   s      r   test_gdbCmdLineParserTest.test_gdb   sm    -/
  	**D1++RYY7))+""7[,,GHr   c                     [        SS/5      u  pU R                  UR                  S5        U R                  5         U R	                  US/5        g )Nz--3strr   3rP   )r	   r0   rP   r2   r?   rR   s      r   	test_3strCmdLineParserTest.test_3str   sR    -/
  	//5))+""7-=,>?r   c                     [        SS/5      u  pU R                  UR                  S5        U R                  5         U R	                  US/5        g )Nz--capi-reexport-cincludesr   Tcapi_reexport_cincludes)r	   r0   r   r2   r?   rR   s      r   test_capi_reexport_cincludes.CmdLineParserTest.test_capi_reexport_cincludes   sR    -'/
  	88$?))+""7-F,GHr   c                     [        SS/5      u  pU R                  [        R                  S5        U R	                  S/5        U R                  U5        g )Nz--fast-failr   T	fast_fail)r	   r0   r   r   r2   r?   rR   s      r   test_fast_fail CmdLineParserTest.test_fast_fail  sP    -/
  	**D1));-8""7+r   c                     [        SS/5      u  pU R                  [        R                  S5        U R	                  S/5        U R                  U5        g )Nz--cimport-from-pyxr   Tcimport_from_pyx)r	   r0   r   r   r2   r?   rR   s      r   test_cimport_from_pyx'CmdLineParserTest.test_cimport_from_pyx  sR    - /
  	1148))+=*>?""7+r   c                     [        SS/5      u  pU R                  [        R                  S5        U R	                  S/5        U R                  U5        g )Nz-Werrorr   Twarning_errorsr	   r0   r   r   r2   r?   rR   s      r   test_WerrorCmdLineParserTest.test_Werror  sR    -/
  	//6))+;*<=""7+r   c                     [        SS/5      u  pU R                  [        R                  S5        U R	                  S/5        U R                  U5        g )Nz--warning-errorsr   Tr   r   rR   s      r   test_warning_errors%CmdLineParserTest.test_warning_errors  sR    -/
  	//6))+;*<=""7+r   c                     [        SS/5      u  pU R                  UR                  [        R                  5        U R                  5         U R                  US/5        g )Nz-Wextrar   rn   r	   r0   rn   r   extra_warningsr2   r?   rR   s      r   test_WextraCmdLineParserTest.test_Wextra(  sX    -/
  	44g6L6LM))+""7-B,CDr   c                     [        SS/5      u  pU R                  UR                  [        R                  5        U R                  5         U R                  US/5        g )N--warning-extrar   rn   r   rR   s      r   test_warning_extra$CmdLineParserTest.test_warning_extra1  sX    -/
  	44g6L6LM))+""7-B,CDr   c                     [        SS/5      u  pU R                  [        R                  S5        U R	                  S/5        U R                  U5        g )Nz--old-style-globalsr   Told_style_globals)r	   r0   r   r   r2   r?   rR   s      r   test_old_style_globals(CmdLineParserTest.test_old_style_globals:  sR    -!/
  	22D9))+>*?@""7+r   c                     [        / SQ5      u  pU R                  UR                  S   S5        U R                  UR                  S   S5        U R                  5         U R	                  US/5        g )N)-Xcdivision=Truer   c_string_type=bytesr   	cdivisionTc_string_typebytesrn   r	   r0   rn   r2   r?   r(   r<   sources      r   test_directive_multiple)CmdLineParserTest.test_directive_multipleC  sk    , .
 
 	44[A4H44_EwO))+""7-B,CDr   c                     [        / SQ5      u  pU R                  UR                  S   S5        U R                  UR                  S   S5        U R                  5         U R	                  US/5        g )N)r   z"cdivision=True,c_string_type=bytesr   r   Tr   r   rn   r   r   s      r   test_directive_multiple_v2,CmdLineParserTest.test_directive_multiple_v2N  sk    , .
  	44[A4H44_EwO))+""7-B,CDr   c                     [        / SQ5      u  pU R                  UR                  S   S5        U R                  5         U R	                  US/5        g )N)r   zcdivision=YeSr   r   Trn   r   r   s      r   test_directive_value_yes*CmdLineParserTest.test_directive_value_yesX  sP    , .
  	44[A4H))+""7-B,CDr   c                     [        / SQ5      u  pU R                  UR                  S   S5        U R                  5         U R	                  US/5        g )N)r   zcdivision=nor   r   Frn   r   r   s      r   test_directive_value_no)CmdLineParserTest.test_directive_value_noa  sP    , .
  	44[A5I))+""7-B,CDr   c                 >    U R                  [        [        / SQ5        g )N)r   zcdivision=sadfasdr   assertRaises
ValueErrorr	   r'   s    r   test_directive_value_invalid.CmdLineParserTest.test_directive_value_invalidj      *&8 ;
 	r   c                 >    U R                  [        [        / SQ5        g )N)r   abracadabrar   r   r'   s    r   test_directive_key_invalid,CmdLineParserTest.test_directive_key_invalidp  r   r   c                 >    U R                  [        [        / SQ5        g )N)r   r   r   r   r'   s    r   test_directive_no_value)CmdLineParserTest.test_directive_no_valuev  r   r   c                     [        / SQ5      u  pU R                  UR                  S   S5        U R                  5         U R	                  US/5        g )N)-E	MYSIZE=10r   MYSIZE
   compile_time_envr	   r0   r   r2   r?   r   s      r   test_compile_time_env_short-CmdLineParserTest.test_compile_time_env_short|  P    , .
  	11(;R@))+""7-?,@Ar   c                     [        / SQ5      u  pU R                  UR                  S   S5        U R                  5         U R	                  US/5        g )N)z--compile-time-envr   r   r   r   r   r   r   s      r   test_compile_time_env_long,CmdLineParserTest.test_compile_time_env_long  r   r   c                     [        / SQ5      u  pU R                  UR                  S   S5        U R                  UR                  S   S5        U R                  5         U R	                  US/5        g )N)r   r   r   z
ARRSIZE=11r   r   r   ARRSIZE   r   r   r   s      r   test_compile_time_env_multiple0CmdLineParserTest.test_compile_time_env_multiple  k    , .
  	11(;R@11)<bA))+""7-?,@Ar   c                     [        / SQ5      u  pU R                  UR                  S   S5        U R                  UR                  S   S5        U R                  5         U R	                  US/5        g )N)r   zMYSIZE=10,ARRSIZE=11r   r   r   r   r  r   r   r   s      r   !test_compile_time_env_multiple_v23CmdLineParserTest.test_compile_time_env_multiple_v2  r  r   c                 H    [        SS/5      u  pU R                  US/5        g )NrB   r   r	   r0   rR   s      r   test_option_first#CmdLineParserTest.test_option_first  s&    -tZ.@A:,/r   c                 H    [        / SQ5      u  pU R                  US/5        g )N)rB   r   rD   r   r	  rR   s      r   test_file_inbetween%CmdLineParserTest.test_file_inbetween  s"    -.FG:,/r   c                 H    [        SS/5      u  pU R                  US/5        g )Nr   rB   r	  rR   s      r   test_option_trailing&CmdLineParserTest.test_option_trailing  s&    -z4.@A:,/r   c                 J    [        / SQ5      u  pU R                  U/ SQ5        g )N)r   rB   r   rD   r   )r   r   r   r	  rR   s      r   test_multiple_files%CmdLineParserTest.test_multiple_files  s'    - /
 
 	"IJr   c                     [        / SQ5      u  pSSKJn  S H-  nU R                  [	        X45      US;   5        [        X4S5        M/     g )N)z--debug-disposal-codez--debug-coercionr   r   )
DebugFlags)debug_disposal_codedebug_temp_allocdebug_coercion)r  r  )r	   Cython.Compilerr  r0   r;   setattr)r(   r<   rS   r  r>   s        r   test_debug_flags"CmdLineParserTest.test_debug_flags  sI    - /
  	/QDWZ6@i8ijJa( Rr   c                     [        / SQ5      u  pU R                  UR                  S5        U R                  UR                  [        R
                  5        U R                  5         U R                  USS/5        g )N)--gdb-outdir=my_dirr   r   Trl   rm   r   rR   s      r   test_gdb_overwrites_gdb_outdir0CmdLineParserTest.test_gdb_overwrites_gdb_outdir  sg    - /
  	**D1++RYY7))+""7[,,GHr   c                     [        / SQ5      u  pU R                  UR                  S5        U R                  UR                  S5        U R	                  5         U R                  USS/5        g )N)r   r  r   Tmy_dirrl   rm   )r	   r0   rl   rm   r2   r?   rR   s      r   test_gdb_first CmdLineParserTest.test_gdb_first  sc    - /
  	**D1++X6))+""7[,,GHr   c                     [        / SQ5      u  pU R                  [        R                  S5        U R                  [        R                  S5        U R                  SS/5        U R                  U5        g )N)r   --annotate-coverage=my.xmlr   Tmy.xmlrO   rk   r	   r0   r   rO   rk   r2   r?   rR   s      r   #test_coverage_overwrites_annotation5CmdLineParserTest.test_coverage_overwrites_annotation  sd    - /
  	))4066A)):7N*OP""7+r   c                     [        / SQ5      u  pU R                  [        R                  S5        U R                  [        R                  S5        U R                  SS/5        U R                  U5        g )N)r'  r   r   r   r(  rO   rk   r)  rR   s      r   test_coverage_first%CmdLineParserTest.test_coverage_first  sd    - /
  	))7366A)):7N*OP""7+r   c                     [        / SQ5      u  pU R                  [        R                  S5        U R	                  S/5        U R                  U5        g )N)rZ   r   r   r   rO   r	   r0   r   rO   r2   r?   rR   s      r    test_annotate_first_fullc_second2CmdLineParserTest.test_annotate_first_fullc_second  sJ    - /
  	))73)):,7""7+r   c                     [        / SQ5      u  pU R                  [        R                  S5        U R	                  S/5        U R                  U5        g )N)r   rZ   r   r   rO   r0  rR   s      r   test_annotate_fullc_first+CmdLineParserTest.test_annotate_fullc_first  sJ    - /
  	))95)):,7""7+r   c                     [        / SQ5      u  pU R                  [        UR                  5      [        [        R
                  5      S-   5        U R                  5         U R                  US/5        g )N)r   r   r   r   r   r   r
   rn   )r	   rG   rQ   rn   r   r   r2   r?   rR   s      r   !test_warning_extra_dont_overwrite3CmdLineParserTest.test_warning_extra_dont_overwrite  s`    - /
  	G778#g>T>T:UXY:YZ))+""7-B,CDr   c                 6   [        S/5      u  pU R                  UR                  S 5        U R                  5         U R	                  U5        [        / SQ5      u  pU R                  UR                  S5        U R                  5         U R	                  US/5        g )Nr   )--module-namefoo.barr   r;  module_name)r	   r0   r<  r2   r?   rR   s      r   test_module_name"CmdLineParserTest.test_module_name  s    -/
  	,,d3))+""7+- /
  	,,i8))+""7]O<r   c                 |    [        S/5      u  pU R                  U/ 5        U R                  UR                  S5        g )Nz--generate-shared=foo/shared.czfoo/shared.c)r	   r0   shared_c_file_pathrR   s      r   test_generate_shared&CmdLineParserTest.test_generate_shared  s?    -,/
  	"%33^Dr   c                 :  ^  SU 4S jjnU" S/S5        U" S/S5        U" S/S5        U" S/S	5        U" S
/S5        U" S/S5        U" S/S5        U" SS/S5        U" SS/S5        U" SS/S5        U" / SQS5        U" / SQS5        U" SS/S5        U" S/S5        g ) Nc                   > [         R                  n[        5       =n[         l         TR                  [        [
        [        U 5      5        U[         l        UR                  5       nSR                  UR                  5       5      nTR                  UR                  S5      SU-  5        TR                  SU;   SU-  5        U(       a/  TR                  [        R                  " X5      U< SU< S35        g g ! U[         l        f = f)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striprG   
startswithresearch)argsregex
old_stderrrG  r5   err_msgr(   s         r   error,CmdLineParserTest.test_errors.<locals>.error  s    J"**,FSZ(!!*.@$t*M'
//#C$++CIIK8GOOCNN95>HJOOK3.=GI		% 5!(%!12  (
s   $C9 9D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;  rX   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(   rT  s   ` r   test_errors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   )r&   N)=__name__
__module____qualname____firstlineno__r)   r,   r2   r?   rT   r_   rp   rt   rw   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-  r1  r4  r7  r=  rA  rW  __static_attributes__rV  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   rF  rN  ior   unittestr   unittest.mockr   r   r/   r   CmdLiner	   Utilsr   r   r   r   existsr   r   r"   rV  r   r   <module>rd     sd    	 
 	   %  ( H H77>> "  Tn=>jC jC ?jCr   