
    6bhU                    R   d dl mZ d dlmZ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Zd dlZd dlZd dlZd dlZd dlZ ej(                  d        ej*                  d      5  d dlZd d	lmZ ddd       d
 Zd Z G d de      Z G d d      Z G d d      Z G d d      Z ej<                  dd      Z G d d      Z  G d de      Z! G d de      Z" G d de      Z# G d d       Z$ G d! d"      Z% G d# d$e      Z& G d% d&e      Z' G d' d(e      Z(	 d dl)Z* ejX                  e*du d)       G d* d+ej                               Z- G d, d-ej                        Z. G d. d/ej                        Z/e0d0k(  r ejb                          yy# 1 sw Y   !xY w# e+$ r dZ*Y w xY w)1    )partial)support
test_tools)	os_helper)TESTFNunlink)dedent)TestCaseNclinic)	DSLParserc                 F    | j                          | j                  |       y N)clearupdate)
convertersold_converterss     :/opt/python-3.12.12/usr/lib/python3.12/test/test_clinic.pyrestore_dictr      s    n%    c                    | j                  t        t        j                  t        j                  j	                                | j                  t        t        j
                  t        j
                  j	                                | j                  t        t        j                  t        j                  j	                                y r   )
addCleanupr   r   r   copylegacy_convertersreturn_converters)testcases    r   save_restore_convertersr      s    f&7&7))..02f&>&>005579f&>&>005579r   c                       e Zd ZdZd Zd Zy)_ParserBaseNc                     t        j                         5 }| j                  t              5   ||       d d d        d d d        |j	                         S # 1 sw Y   !xY w# 1 sw Y   j	                         S xY wr   )r   captured_stdoutassertRaises
SystemExitgetvalue)selfparser_inputstdouts       r   expect_parser_failurez!_ParserBase.expect_parser_failure)   s\    $$&&"":.v / '    /. '   s!   A 	AA A	A  A8c                 :    | j                  | j                  |      S r   )r(   parse_function)r$   r&   s     r   parse_function_should_failz&_ParserBase.parse_function_should_fail/   s    ))$*=*=vFFr   )__name__
__module____qualname__maxDiffr(   r+    r   r   r   r   &   s    G!Gr   r   c                       e Zd Zd Zy)FakeConverterc                      || _         || _        y r   )nameargsr$   r4   r5   s      r   __init__zFakeConverter.__init__4   s    		r   N)r,   r-   r.   r7   r0   r   r   r2   r2   3   s    r   r2   c                       e Zd Zd Zd Zy)FakeConverterFactoryc                     || _         y r   r4   r$   r4   s     r   r7   zFakeConverterFactory.__init__:   s	    	r   c                 .    t        | j                  |      S r   )r2   r4   )r$   r4   defaultkwargss       r   __call__zFakeConverterFactory.__call__=   s    TYY//r   N)r,   r-   r.   r7   r@   r0   r   r   r9   r9   9   s    0r   r9   c                       e Zd Zd Zd Zy)FakeConvertersDictc                     i | _         y r   )used_convertersr$   s    r   r7   zFakeConvertersDict.__init__B   s
    !r   c                 L    | j                   j                  |t        |            S r   )rD   
setdefaultr9   )r$   r4   r>   s      r   getzFakeConvertersDict.getE   s!    ##..t5I$5OPPr   N)r,   r-   r.   r7   rH   r0   r   r   rB   rB   A   s    "Qr   rB   Cfile)languagefilenamec                   V    e Zd Zd Zd Zd Zd Zd Zej                  j                  Z
y)
FakeClinicc                    t               | _        t               | _        t        j                  d       | _        d | _        i | _        t        j                  d| j
                        | _	        t        j                         | _        t        j                         | _        | t        _        d| _        dx| _        | _        i | _        | j%                  dd       | j%                  dd       | j%                  dd       | j"                  j&                  }t        j                  d |d      fd |d      fd	 |d      fd
 |d      fd |d      fd |d      fd |d      ff      | _        y )N rN   blockbufferrJ   suppressdocstring_prototypedocstring_definitionmethoddef_defineimpl_prototypeparser_prototypeparser_definitionimpl_definition)rB   r   r   r   	CLanguagerK   rL   destination_buffersBlockParserblock_parsercollectionsOrderedDictmodulesclassesr4   line_prefixline_suffixdestinationsadd_destinationrH   field_destinations)r$   ds     r   r7   zFakeClinic.__init__K   sD   ,.!3!5((.#% "..r4==A"..0"..0 	.004+Wh/VX.Z4!!"-"9"9"AjM2#QwZ07,qz*:/ !G*-'
+;
 #r   c                     | j                   j                  |      }|s!t        j                  dt	        |      z          |S )NzDestination does not exist: )re   rH   sysexitrepr)r$   r4   rh   s      r   get_destinationzFakeClinic.get_destinationf   s6    !!$'HH3d4j@Ar   c                     || j                   v r!t        j                  dt        |      z          t	        j
                  ||| g| | j                   |<   y )NzDestination already exists: )re   rj   rk   rl   r   Destination)r$   r4   typer5   s       r   rf   zFakeClinic.add_destinationl   sJ    4$$$HH3d4j@A"("4"4T4"M"M$r   c                     |dk(  S )Nmoduler0   r<   s     r   is_directivezFakeClinic.is_directiveq   s    xr   c                 "    || j                   |<   y r   )called_directivesr6   s      r   	directivezFakeClinic.directivet   s    '+t$r   N)r,   r-   r.   r7   rm   rf   rs   rv   r   Clinic_module_and_classr0   r   r   rN   rN   J   s.    6N
 , 77r   rN   c                   r    e 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y)ClinicWholeFileTestc                 x    t        |        t        j                  t        j                  d       d      | _        y )Ntest.crL   )r   r   rw   r[   rE   s    r   setUpzClinicWholeFileTest.setUp{   s'    %mmF$4$4T$:XNr   c                     t        |      j                         }| j                  | j                  j                  |      S r   )r	   stripr(   r   parse)r$   rawr&   s      r   expect_failurez"ClinicWholeFileTest.expect_failure   s1    ""$))$++*;*;VDDr   c                     d}| j                   j                  |      j                         }|d   j                         }| j	                  |d       | j                  |d       y )Nz/*[clinic]
foo
[clinic]*/   z[clinic]*/[clinic]*/z
[clinic]*/)r   r   
splitlinesrstripassertNotEqualassertEqual)r$   r   cookedend_lines       r   test_eolzClinicWholeFileTest.test_eol   s[     ,""3'224!9##% 	H&<=<0r   c                 R    d}d}| j                  |      }| j                  ||       y )Nz
            /*[clinic input]
            [clinic start generated code]*/
            /*[clinic end generated code: foo]*/
        znError in file "test.c" on line 3:
Mangled Argument Clinic marker line: '/*[clinic end generated code: foo]*/'
r   r   r$   r   msgouts       r   test_mangled_marker_linez,ClinicWholeFileTest.test_mangled_marker_line   s6    \ 	 !!#&c"r   c                 R    d}d}| j                  |      }| j                  ||       y )Nz
            /*[clinic input]
            [clinic start generated code]*/
            /*[clinic end generated code: output=0123456789abcdef input=fedcba9876543210]*/
        zkError in file "test.c" on line 3:
Checksum mismatch!
Expected: 0123456789abcdef
Computed: da39a3ee5e6b4b0d
r   assertInr   s       r   test_checksum_mismatchz*ClinicWholeFileTest.test_checksum_mismatch   s3    + 	 !!#&c3r   c                 R    d}d}| j                  |      }| j                  ||       y )Nz_
            /*[clinic input]
            [clinic start generated code]*/foobarfoobar!
        zKError in file "test.c" on line 2:
Garbage after stop line: 'foobarfoobar!'
r   r   s       r   test_garbage_after_stop_linez0ClinicWholeFileTest.test_garbage_after_stop_line   s5    
9 	 !!#&c"r   c                 R    d}d}| j                  |      }| j                  ||       y )NzS
            /*[clinic input]
             [clinic start generated code]*/
        zuError in file "test.c" on line 2:
Whitespace is not allowed before the stop line: ' [clinic start generated code]*/'
r   r   s       r    test_whitespace_before_stop_linez4ClinicWholeFileTest.test_whitespace_before_stop_line   s6    
c 	 !!#&c"r   c                 0   t        j                  d       }d|_        d|_        d|_        t        j
                  |d      }t        d      j                         }|j                  |      }t        d      j                         }| j                  ||       y )Nz//z//[{dsl_name} start]z//[{dsl_name} stop]r|   r}   z\
            //[clinic start]
            //module test
            //[clinic stop]
        z
            //[clinic start]
            //module test
            //
            //[clinic stop]
            /*[clinic end generated code: output=da39a3ee5e6b4b0d input=65fab8adff58cf08]*/
        )r   r[   body_prefix
start_line	stop_linerw   r	   r   r   lstripr   )r$   clangclr   r   expecteds         r   test_parse_with_body_prefixz/ClinicWholeFileTest.test_parse_with_body_prefix   s      & 1/]]584   UW	 	
 hhsm   VX 	 	h'r   c                 R    d}d}| j                  |      }| j                  ||       y )NzR
            /* start
            /* nested
            */
            */
        z8Error in file "test.c" on line 2:
Nested block comment!
r   r   s       r   *test_cpp_monitor_fail_nested_block_commentz>ClinicWholeFileTest.test_cpp_monitor_fail_nested_block_comment   s5    & 	 !!#&c"r   c                 R    d}d}| j                  |      }| j                  ||       y )Nz<
            #if
            a()
            #endif
        zLError in file "test.c" on line 1:
Invalid format for #if line: no argument!
r   r   s       r   *test_cpp_monitor_fail_invalid_format_noargz>ClinicWholeFileTest.test_cpp_monitor_fail_invalid_format_noarg   s5    : 	 !!#&c"r   c                 R    d}d}| j                  |      }| j                  ||       y )NzC
            #ifdef A B
            a()
            #endif
        zbError in file "test.c" on line 1:
Invalid format for #ifdef line: should be exactly one argument!
r   r   s       r   0test_cpp_monitor_fail_invalid_format_toomanyargszDClinicWholeFileTest.test_cpp_monitor_fail_invalid_format_toomanyargs   s6    P 	 !!#&c"r   c                 R    d}d}| j                  |      }| j                  ||       y )Nz#elsezQError in file "test.c" on line 1:
#else without matching #if / #ifdef / #ifndef!
r   r   s       r   $test_cpp_monitor_fail_no_matching_ifz8ClinicWholeFileTest.test_cpp_monitor_fail_no_matching_if  s3    ? 	 !!#&c"r   c                 N    | j                  d      }d}| j                  ||       y )Nzy
            /*[clinic input]
            output preset nosuchpreset
            [clinic start generated code]*/
        zUnknown preset 'nosuchpreset'r   r$   r   r   s      r   $test_directive_output_unknown_presetz8ClinicWholeFileTest.test_directive_output_unknown_preset  s,    !! # 
 .c3r   c                 N    | j                  d      }d}| j                  ||       y )Nzi
            /*[clinic input]
            output pop
            [clinic start generated code]*/
        z"Can't 'output pop', stack is emptyr   r   s      r   test_directive_output_cant_popz2ClinicWholeFileTest.test_directive_output_cant_pop  s,    !! # 
 3c3r   c                    t        d      }| j                  j                  |      }| j                  |j	                  t        d                   h d}|D ]/  }| j                  |      5  | j                  ||       d d d        1 |j                         j                  d      d   }| j                  |j	                  d             y # 1 sw Y   ~xY w)Nz~
            /*[clinic input]
            output print 'I told you once.'
            [clinic start generated code]*/
        >
   cpp_if	cpp_endifrW   rZ   rV   methoddef_ifndefrX   rY   rT   rU   )field
z%/*[clinic end generated code: output=)	r	   r   r   
assertTrue
startswithsubTestr   r   split)r$   r   r   fieldsr   	last_lines         r   test_directive_output_printz/ClinicWholeFileTest.test_directive_output_print   s      
 kk$ 	v / (  	

 EE*eS) +*  JJL&&t,R0	  !HI	
 +*s   +CC	c                 N    | j                  d      }d}| j                  ||       y )Nz
            /*[clinic input]
            destination buffer nosuchcommand
            [clinic start generated code]*/
        z+unknown destination command 'nosuchcommand'r   r   s      r    test_unknown_destination_commandz4ClinicWholeFileTest.test_unknown_destination_commandC  s,    !! # 
 <c3r   c                 N    | j                  d      }d}| j                  ||       y )Na  
            /*[python input]
            class Custom_converter(CConverter):
                converter = "some_c_function"
                def converter_init(self):
                    self.function.noaccess
            [python start generated code]*/
            /*[clinic input]
            module test
            test.fn
                a: Custom
            [clinic start generated code]*/
        z{Stepped on a land mine, trying to access attribute 'noaccess':
Don't access members of self.function inside converter_init!r   r   s      r   +test_no_access_to_members_in_converter_initz?ClinicWholeFileTest.test_no_access_to_members_in_converter_initL  s2    !! # K 	 	c3r   N)r,   r-   r.   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r0   r   r   rz   rz   z   sZ    OE1"# 
#
#(*####  !
F  r   rz   c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)ClinicGroupPermuterTestc                 V    t        j                  |||      }| j                  ||       y r   )r   permute_optional_groupsr   )r$   lmroutputcomputeds         r   _testzClinicGroupPermuterTest._testb  s&    11!Q:*r   c                 6    | j                  dggdgdggd       y )Nstartstopstep))r   )r   r   )r   r   r   r   rE   s    r   
test_rangez"ClinicGroupPermuterTest.test_rangef  s#    

WI;F8*	r   c                 8    | j                  ddggdgdggd       y )Nxychattr))r   )r   r   )r   r   r   )r   r   r   r   r   rE   s    r   test_add_windowz'ClinicGroupPermuterTest.test_add_windown  s%    

S#J<$6(	r   c                 F    | j                  g dddggdgddgg dgd       y )	N)a1a2a3b1b2c1d1d2)e1e2e3))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   rE   s    r   test_ludicrousz&ClinicGroupPermuterTest.test_ludicrousw  s/    

&t5vtN`?a	r   c                 8    | j                  g g dgdgdggd       y )Nabc)r0   r   r   r   r   r   r   r   rE   s    r   test_right_onlyz'ClinicGroupPermuterTest.test_right_only  s&    

2rSE3%.	r   c                 6    d }| j                  t        |       y )Nc                  4    t        j                  dgg g        y )Nr   )r   r   r0   r   r   fnzPClinicGroupPermuterTest.test_have_left_options_but_required_is_empty.<locals>.fn  s    **C5"b9r   )r!   
ValueErrorr$   r   s     r   ,test_have_left_options_but_required_is_emptyzDClinicGroupPermuterTest.test_have_left_options_but_required_is_empty  s    	:*b)r   N)	r,   r-   r.   r   r   r   r   r   r   r0   r   r   r   r   a  s     +	*r   r   c                   6    e Zd Zd Zd Zd Zd Zd Zd Zd Z	y)	ClinicLinearFormatTestc                 T    t        j                  |fi |}| j                  ||       y r   )r   linear_formatr   )r$   inputr   r?   r   s        r   r   zClinicLinearFormatTest._test  s'    ''88*r   c                 (    | j                  dd       y )NrP   r   rE   s    r   test_empty_stringsz)ClinicLinearFormatTest.test_empty_strings  s    

2rr   c                 (    | j                  dd       y )Nr   r   rE   s    r   test_solo_newlinez(ClinicLinearFormatTest.test_solo_newline  s    

4r   c                 (    | j                  dd       y )Nz
          abc
        r   rE   s    r   test_no_substitutionz+ClinicLinearFormatTest.test_no_substitution  s    

 	r   c                 ,    | j                  ddd       y )N6
          abc
          {name}
          def
        z%
          abc
          def
        rP   r;   r   rE   s    r   test_empty_substitutionz.ClinicLinearFormatTest.test_empty_substitution  s"    

   	 	r   c                 ,    | j                  ddd       y )Nr   z6
          abc
          GARGLE
          def
        GARGLEr;   r   rE   s    r   test_single_line_substitutionz4ClinicLinearFormatTest.test_single_line_substitution  s"    

   	 	r   c                 ,    | j                  ddd       y )Nr   zH
          abc
          bingle
          bungle

          def
        zbingle
bungle
r;   r   rE   s    r   test_multiline_substitutionz2ClinicLinearFormatTest.test_multiline_substitution  s"    

  % 	 
	&r   N)
r,   r-   r.   r   r   r   r   r  r  r  r0   r   r   r   r     s%    +	&r   r   c                       e Zd Zd Zd Zy)InertParserc                      y r   r0   r$   r   s     r   r7   zInertParser.__init__      r   c                      y r   r0   r$   rQ   s     r   r   zInertParser.parse  r  r   Nr,   r-   r.   r7   r   r0   r   r   r  r    s    r   r  c                       e Zd Zd Zd Zy)
CopyParserc                      y r   r0   r
  s     r   r7   zCopyParser.__init__  r  r   c                 &    |j                   |_        y r   )r   r   r  s     r   r   zCopyParser.parse  s    {{r   Nr  r0   r   r   r  r    s    #r   r  c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)ClinicBlockParserTestc                     t        j                  d       }t        t        j                  ||            }t        j                  |      }|D ]  }|j                  |        |j                  j                         }y r   )r   r[   listr]   BlockPrinterprint_blockfr#   )r$   r   r   rK   blockswriterrQ   s          r   r   zClinicBlockParserTest._test  sc    ##D)f((9:$$X.Eu% ""$r   c                 &    | j                  ||      S r   r   )r$   r   s     r   
round_tripz ClinicBlockParserTest.round_trip  s    zz%''r   c                 &    | j                  d       y )Nz@
            verbatim text here
            lah dee dah
        r  rE   s    r   test_round_trip_1z'ClinicBlockParserTest.test_round_trip_1  s      	r   c                 &    | j                  d       y )Nz
    verbatim text here
    lah dee dah
/*[inert]
abc
[inert]*/
def
/*[inert checksum: 7b18d017f89f61cf17d47f92749ea6930a3f1deb]*/
xyz
r  rE   s    r   test_round_trip_2z'ClinicBlockParserTest.test_round_trip_2  s     	 		r   c                    t        j                  d       }t        j                  |d      }t        |      |j                  d<   t        |      |j                  d<   |j                  |      }| j                  ||       y )NrJ   r}   inertr   )r   r[   rw   r  parsersr  r   r   )r$   r   r   rK   r   r   s         r   _test_clinicz"ClinicBlockParserTest._test_clinic  sc    ##D)MM(V4(^		'&qM		&775>*r   c                 (    | j                  dd       y )Nz
    verbatim text here
    lah dee dah
/*[copy input]
def
[copy start generated code]*/
abc
/*[copy end generated code: output=03cfd743661f0797 input=7b18d017f89f61cf]*/
xyz
z
    verbatim text here
    lah dee dah
/*[copy input]
def
[copy start generated code]*/
def
/*[copy end generated code: output=7b18d017f89f61cf input=7b18d017f89f61cf]*/
xyz
)r&  rE   s    r   test_clinic_1z#ClinicBlockParserTest.test_clinic_1  s     			r   N)	r,   r-   r.   r   r  r   r"  r&  r(  r0   r   r   r  r    s!    k(

+r   r  c                   p   e 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) Z+d* Z,d+ Z-d, Z.d- Z/d. Z0d/ Z1d0 Z2d1 Z3d2 Z4d3 Z5d4 Z6d5 Z7d6 Z8d7 Z9d8 Z:d9 Z;d=d:Z<d; Z=y<)>ClinicParserTestc                     | j                  t        |d             | j                  |j                  j	                         t        |      j	                                y )N	docstring)r   hasattrr   r,  r   r	   )r$   r   r   s      r   checkDocstringzClinicParserTest.checkDocstring  sC    K01++-)//1	3r   c                    t        t                     }t        j                  d      }|j	                  |       |j
                  \  }}| j                  d|j                         | j                  d|j                         y )Nz5
            module os
            os.access
        accessos)r   rN   r   Blockr   
signaturesr   r4   )r$   r%   rQ   rr   functions        r   test_trivialzClinicParserTest.test_trivial  sg    :<(   	U ++8==1v{{+r   c                     | j                  t        d            }|j                  \  }}| j                  d|j                         | j                  d|j                         y )NzC
            #
            module os
            os.access
        r0  r1  )r   r	   r3  r   r4   )r$   rQ   rr   r4  s       r   test_ignore_linez!ClinicParserTest.test_ignore_line"  sV    

6 #  
 !++8==1v{{+r   c                 R   | j                  d      }| j                  d|j                         | j                  dt        |j                               |j                  d   }| j                  d|j                         | j                  |j                  t        j                         y )NzO
            module os
            os.access
                path: int
        r0  r   path)	r*   r   r4   len
parametersassertIsInstance	converterr   int_converterr$   r4  ps      r   
test_paramzClinicParserTest.test_param,  s    && ( 
 	8==1C 3 345'(akk6+?+?@r   c                 |    | j                  d      }|j                  d   }| j                  d|j                         y )Nzb
            module os
            os.access
                follow_symlinks: bool = True
        follow_symlinksTr*   r;  r   r>   r?  s      r   test_param_defaultz#ClinicParserTest.test_param_default8  s>    && ( 
  12qyy)r   c                 |    | j                  d      }|j                  d   }| j                  d|j                         y )Nz
            module os
            os.access
                follow_symlinks: \
                bool \
                = \
                True
        rC  TrD  r?  s      r   test_param_with_continuationsz.ClinicParserTest.test_param_with_continuationsA  s>    && (   12qyy)r   c                 .   | j                  d      }|j                  d   }| j                  t        j                  |j
                         | j                  d|j                  j                         d}| j                  d      }| j                  ||       y )Nz
            module os
            os.access
                follow_symlinks: int(c_default='MAXSIZE') = sys.maxsize
            rC  MAXSIZEz~Error on line 0:
When you specify a named constant ('sys.maxsize') as your default value,
you MUST specify a valid c_default.
zh
            module os
            os.access
                follow_symlinks: int = sys.maxsize
        )	r*   r;  r   rj   maxsizer>   r=  	c_defaultr+   )r$   r4  r@  expected_msgr   s        r   test_param_default_expressionz.ClinicParserTest.test_param_default_expressionM  s    && ( 
  12aii0AKK$9$9:4 	
 -- / 
 	l+r   c                     | j                  d      }| j                  dt        |j                               |j                  d   j                  }| j                  |t        j                         y )Nz
            module os
            os.access
                follow_symlinks: bool = True
                something_else: str = ''
           something_else)r*   r   r:  r;  r=  r<  r   str_converter)r$   r4  convs      r   test_param_no_docstringz(ClinicParserTest.test_param_no_docstringc  sa    && (  	C 3 345""#34>>dF$8$89r   c                 N    d}| j                  d      }| j                  ||       y )NzoError on line 0:
Can't have a parameter without a default ('something_else')
after a parameter with a default!
z}
            module os
            os.access
                follow_symlinks: bool = True
                something_else: strr+   r   r$   rL  r   s      r   *test_param_default_parameters_out_of_orderz;ClinicParserTest.test_param_default_parameters_out_of_ordern  s5    2 	
 -- /' (
 	l+r   c                     | j                  d      }|j                  d   }| j                  d|j                  j                  d          y )Nz^
            module os
            os.access
                path: path_t(allow_fd=1)
        r9     allow_fd)r*   r;  r   r=  r5   r?  s      r   !disabled_test_converter_argumentsz2ClinicParserTest.disabled_test_converter_arguments{  sH    && ( 
 'AKK,,Z89r   c                 J    | j                  d      }| j                  |d       y )Nz
            module os
            os.stat as os_stat_fn

               path: str
                   Path to be examined

            Perform a stat system call on the given path.
        z
            stat($module, /, path)
            --

            Perform a stat system call on the given path.

              path
                Path to be examined
        r*   r.  r$   r4  s     r   test_function_docstringz(ClinicParserTest.test_function_docstring  .    && (  	H ' 	r   c                 \    | j                  t        d            }| j                  |d       y )Nz
            module foo
            foo.bar
              x: int
                 Documentation for x.
              y: int

            This is the documentation for foo.

            Okay, we're done here.
        z
            bar($module, /, x, y)
            --

            This is the documentation for foo.

              x
                Documentation for x.

            Okay, we're done here.
        r*   r	   r.  r^  s     r   %test_explicit_parameters_in_docstringz6ClinicParserTest.test_explicit_parameters_in_docstring  s5    &&v 
/ 
( 
 	H 
' 
	r   c                 \    | j                  t        d            }| j                  |d       y )Nzt
            module os
            os.stat
                path: str
            This/used to break Clinic!
        zc
            stat($module, /, path)
            --

            This/used to break Clinic!
        rb  r^  s     r   Ttest_parser_regression_special_character_in_parameter_column_of_docstring_first_linezeClinicParserTest.test_parser_regression_special_character_in_parameter_column_of_docstring_first_line  s5    &&v / (  	H ' 	r   c                 ^    | j                  d      }| j                  d|j                         y )NzA
            module os
            os.stat as os_stat_fn
        
os_stat_fn)r*   r   
c_basenamer^  s     r   test_c_namezClinicParserTest.test_c_name  s/    && (  	x':':;r   c                 z    | j                  d      }| j                  |j                  t        j                         y )Nz:
            module os
            os.stat -> int
        )r*   r<  return_converterr   int_return_converterr^  s     r   test_return_converterz&ClinicParserTest.test_return_converter  s5    && (  	h779T9TUr   c                     | j                  d      }|j                  d   }| j                  t        j                  j
                  |j                         | j                  d|j                         y )Nzt
            module os
            os.access
                *
                follow_symlinks: bool = True
        rC  r   )r*   r;  r   inspect	ParameterKEYWORD_ONLYkindgroupr?  s      r   	test_starzClinicParserTest.test_star  s^    && (   12**77@AGG$r   c                 |    | j                  d      }|j                  d   }| j                  d|j                         y )Nz
            module window
            window.border
                [
                ls: int
                ]
                /
        lsrY  )r*   r;  r   rs  r?  s      r   
test_groupzClinicParserTest.test_group  s=    && (  %AGG$r   c                 p   | j                  d      }d}|D ]  \  }}| j                  ||      5  |j                  |   }| j                  |j                  |       | j                  |j
                  t        j                  j                         d d d         | j                  |d       y # 1 sw Y   xY w)Na  
            module curses
            curses.addch
                [
                y: int
                    Y-coordinate.
                x: int
                    X-coordinate.
                ]
                ch: char
                    Character to add.
                [
                attr: long
                    Attributes for the character.
                ]
                /
        ))r   r   )r   r   r   r   )r   rY  r4   rs  a  
            addch([y, x,] ch, [attr])


              y
                Y-coordinate.
              x
                X-coordinate.
              ch
                Character to add.
              attr
                Attributes for the character.
        
r*   r   r;  r   rs  rr  ro  rp  POSITIONAL_ONLYr.  r$   r4  datasetr4   rs  r@  s         r   test_left_groupz ClinicParserTest.test_left_group  s    && ( "

 #KD%4u5''-  %0  ):):)J)JK 65 #
 	H ' 		 65   A B,,B5	c                 p   | j                  d      }d}|D ]  \  }}| j                  ||      5  |j                  |   }| j                  |j                  |       | j                  |j
                  t        j                  j                         d d d         | j                  |d       y # 1 sw Y   xY w)Na  
            module curses
            curses.imaginary
               [
               [
               y1: int
                 Y-coordinate.
               y2: int
                 Y-coordinate.
               ]
               x1: int
                 X-coordinate.
               x2: int
                 X-coordinate.
               ]
               ch: char
                 Character to add.
               [
               attr1: long
                 Attributes for the character.
               attr2: long
                 Attributes for the character.
               attr3: long
                 Attributes for the character.
               [
               attr4: long
                 Attributes for the character.
               attr5: long
                 Attributes for the character.
               attr6: long
                 Attributes for the character.
               ]
               ]
               /
        ))y1)y2r  )x1r   )x2r   ry  )attr1rY  )attr2rY  )attr3rY  )attr4r   )attr5r   )attr6r   rz  a  
            imaginary([[y1, y2,] x1, x2,] ch, [attr1, attr2, attr3, [attr4, attr5,
                      attr6]])


              y1
                Y-coordinate.
              y2
                Y-coordinate.
              x1
                X-coordinate.
              x2
                X-coordinate.
              ch
                Character to add.
              attr1
                Attributes for the character.
              attr2
                Attributes for the character.
              attr3
                Attributes for the character.
              attr4
                Attributes for the character.
              attr5
                Attributes for the character.
              attr6
                Attributes for the character.
        r{  r}  s         r   test_nested_groupsz#ClinicParserTest.test_nested_groups  s    && "( "F
 #KD%4u5''-  %0  ):):)J)JK 65 # 	H ' 	 65r  c                    t        j                         5 }| j                  t              5  | j	                  |       d d d        d d d        |j                         S # 1 sw Y   !xY w# 1 sw Y   j                         S xY wr   )r   r    r!   r"   r*   r#   )r$   sr'   s      r   r+   z+ClinicParserTest.parse_function_should_fail[  sc    $$&&"":.##A& / '    /. '   s!   A)AA)A&	"A))Bc                 N    d}| j                  d      }| j                  ||       y )NzpError on line 0:
Function two_top_groups_on_left has an unsupported group configuration. (Unexpected state 2.b)
z
            module foo
            foo.two_top_groups_on_left
                [
                group1 : int
                ]
                [
                group2 : int
                ]
                param: int
        rU  rV  s      r   0test_disallowed_grouping__two_top_groups_on_leftzAClinicParserTest.test_disallowed_grouping__two_top_groups_on_lefta  s5    6 	
 -- 
/ 
 	l+r   c                 N    | j                  d      }d}| j                  ||       y )Nz
            module foo
            foo.two_top_groups_on_right
                param: int
                [
                group1 : int
                ]
                [
                group2 : int
                ]
        z_Function two_top_groups_on_right has an unsupported group configuration. (Unexpected state 6.b)r+   r   r   s      r   1test_disallowed_grouping__two_top_groups_on_rightzBClinicParserTest.test_disallowed_grouping__two_top_groups_on_rightt  1    -- 
/ 
4 	 	c3r   c                 N    | j                  d      }d}| j                  ||       y )Nz
            module foo
            foo.parameter_after_group_on_right
                param: int
                [
                [
                group1 : int
                ]
                group2 : int
                ]
        zfFunction parameter_after_group_on_right has an unsupported group configuration. (Unexpected state 6.a)r  r   s      r   8test_disallowed_grouping__parameter_after_group_on_rightzIClinicParserTest.test_disallowed_grouping__parameter_after_group_on_right  r  r   c                 N    | j                  d      }d}| j                  ||       y )Nz
            module foo
            foo.group_after_parameter_on_left
                [
                group2 : int
                [
                group1 : int
                ]
                ]
                param: int
        zeFunction group_after_parameter_on_left has an unsupported group configuration. (Unexpected state 2.b)r  r   s      r   7test_disallowed_grouping__group_after_parameter_on_leftzHClinicParserTest.test_disallowed_grouping__group_after_parameter_on_left  r  r   c                 N    | j                  d      }d}| j                  ||       y )Nz
            module foo
            foo.empty_group
                [
                [
                ]
                group2 : int
                ]
                param: int
        XFunction empty_group has an empty group.
All groups must contain at least one parameter.r  r   s      r   -test_disallowed_grouping__empty_group_on_leftz>ClinicParserTest.test_disallowed_grouping__empty_group_on_left  1    -- 	/ 	> 	 	c3r   c                 N    | j                  d      }d}| j                  ||       y )Nz
            module foo
            foo.empty_group
                param: int
                [
                [
                ]
                group2 : int
                ]
        r  r  r   s      r   .test_disallowed_grouping__empty_group_on_rightz?ClinicParserTest.test_disallowed_grouping__empty_group_on_right  r  r   c                 N    | j                  d      }d}| j                  ||       y )Nz
            module foo
            foo.empty_group
                param: int
                ]
                group2: int
                ]
        z2Function empty_group has a ] without a matching [.r  r   s      r   -test_disallowed_grouping__no_matching_bracketz>ClinicParserTest.test_disallowed_grouping__no_matching_bracket  s-    -- /  Cc3r   c                     | j                  d      }| j                  d|j                         | j                  dt        |j                               y )NzL
            module foo
            foo.bar

            Docstring

        zbar($module, /)
--

DocstringrY  r*   r   r,  r:  r;  r^  s     r   test_no_parametersz#ClinicParserTest.test_no_parameters  sK    && (  	;X=O=OPC 3 345r   c                     | j                  ddd      }| j                  d|j                         | j                  dt        |j                               y )Nz
            module foo
            class foo.Bar "unused" "notneeded"
            foo.Bar.__init__

            Docstring

        rO  r   signatures_in_blockfunction_indexzBar()
--

DocstringrY  r  r^  s     r   test_init_with_no_parametersz-ClinicParserTest.test_init_with_no_parameters  sW    && ( "#1 ' 6 	183E3EFC 3 345r   c                 N    | j                  d      }d}| j                  ||       y )NzM
            module foo
            foo.bar => int
                /
        z%Illegal function name: foo.bar => intr  r   s      r   test_illegal_module_linez)ClinicParserTest.test_illegal_module_line  s,    -- / 
 6c3r   c                 N    | j                  d      }d}| j                  ||       y )NzM
            module foo
            foo.bar as 935
                /
        zIllegal C basename: 935r  r   s      r   test_illegal_c_basenamez(ClinicParserTest.test_illegal_c_basename  s,    -- / 
 (c3r   c                 J    | j                  d      }| j                  d|       y )NzX
            module foo
            foo.bar
                *
                *
        z%Function bar uses '*' more than once.r  r$   r   s     r   test_single_starz!ClinicParserTest.test_single_star  s(    -- /  	=sCr   c                     d}d}|D ]@  }| j                  |      5  | j                  |      }| j                  ||       d d d        B y # 1 sw Y   MxY w)N)zmodule foo
foo.bar
  *z&module foo
foo.bar
  *
Docstring here.z"module foo
foo.bar
  this: int
  *z-module foo
foo.bar
  this: int
  *
Docstring.z=Function bar specifies '*' without any parameters afterwards.rQ   )r   r+   r   )r$   r~  r   rQ   r   s        r   #test_parameters_required_after_starz4ClinicParserTest.test_parameters_required_after_star  sV    
 NEE*55e<c3' +* **   $AA	c                 N    | j                  d      }d}| j                  ||       y )NzX
            module foo
            foo.bar
                /
                /
        KFunction bar has an unsupported group configuration. (Unexpected state 0.d)r  r   s      r   test_single_slashz"ClinicParserTest.test_single_slash  1    -- / % 	 	c3r   c                 N    | j                  d      }d}| j                  ||       y )Nz
            module foo
            foo.bar
                a: int
                /
                b: int
                /
        z%Function bar uses '/' more than once.r  r   s      r   test_double_slashz"ClinicParserTest.test_double_slash'  s,    -- /  6c3r   c                 N    | j                  d      }d}| j                  ||       y )Nz
            module foo
            foo.bar
               x: int
               y: int
               *
               z: int
               /
        zUFunction bar mixes keyword-only and positional-only parameters, which is unsupported.r  r   s      r   test_mix_star_and_slashz(ClinicParserTest.test_mix_star_and_slash3  s1    -- / $ 	 	c3r   c                 N    | j                  d      }d}| j                  ||       y )Nz]
            module foo
            foo.bar
                /
                x: int
        r  r  r   s      r   1test_parameters_not_permitted_after_slash_for_nowzBClinicParserTest.test_parameters_not_permitted_after_slash_for_nowC  r  r   c                 N    d}| j                  d      }| j                  ||       y )Nz#Error on line 0:
Too many var args
zt
            module foo
            foo.bar
               *vararg1: object
               *vararg2: object
        rU  rV  s      r   'test_parameters_no_more_than_one_varargz8ClinicParserTest.test_parameters_no_more_than_one_varargP  s5    " 	 -- /  	l+r   c                 J    | j                  d      }| j                  |d       y )Nz
              module foo
              foo.bar
                x: int
                  Nested docstring here, goeth.
                *
                y: str
              Not at column 0!
        z
            bar($module, /, x, *, y)
            --

            Not at column 0!

              x
                Nested docstring here, goeth.
        r]  r^  s     r   test_function_not_at_column_0z.ClinicParserTest.test_function_not_at_column_0]  r`  r   c                 N    | j                  d      }d}| j                  ||       y )Nzr
            module foo
            foo.bar
               *vararg1: object
            	*vararg2: object
        z-Tab characters are illegal in the Clinic DSL.r  r   s      r   test_indent_stack_no_tabsz*ClinicParserTest.test_indent_stack_no_tabsq  s,    -- /  >c3r   c                 J    | j                  d      }| j                  d|       y )Nzc
            module foo
            foo.bar
              a: object
             b: object
        zIllegal outdentr  r  s     r   !test_indent_stack_illegal_outdentz2ClinicParserTest.test_indent_stack_illegal_outdent{  s(    -- /  	'-r   c                     t               }t        |      d_        fdj                  d<   t	        j
                  d      }j                  |       | j                  j                         y )NFc                      t         dd      S )NflagT)setattr)r%   s   r   <lambda>z1ClinicParserTest.test_directive.<locals>.<lambda>  s    0Mr   setflag)rN   r   r  
directivesr   r2  r   r   )r$   r   rQ   r%   s      @r   test_directivezClinicParserTest.test_directive  sT    L1'M)$Y'U$r   c                     | j                  d      }|j                  \  }}|j                  d   j                  }| j	                  |t
        j                         y )Nz module os
os.access
   path: "s"r9  )r   r3  r;  r=  r<  r   rQ  )r$   rQ   rr   r4  rR  s        r   test_legacy_convertersz'ClinicParserTest.test_legacy_converters  sM    

?@ ++##F+66dF$8$89r   c                     d}d}|D ]@  }| j                  |      5  | j                  |      }| j                  ||       d d d        B y # 1 sw Y   MxY w)NRError on line 0:
Annotations must be either a name, a function call, or a string.
)zmodule os
os.access
   path: 42z"module os
os.access
   path: 42.42z module os
os.access
   path: 42jz"module os
os.access
   path: b"42"r  r   r+   r   r$   expected_failure_messager~  rQ   r   s        r   5test_legacy_converters_non_string_constant_annotationzFClinicParserTest.test_legacy_converters_non_string_constant_annotation  s^    Q 	!
 EE*55e<  &>? +* **r  c                     d}d}|D ]@  }| j                  |      5  | j                  |      }| j                  ||       d d d        B y # 1 sw Y   MxY w)Nr  )z3module os
os.access
   path: {"some": "dictionary"}z6module os
os.access
   path: ["list", "of", "strings"]z3module os
os.access
   path: (x for x in range(42))r  r  r  s        r   -test_other_bizarre_things_in_annotations_failz>ClinicParserTest.test_other_bizarre_things_in_annotations_fail  s^    Q 	!

 EE*55e<  &>? +* **r  c                     d}d}|D ]@  }| j                  |      5  | j                  |      }| j                  ||       d d d        B y # 1 sw Y   MxY w)NzHError on line 0:
Cannot use a kwarg splat in a function-call annotation
)z1module fo
fo.barbaz
   o: bool(**{None: "bang!"})z.module fo
fo.barbaz -> bool(**{None: "bang!"})z+module fo
fo.barbaz -> bool(**{"bang": 42})z0module fo
fo.barbaz
   o: bool(**{"bang": None}))r   r  )r$   expected_error_msgr~  r   r   s        r   9test_kwarg_splats_disallowed_in_function_call_annotationszJClinicParserTest.test_kwarg_splats_disallowed_in_function_call_annotations  s^    G 	
 B$55b9  &89 %$ $$r  c                 R    d}d}| j                  |      }| j                  ||       y )NzhError on line 0:
A 'self' parameter, if specified, must be the very first thing in the parameter block.
zz
            module foo
            foo.func
                a: int
                self: self(type="PyObject *")
        rU  r$   r  rQ   r   s       r   test_self_param_placementz*ClinicParserTest.test_self_param_placement  s6    ( 	
 --e401r   c                 R    d}d}| j                  |      }| j                  ||       y )Nz?Error on line 0:
A 'self' parameter cannot be marked optional.
zj
            module foo
            foo.func
                self: self(type="PyObject *") = None
        rU  r  s       r   "test_self_param_cannot_be_optionalz3ClinicParserTest.test_self_param_cannot_be_optional  s6    > 	
 --e401r   c                 R    d}d}| j                  |      }| j                  ||       y )NzError on line 0:
A 'defining_class' parameter, if specified, must either be the first thing in the parameter block, or come just after 'self'.
z
            module foo
            foo.func
                self: self(type="PyObject *")
                a: int
                cls: defining_class
        rU  r  s       r   #test_defining_class_param_placementz4ClinicParserTest.test_defining_class_param_placement  s7    O 	
 --e401r   c                 R    d}d}| j                  |      }| j                  ||       y )NzIError on line 0:
A 'defining_class' parameter cannot be marked optional.
zs
            module foo
            foo.func
                cls: defining_class(type="PyObject *") = None
        rU  r  s       r   ,test_defining_class_param_cannot_be_optionalz=ClinicParserTest.test_defining_class_param_cannot_be_optional  s7    H 	
 --e401r   c                     d}d}| j                  t        |      5  | j                  |       d d d        y # 1 sw Y   y xY w)Nz
            module foo
            class Foo "" ""
            Foo.__init__
                cls: defining_class
                a: object
        z0Slot methods cannot access their defining class.)assertRaisesRegexr   r*   )r$   rQ   r   s      r   .test_slot_methods_cannot_access_defining_classz?ClinicParserTest.test_slot_methods_cannot_access_defining_class  s;     A##J4& 544s   6?c                 N    d}| j                  d      }| j                  ||       y )Nz1Error on line 0:
__new__ must be a class method!
zT
            module foo
            class Foo "" ""
            Foo.__new__
        rU  r$   r  r   s      r   test_new_must_be_a_class_methodz0ClinicParserTest.test_new_must_be_a_class_method  s6    0 	 -- / 
 	01r   c                 N    d}| j                  d      }| j                  ||       y )NzQError on line 0:
__init__ must be a normal method, not a class or static method!
zn
            module foo
            class Foo "" ""
            @classmethod
            Foo.__init__
        rU  r  s      r   !test_init_must_be_a_normal_methodz2ClinicParserTest.test_init_must_be_a_normal_method  s7    P 	 -- /  	01r   c                    | j                  d      }|j                  d   }|j                  fd}dddddddd	dd
d	df}|D ]  }|j                         \  }}| j	                  ||      5   ||      }| j                  ||j                         |j                  d      }	|r| j                  d|	       n| j                  d|	       |j                  d	      }
| j                  d|
       d d d         y # 1 sw Y   xY w)Nz
            module foo
            foo.func
                fn: object
                k: float
                i: float(unused=True)
                /
                *
                flag: bool(unused=True) = False
        rY  c                 "    |    j                   S r   r=  )r   paramss    r   r  z4ClinicParserTest.test_unused_param.<locals>.<lambda>-  s    &*..r   r   F)r4   unusedkiTr  )	in_parser	Py_UNUSED)
r   r3  r;  valuesr   r   r  simple_declarationr   assertNotIn)r$   rQ   sigrR  r~  paramr4   r  r@  declparser_declr  s              @r   test_unused_paramz"ClinicParserTest.test_unused_param   s   

 	 	 q!.U+E*D)t,	
 E <<>LD&47J  2 ++e+<MM+t4$$[$7  22T2B  k: 87 77s   0BC==D	c                     | j                  ddd      }|j                  d   }| j                  |j                  t        j
                  j                         y )Nz}
            module m
            class m.C "PyObject *" ""
            m.C.meth
                cls: defining_class
        rO  r   r  cls)r*   r;  r   rr  ro  rp  r|  r?  s      r   test_kind_defining_classz)ClinicParserTest.test_kind_defining_classF  sU    && (
 "#1 ' 6 &!2!2!B!BCr   c                 N    d}| j                  d      }| j                  ||       y )NzQError on line 0:
A 'defining_class' parameter cannot be defined at module level.
zU
            module m
            m.func
                cls: defining_class
        rU  r  s      r   ,test_disallow_defining_class_at_module_levelz=ClinicParserTest.test_disallow_defining_class_at_module_levelP  s7    P 	 -- / 
 	01r   c                 |    t               }t        |      }t        j                  |      }|j	                  |       |S r   )rN   r   r   r2  r   )r$   textr   r%   rQ   s        r   r   zClinicParserTest.parse\  s1    L1T"Ur   c                 |    | j                  |      }|j                  }| j                  t        |      |       ||   S r   )r   r3  r   r:  )r$   r  r  r  rQ   r  s         r   r*   zClinicParserTest.parse_functionc  s=    

4 Q!45   r   c                    | j                  t        t        j                        d       | j                  t        t        j                        d       d}t        j                         5 }| j                  t              5  t        j                  ddd       d d d        d d d        j                         }| j                  ||       y # 1 sw Y   4xY w# 1 sw Y   8xY w)Nz<Unspecified>z<Null>z>Error in file "clown.txt" on line 69:
The igloos are melting!
zThe igloos are melting!z	clown.txtE   )rL   line_number)r   rl   r   unspecifiedNULLr   r    r!   r"   failr#   )r$   r   r'   actuals       r   test_scaffoldingz!ClinicParserTest.test_scaffoldingk  s    f001?Cfkk*H5( 	 $$&&"":.5%0bB / ' "*	 /. '&s$   )C?CCC	CC N)r   rY  )>r,   r-   r.   r.  r5  r7  rA  rE  rG  rM  rS  rW  r[  r_  rc  re  ri  rm  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*   r  r0   r   r   r*  r*    s3   3
	,,
A*
*,,	:,:(0<V	%
%(TL\!,& $ $ $ " "
 	66  D( 
    ,( .%:@ @: 222 2
'
22$;LD
2!+r   r*  c                       e Zd ZdZej
                  j                  ej                  dd      Z	d Z
dd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y)ClinicExternalTestNr   z	clinic.pyc                     t        |        y r   )r   rE   s    r   r~   zClinicExternalTest.setUp  s
    %r   T)expect_successc                   t        j                  t        j                  d| j                  g|ddt         j
                  t         j
                        5 }|j                          |rD|j                  r8| j                  dj                  g |j                  |j                               |j                  j                         }|j                  j                         }| j                  |d       |cd d d        S # 1 sw Y   y xY w)Nz-Xutf8utf-8r   )encodingbufsizer'   stderrrP   )
subprocessPopenrj   
executable	clinic_pyPIPEwait
returncoder  joinr'   r  readr   )r$   r  r5   procr'   r  s         r   _do_testzClinicExternalTest._do_test  s    ^^Xt~~==????
 IIK$//		"''">DKK">$++">?@[[%%'F[[%%'FVR(
 
 
s   BC<<Dc                       | j                   | S r   r!  r$   r5   s     r   r  z!ClinicExternalTest.expect_success  s    t}}d##r   c                 &     | j                   |ddiS )Nr  Fr#  r$  s     r   r   z!ClinicExternalTest.expect_failure  s    t}}d9599r   c                    d}t        j                  |      }t        |d      5 }|j                         }d d d        | j	                  t
        t               | j                  ddt        |      }| j                  |d       t        t        d      5 }|j                         }d d d        | j                         y # 1 sw Y   xY w# 1 sw Y   (xY w)Nzclinic.test.cr  r  -f-orP   )	r   findfileopenr  r   r   r   r  r   )r$   CLINIC_TESTsourcer  orig_contentsr   new_contentss          r   test_externalz ClinicExternalTest.test_external  s    %!!+.&7+qFFHM , 	'!!$ff=b!&7+q668L , 	}5 ,+ ,+s   B?C?CCc                    t        d      }t        j                         5 }t        j                  j                  |d      }t        |dd      5 }|j                  |       d d d        t        j                  |      j                  }| j                  |       t        j                  |      j                  }d d d        | j                         y # 1 sw Y   sxY w# 1 sw Y   (xY w)Nz
            /*[clinic input]
            [clinic start generated code]*/
            /*[clinic end generated code: output=da39a3ee5e6b4b0d input=da39a3ee5e6b4b0d]*/
        r|   wr  r'  )r	   r   temp_dirr1  r9  r  r+  writestatst_mtime_nsr  r   )r$   codetmp_dirr   r  	pre_mtime
post_mtimes          r   test_no_changez!ClinicExternalTest.test_no_change  s       
 !Wgx0Bb#0A 1//I#00J " 	J/ 10 "!s$   /CC!ACC	CC(c                 |   t        d      }t        d      }t        j                         5 }t        j                  j                  |d      }t        |dd      5 }|j                  |       d d d        | j                  |      }| j                  |j                  |             | j                  d|      }| j                  |d       d	}t        |d      5 }|j                         }d d d        | j                  j                  |             d d d        y # 1 sw Y   xY w# 1 sw Y   >xY w# 1 sw Y   y xY w)
NaA  
            /*[clinic input]
            output preset block
            module test
            test.fn
                a: int
            [clinic start generated code]*/

            const char *hand_edited = "output block is overwritten";
            /*[clinic end generated code: output=bogus input=bogus]*/
        z
            Checksum mismatch!
            Expected: bogus
            Computed: 2ed19
            Suggested fix: remove all generated code including the end marker,
            or use the '-f' option.
        r|   r2  r  r'  r(  rP   zP/*[clinic end generated code: output=99dd9b13ffdc660d input=9543a8d2da235301]*/
)r	   r   r3  r1  r9  r  r+  r4  r   r   endswithr  r   r  )	r$   invalid_inputfail_msgr8  r   r  r   checksum	generateds	            r   test_cli_forcez!ClinicExternalTest.test_cli_force  s    
  
    !Wgx0Bb#0A& 1
 %%b)COOCLL23%%dB/CS"%F  b7+qFFH	 ,OOI..x89' "!00 ,+# "!s<   /D2D,A,D2D&)(D2D#	D2&D/	+D22D;c                    t        d      }d}d}d}d }t        j                         5 } ||||        ||||       t        j                  j                  |d      }t        j                  |      5 } ||||       | j                  dd	d
|      }	d d d        |D ]O  }
| j                  |
      5  t        j                  j                  ||
      }| j                  |	       d d d        Q |D ]O  }
| j                  |
      5  t        j                  j                  ||
      }| j                  |	       d d d        Q |D ]O  }
| j                  |
      5  t        j                  j                  ||
      }| j                  |	       d d d        Q 	 d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)NzR
            /*[clinic input]
            [clinic start generated code]*/
        pass)zfile1.czfile2.c)zfile1.pyzfile2.pyc                     | D ]J  }t         j                  j                  ||      }t        |dd      5 }|j	                  |       d d d        L y # 1 sw Y   WxY w)Nr2  r  r'  )r1  r9  r  r+  r4  )filessrcdirr7  r   r9  r  s         r   create_filesz6ClinicExternalTest.test_cli_make.<locals>.create_files  sH    ww||FB/$g6!GGDM 76 66s   AA		externals)r9  -v--make--srcdirr}   )
r	   r   r3  r1  r9  r  r  r   r   r  )r$   c_codepy_codec_filespy_filesrH  r8  ext_pathrI  r   rL   r9  s               r   test_cli_makez ClinicExternalTest.test_cli_make  s      &)	" !W'627G4 ww||G[9H##2iWi8 ))$*gN	 3 $\\8\477<<:DMM$, 54 $ %\\8\477<<:D$$T3/ 54 %
 $\\8\477<<(;D$$T3/ 54 $/ "! 32 54 54
 541 "!sl   AG4F!G23F.%!G3F;9!G3G
G!F+	&G.F83G;G GGGGc                 b   t        j                         5 }t        j                  j	                  |d      }t        |dd      5 }|j                  d       d d d        | j                  d|      }| j                  |j                         |       d d d        y # 1 sw Y   DxY w# 1 sw Y   y xY w)Nr|   r2  r  r'  rP   rJ  )
r   r3  r1  r9  r  r+  r4  r  r   r   )r$   r8  r   r  r   s        r   test_cli_verbosez#ClinicExternalTest.test_cli_verbose  s    !Wgx0Bb#0A 1%%dB/CSYY["- "!00 "!s#   /B%B:B%B"	B%%B.c                 J    | j                  d      }| j                  d|       y )Nz-husage: clinic.py)r  r   r  s     r   test_cli_helpz ClinicExternalTest.test_cli_help  s!    !!$'(#.r   c           	      $   t        d      }d}t        d      }| j                  d      }| j                  |j                  |      |       | j                  |j	                  |      |       |j                  |      }|j                  |      }|j                  d      }t        ||      D ]W  \  }}|j                         }| j                  |      5  | j                  |j                  |      d|d|       d d d        Y y # 1 sw Y   dxY w)	Nz
            Legacy converters:
                B C D L O S U Y Z Z#
                b c d f h i l p s s# s* u u# w* y y# y* z z# z*

            Converters:
        )boolbytechardefining_classdoublefildesfloatintlong	long_longobject	Py_buffer
Py_complex
Py_ssize_t
Py_UNICODEPyByteArrayObjectPyBytesObjectr$   shortsize_tslice_indexstrunicodeunsigned_charunsigned_intunsigned_longunsigned_long_longunsigned_shorta  
            Return converters:
                bool()
                double()
                float()
                init()
                int()
                long()
                Py_ssize_t()
                size_t()
                unsigned_int()
                unsigned_long()

            All converters also accept (c_default=None, py_default=None, annotation=None).
            All return converters also accept (py_default=None).
        --convertersr   r  zexpected converter z, got )r	   r  r   r   r=  removeprefixremovesuffixr   zipr   r   )r$   preludeexpected_convertersfinaler   linesr=  lines           r   test_cli_convertersz&ClinicExternalTest.test_cli_converters  s      
<     !!.1
 	w/5V,c2w'v&		$"#6>OIt;;=D	2OOI.))fTHE 32  ?22s   (DD	c                 P    | j                  dd      }d}| j                  ||       y )Nrt  r|   zGUsage error: can't specify --converters and a filename at the same timer   r   s      r   %test_cli_fail_converters_and_filenamez8ClinicExternalTest.test_cli_fail_converters_and_filenameg  s.    !!.(;. 	 	c3r   c                 H    | j                         }| j                  d|       y )NrV  r   r  s     r   test_cli_fail_no_filenamez,ClinicExternalTest.test_cli_fail_no_filenameo  s    !!#(#.r   c                 T    | j                  dddd      }d}| j                  ||       y )Nr)  out.czinput.czmoreinput.cz1Usage error: can't use -o with multiple filenamesr   r   s      r   'test_cli_fail_output_and_multiple_filesz:ClinicExternalTest.test_cli_fail_output_and_multiple_filess  s+    !!$MJAc3r   c                     dD ]D  }| j                  |      5   | j                  dg| }d}| j                  ||       d d d        F y # 1 sw Y   QxY w)N))r)  r  )z
filename.c)optsrK  z2Usage error: can't use -o or filenames with --make)r   r   r   )r$   r  r   r   s       r   )test_cli_fail_filename_or_output_and_makez<ClinicExternalTest.test_cli_fail_filename_or_output_and_makex  sS    4D4()d))(:T:Jc3' )( 5((   (AA	c                 R    | j                  ddd      }d}| j                  ||       y )NrK  rL  rP   z3Usage error: --srcdir must not be empty with --maker   r   s      r   !test_cli_fail_make_without_srcdirz4ClinicExternalTest.test_cli_fail_make_without_srcdir  s)    !!(J;Cc3r   )r,   r-   r.   r/   r1  r9  r  r   toolsdirr  r~   r!  r  r   r0  r;  rB  rR  rT  rW  r}  r  r  r  r  r  r0   r   r   r  r  }  s|    GZ00(KHI& .2 "$:6 0(&:P)0V./GR / 
( r   r  z_testclinic is missingc                      e Zd Z e       j	                  d  ee      D               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, Z1d- Z2d. Z3d/ Z4d0 Z5d1 Z6d2 Z7d3 Z8d4 Z9d5 Z:d6 Z;d7 Z<y8)9ClinicFunctionalTestc              #   b   K   | ]'  }|j                  d       r|t        t        |      f ) yw)test_N)r   getattr	ac_tester).0r4   s     r   	<genexpr>zClinicFunctionalTest.<genexpr>  s0      L .$//'2J 79d34 .s   -/c                 f   | j                  t              5  t        j                          d d d        | j	                  t        j                  dd      d       | j	                  t        j                  g d      g df       | j	                  t        j                  d      d       y # 1 sw Y   }xY w)NrY  r   rY  r   zwhatever class)rY  N)r!   	TypeErrorr  objects_converterr   rE   s    r   test_objects_converterz+ClinicFunctionalTest.test_objects_converter  s    y)'') *44Q:FC44R9IJRQaLbc44Q7C	 *)s   B''B0c                     | j                  t              5  t        j                  d       d d d        | j	                  t        j                  d      d       y # 1 sw Y   /xY w)NrY     BytesObject)r  )r!   r  r  bytes_object_converterr   rE   s    r   test_bytes_object_converterz0ClinicFunctionalTest.test_bytes_object_converter  sH    y),,Q/ *99.IK\] *)   AA#c                     | j                  t              5  t        j                  d       d d d        t	        d      }| j                  t        j                  |      |f       y # 1 sw Y   ;xY w)NrY  s   ByteArrayObject)r!   r  r  byte_array_object_converter	bytearrayr   )r$   byte_arrs     r    test_byte_array_object_converterz5ClinicFunctionalTest.test_byte_array_object_converter  sT    y)11!4 */0>>xH8+V *)s   A&&A/c                     | j                  t              5  t        j                  d       d d d        | j	                  t        j                  d      d       y # 1 sw Y   /xY w)NrY  rn  )rn  )r!   r  r  unicode_converterr   rE   s    r   test_unicode_converterz+ClinicFunctionalTest.test_unicode_converter  sG    y)''* *44Y?N *)r  c                 n   | j                  t              5  t        j                  ddd       d d d        | j	                  t        j                         d       | j	                  t        j                  dg d      d       | j	                  t        j                  ddd	id
      d       y # 1 sw Y   ~xY w)NFz	not a int)TTTrP      )FFT)z	not emptyrY  r   r   )TTF)r!   r  r  bool_converterr   rE   s    r   test_bool_converterz(ClinicFunctionalTest.test_bool_converter  s    y)$$UE;? *1135GH11"b!<>RS11.1a&!LNab	 *)s   B++B4c                    | j                  t              5  t        j                  d       d d d        | j                  t              5  t        j                  d       d d d        g d}t	        d |D              }| j                  t        j                         |       g d}t	        d |D              }| j                  t        j                  | |       y # 1 sw Y   xY w# 1 sw Y   xY w)NrY  s   ab)   A         	   
            "   '   ?   \       c              3   2   K   | ]  }t        |        y wr   ordr  r   s     r   r  z;ClinicFunctionalTest.test_char_converter.<locals>.<genexpr>       /AQ   )   1   2   3   4   5   6   7   8   9   0   a   b   c   dc              3   2   K   | ]  }t        |        y wr   r  r  s     r   r  z;ClinicFunctionalTest.test_char_converter.<locals>.<genexpr>  r  r  )r!   r  r  char_convertertupler   )r$   charsr   s      r   test_char_converterz(ClinicFunctionalTest.test_char_converter  s    y)$$Q' *y)$$U+ *r///113X>d///11598D *)))s   C	C&C#&C/c                    ddl m} | j                  t              5  t	        j
                  d       d d d        | j                  t              5  t	        j
                  |dz          d d d        | j                  t              5  t	        j
                  d|dz          d d d        | j                  t              5  t	        j
                  g        d d d        | j                  t	        j
                         d       | j                  t	        j
                  dd|dz         d       | j                  t	        j
                  dd|dz   dz  dz         d	       y # 1 sw Y   )xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w)
Nr   )	UCHAR_MAXr   rY     "   8   r   r   r   rO  {   r   r   r  )	_testcapir  r!   OverflowErrorr  unsigned_char_converterr  r   )r$   r  s     r   test_unsigned_char_converterz1ClinicFunctionalTest.test_unsigned_char_converter  s   '}---b1 .}---i!m< .}---aQ? .y)--b1 *::<lK::1aQOQZ[::1a)a-STATWZAZ[]hi .-----))/   EE&E2<E>E#&E/2E;>Fc                 .   ddl m}m} | j                  t              5  t        j                  |dz
         d d d        | j                  t              5  t        j                  |dz          d d d        | j                  t              5  t        j                  g        d d d        | j                  t        j                  d      d       | j                  t        j                  d      d       y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   lxY w)Nr   )SHRT_MINSHRT_MAXrY  .r    )r  )	r  r  r  r!   r  r  short_converterr  r   )r$   r  r  s      r   test_short_converterz)ClinicFunctionalTest.test_short_converter  s    0}-%%hl3 .}-%%hl3 .y)%%b) *22598D2248'B .---))s#   C3C?
D3C<?DDc                    ddl m} | j                  t              5  t	        j
                  d       d d d        | j                  t              5  t	        j
                  |dz          d d d        | j                  t              5  t	        j
                  d|dz          d d d        | j                  t              5  t	        j
                  g        d d d        | j                  t	        j
                         d       | j                  t	        j
                  dd|dz         d       | j                  t	        j
                  dd|dz   dz  dz         d	       y # 1 sw Y   )xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w)
Nr   )	USHRT_MAXr   rY  r  r  rO  r  r  )	r  r  r!   r   r  unsigned_short_converterr  r  r   )r$   r  s     r   test_unsigned_short_converterz2ClinicFunctionalTest.test_unsigned_short_converter  s   'z*..r2 +}-..y1}= .}-..q)a-@ .y)..r2 *;;=|L;;Aq)a-PR[\;;Aq9q=TUBUX[B[\^ij +*----))r  c                    ddl m}m} | j                  t              5  t        j                  |dz
         d d d        | j                  t              5  t        j                  |dz          d d d        | j                  t              5  t        j                  ddd       d d d        | j                  t              5  t        j                  g        d d d        | j                  t        j                         d       | j                  t        j                  ddd      ddt        d      f       y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w)Nr   )INT_MININT_MAXrY  r   rO  )r  r  -   3)
r  r  r  r!   r  r  r>  r  r   r  )r$   r  r  s      r   test_int_converterz'ClinicFunctionalTest.test_int_converter  s    .}-##GaK0 .}-##GaK0 .y)##Aq!, *y)##B' *002LA00As;aCH=MN .---))))s/   D5E
E?E5D>E
EE"c                    ddl m} | j                  t              5  t	        j
                  d       d d d        | j                  t              5  t	        j
                  |dz          d d d        | j                  t              5  t	        j
                  d|dz          d d d        | j                  t              5  t	        j
                  g        d d d        | j                  t	        j
                         d       | j                  t	        j
                  dd|dz         d       | j                  t	        j
                  dd|dz   dz  dz         d	       y # 1 sw Y   )xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w)
Nr   )UINT_MAXr   rY  r  r  rO  r  r  )	r  r  r!   r   r  unsigned_int_converterr  r  r   )r$   r  s     r   test_unsigned_int_converterz0ClinicFunctionalTest.test_unsigned_int_converter  s   &z*,,R0 +}-,,X\: .}-,,Q1= .y),,R0 *99;\J99!Q1MyY99!QAQR@RUX@XY[fg +*----))r  c                 ,   ddl m}m} | j                  t              5  t        j                  |dz
         d d d        | j                  t              5  t        j                  |dz          d d d        | j                  t              5  t        j                  g        d d d        | j                  t        j                         d       | j                  t        j                  d      d       y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   kxY w)Nr   )LONG_MINLONG_MAXrY  r  r  r  )	r  r  r  r!   r  r  long_converterr  r   )r$   r  r  s      r   test_long_converterz(ClinicFunctionalTest.test_long_converter  s    0}-$$X\2 .}-$$X\2 .y)$$R( *113U;11%8(C .---))#   C2C>
D
2C;>D
Dc                    ddl m} | j                  t              5  t	        j
                  d       d d d        | j                  t              5  t	        j
                  |dz          d d d        | j                  t              5  t	        j
                  d|dz          d d d        | j                  t              5  t	        j
                  g        d d d        | j                  t	        j
                         d       | j                  t	        j
                  dd|dz         d       | j                  t	        j
                  dd|dz   dz  dz         d	       y # 1 sw Y   )xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w)
Nr   )	ULONG_MAXr   rY  r  r  rO  r  r  )	r  r  r!   r   r  unsigned_long_converterr  r  r   )r$   r  s     r   test_unsigned_long_converterz1ClinicFunctionalTest.test_unsigned_long_converter  s   'z*--b1 +}---i!m< .}---aQ? .y)--b1 *::<lK::1aQOQZ[::1a)a-STATWZAZ[]hi +*----))r  c                 ,   ddl m}m} | j                  t              5  t        j                  |dz
         d d d        | j                  t              5  t        j                  |dz          d d d        | j                  t              5  t        j                  g        d d d        | j                  t        j                         d       | j                  t        j                  d      d       y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   kxY w)Nr   )	LLONG_MIN	LLONG_MAXrY  r  r  r  )	r  r  r  r!   r  r  long_long_converterr  r   )r$   r  r  s      r   test_long_long_converterz-ClinicFunctionalTest.test_long_long_converter  s    2}-)))a-8 .}-)))a-8 .y)))"- *668%@66u=xH .---))r  c                    ddl m} | j                  t              5  t	        j
                  d       d d d        | j                  t              5  t	        j
                  |dz          d d d        | j                  t              5  t	        j
                  d|dz          d d d        | j                  t              5  t	        j
                  g        d d d        | j                  t	        j
                         d       | j                  t	        j
                  dd|dz         d       | j                  t	        j
                  dd|dz   dz  dz         d	       y # 1 sw Y   )xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w)
Nr   )
ULLONG_MAXr   rY  r  r  rO  r  r  )	r  r  r!   r   r  unsigned_long_long_converterr  r  r   )r$   r  s     r   !test_unsigned_long_long_converterz6ClinicFunctionalTest.test_unsigned_long_long_converter  s    (z*2226 +}-22:>B .}-221j1nE .y)2226 *??A<P??1jSTnUW`a??1zTU~YZFZ]`F`acno +*----))r  c                 0   ddl m}m} | j                  t              5  t        j                  |dz
         d d d        | j                  t              5  t        j                  |dz          d d d        | j                  t              5  t        j                  g        d d d        | j                  t        j                         d       | j                  t        j                  ddd       d       y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   mxY w)Nr   PY_SSIZE_T_MINPY_SSIZE_T_MAXrY  r  r   rY  r   r  )	r  r  r  r!   r  r  py_ssize_t_converterr  r   r$   r  r  s      r   test_py_ssize_t_converterz.ClinicFunctionalTest.test_py_ssize_t_converter-  s    <}-**>A+=> .}-**>A+=> .y)**2. *779<H771dCZP .---))s#   C4D 
D4C= D	Dc                    ddl m}m} | j                  t              5  t        j                  g        d d d        | j                  t        j                         d       | j                  t        j                  ddd       d       | j                  t        j                  ||dz   |dz         |||f       | j                  t        j                  ||dz
  |dz
        |||f       y # 1 sw Y   xY w)Nr   r  r  rY  r   r  i  )r  r  r  r!   r  r  slice_index_converterr   r  s      r   test_slice_index_converterz/ClinicFunctionalTest.test_slice_index_converter8  s    <y)++B/ *88:LI88AtDjQ88Z[I[]knr]rs(..I	K88Z[I[]knr]rs(..I	K *)s   C((C1c                 H   | j                  t              5  t        j                  d       d d d        | j                  t              5  t        j                  g        d d d        | j                  t        j                         d       y # 1 sw Y   axY w# 1 sw Y   :xY w)Nr   r  )r!   r   r  size_t_converterr  r   rE   s    r   test_size_t_converterz*ClinicFunctionalTest.test_size_t_converterC  sm    z*&&r* +y)&&r* *335u=	 +*))s   B	BBB!c                    | j                  t              5  t        j                  g        d d d        | j	                  t        j                         d       | j	                  t        j                  d      d       y # 1 sw Y   SxY wN)g      )@      ࿩r  )r!   r  r  float_converterr   rE   s    r   test_float_converterz)ClinicFunctionalTest.test_float_converterJ  s`    y)%%b) *224g>2248'B *)   A>>Bc                    | j                  t              5  t        j                  g        d d d        | j	                  t        j                         d       | j	                  t        j                  d      d       y # 1 sw Y   SxY wr  )r!   r  r  double_converterr   rE   s    r   test_double_converterz*ClinicFunctionalTest.test_double_converterP  s`    y)&&r* *335w?33D97C *)r  c                    | j                  t              5  t        j                  g        d d d        | j	                  t        j                  t        dd            t        dd      f       | j	                  t        j                  t        d            t        d      f       | j	                  t        j                  d      d       | j	                  t        j                  d      d       y # 1 sw Y   xY w)NrY  r   z-1-2jr  r  
   )r#  )r!   r  r  py_complex_converterr   complexrE   s    r   test_py_complex_converterz.ClinicFunctionalTest.test_py_complex_converterV  s    y)**2. *771FQRTUHXY778HIGT[L\K^_77=wG77;UC *)s   C11C:c                 p   | j                  t              5  t        j                  d       d d d        | j                  t              5  t        j                  ddd       d d d        | j                  t              5  t        j                  ddd       d d d        | j                  t        j                  ddd      d       | j                  t        j                  ddd      d       | j                  t        j                  ddd	      d
       y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w)NrY  r   r   r      b br  r   r  c cr   r   r)  )r!   r  r  rQ  r   r   rE   s    r   test_str_converterz'ClinicFunctionalTest.test_str_converter^  s    y)##A& *y)##Cc2 *z*##C#6 +00dC@/R00dDA?S00dFCEWX *)))**s#   D	D >D,D D),D5c                    | j                  t              5  t        j                  d       d d d        | j	                  t        j                  ddd      d       | j                  t              5  t        j                  ddd       d d d        | j	                  t        j                  ddt        t        d      g            d       | j	                  t        j                  ddt        t        d      dt        d      g            d	       | j	                  t        j                  ddd
      d	       y # 1 sw Y   xY w# 1 sw Y   xY w)NrY  r   r   r   r   r(  r  r   r*  s   c c)r!   r  r  str_converter_encodingr   r  r  rE   s    r   test_str_converter_encodingz0ClinicFunctionalTest.test_str_converter_encodingi  s   y),,Q/ *99#sCH/Zy),,S'3? *99#tYPSTWPXzEZ[]lm99#tYPSTWPXZ[]`ad]eOfEgh-	/99#tYOQef *) *)s   D70E7EEc           	          | j                  t              5  t        j                  dd       d d d        | j	                  t        j                  dt        g d            d       y # 1 sw Y   ;xY w)Nr   r   abcrY  r   rO  )s   abcs   )r!   r  r  py_buffer_converterr   r  rE   s    r   test_py_buffer_converterz-ClinicFunctionalTest.test_py_buffer_convertert  sQ    y)))#s3 *66ui	>RSUno *)s   A''A0c                     | j                  t        j                  dd      d       | j                  t        j                  dd      d       | j                  t        j                  dd      d       y )NrY  r   r  r   r   )r   r  keywordsrE   s    r   test_keywordsz"ClinicFunctionalTest.test_keywordsy  sY    ++Aq16:++A3V<++a15v>r   c                     | j                  t              5  t        j                  dd       d d d        | j	                  t        j                  dd      d       | j	                  t        j                  dd      d       y # 1 sw Y   XxY w)NrY  r   r5  r  r   )r!   r  r  keywords_kwonlyr   rE   s    r   test_keywords_kwonlyz)ClinicFunctionalTest.test_keywords_kwonly~  sh    y)%%a+ *221:FC22Q!<fE *)s   BBc                 $   | j                  t        j                  d      d       | j                  t        j                  dd      d       | j                  t        j                  ddd      d       | j                  t        j                  dd      d       | j                  t        j                  ddd      d       | j                  t        j                  dd	      d
       | j                  t        j                  ddd      d       y )NrY  rY  NNr   rY  r   NrO  r1  r5  r   r   r   rY  NrO  r   )r   r  keywords_optrE   s    r   test_keywords_optz&ClinicFunctionalTest.test_keywords_opt  s    //2OD//15|D//1a8)D//Q7F//1:IF//!q9<H//!qA>	Jr   c                 Z   | j                  t        j                  d      d       | j                  t        j                  dd      d       | j                  t              5  t        j                  ddd       d d d        | j                  t        j                  dd      d       | j                  t        j                  ddd      d       | j                  t        j                  dd	      d
       | j                  t        j                  dddd      d       y # 1 sw Y   xY w)NrY  rY  NNNr   rY  r   NNrO  r5  r>  rY  r   rO  Nr?  )rY  NrO  N   r   r   r   rh   rY  r   rO  rG  )r   r  keywords_opt_kwonlyr!   r  rE   s    r   test_keywords_opt_kwonlyz-ClinicFunctionalTest.test_keywords_opt_kwonly  s    66q9;PQ66q!<>PQy)))!Q2 *66qA>@RS66q!qA?S66a@BTU66a1JLY *)s   !D!!D*c                    | j                  t        j                  d      d       | j                  t              5  t        j                  dd       d d d        | j                  t        j                  dd      d       | j                  t        j                  dd      d       | j                  t        j                  ddd	      d
       y # 1 sw Y   xY w)NrY  r<  r   r5  r=  rO  r?  r@  r   r1  )r   r  keywords_kwonly_optr!   r  rE   s    r   test_keywords_kwonly_optz-ClinicFunctionalTest.test_keywords_kwonly_opt  s    66q9?Ky)))!Q/ *66qA>M66a@,O66a1EyQ	 *)s   CCc                    | j                  t              5  t        j                  d       d d d        | j                  t              5  t        j                  dd       d d d        | j	                  t        j                  dd      d       | j	                  t        j                  dd      d       y # 1 sw Y   xY w# 1 sw Y   cxY w)NrY  r   r   r  r5  )r!   r  r  posonly_keywordsr   rE   s    r   test_posonly_keywordsz*ClinicFunctionalTest.test_posonly_keywords  s    y)&&q) *y)&&a0 *33Aq96B33A;VD *)))s   B7	C7C Cc                    | j                  t              5  t        j                  d       d d d        | j                  t              5  t        j                  dd       d d d        | j                  t              5  t        j                  dd       d d d        | j	                  t        j                  dd      d       y # 1 sw Y   xY w# 1 sw Y   rxY w# 1 sw Y   IxY w)NrY  r   r   r5  r  )r!   r  r  posonly_kwonlyr   rE   s    r   test_posonly_kwonlyz(ClinicFunctionalTest.test_posonly_kwonly  s    y)$$Q' *y)$$Q* *y)$$qA. *11!q96B *)))))s#   C	C=CCCC&c                 (   | j                  t              5  t        j                  d       d d d        | j                  t              5  t        j                  ddd       d d d        | j                  t              5  t        j                  ddd       d d d        | j	                  t        j                  ddd      d       | j	                  t        j                  ddd      d       y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   rxY w)NrY  r   rO  r   r>  r1  r   r   )r!   r  r  posonly_keywords_kwonlyr   rE   s    r   test_posonly_keywords_kwonlyz1ClinicFunctionalTest.test_posonly_keywords_kwonly  s    y)--a0 *y)--aA6 *y)--Q!< *::1a1EyQ::1QGS *)))))s#   C0	C<>D0C9<DDc                    | j                  t              5  t        j                  d       d d d        | j	                  t        j                  dd      d       | j	                  t        j                  ddd      d       | j	                  t        j                  dddd      d       | j	                  t        j                  dd      d       | j	                  t        j                  ddd	      d       | j                  t              5  t        j                  dddd
       d d d        | j	                  t        j                  dddd      d       y # 1 sw Y   /xY w# 1 sw Y   @xY w)NrY  r   rE  rO  rF  rG  rI  r5  r>  rH  r   r   rh   )r!   r  r  posonly_keywords_optr   rE   s    r   test_posonly_keywords_optz.ClinicFunctionalTest.test_posonly_keywords_opt  s   y)**1- *771=?QR771a@/R771aC\R77Q?AST771BOTy)**Q!qA> *77Q!qI<X *) *)s   EE&E#&E/c                    | j                  t        j                  d      d       | j                  t        j                  dd      d       | j                  t        j                  ddd      d       | j                  t        j                  dddd      d       | j                  t              5  t        j                  dd	       d d d        | j                  t        j                  ddd
      d       | j                  t        j                  dddd      d       | j                  t              5  t        j                  dddd       d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)NrY  rD  r   rE  rO  rF  rG  rI  r5  r>  r   rh   rH  )r   r  posonly_opt_keywords_optr!   r  rE   s    r   test_posonly_opt_keywords_optz2ClinicFunctionalTest.test_posonly_opt_keywords_opt  s   ;;A>@UV;;AqACUV;;Aq!DoV;;Aq!QGVy)..qA6 *;;AqAFX;;AqAK\Zy)..a1B *)	 *) *)s   0E6E%E"%E.c                 x   | j                  t              5  t        j                  d       d d d        | j                  t              5  t        j                  dd       d d d        | j	                  t        j                  dd      d       | j	                  t        j                  ddd      d       | j	                  t        j                  dddd	      d
       | j                  t              5  t        j                  dddd       d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)NrY  r   r5  rE  rO  rV  rF  rG  rZ  rI  rH  )r!   r  r  posonly_kwonly_optr   rE   s    r   test_posonly_kwonly_optz,ClinicFunctionalTest.test_posonly_kwonly_opt  s    y)((+ *y)((A. *55a1=?QR55a1BOT55a1QGVy)((1Q!< *) *)))
 *)s#   D	D$5D0D!$D-0D9c                 @   | j                  t        j                  d      d       | j                  t        j                  dd      d       | j                  t              5  t        j                  ddd       d d d        | j                  t              5  t        j                  dd       d d d        | j                  t        j                  ddd      d       | j                  t        j                  dddd	
      d       y # 1 sw Y   xY w# 1 sw Y   gxY w)NrY  rD  r   rE  rO  r5  r>  rF  rG  r^  rI  )r   r  posonly_opt_kwonly_optr!   r  rE   s    r   test_posonly_opt_kwonly_optz0ClinicFunctionalTest.test_posonly_opt_kwonly_opt  s    99!<>ST99!Q?ASTy),,Q15 *y),,Q!4 *99!Q!DoV99!Q!qI<X *)))s   !DDDDc           	         | j                  t              5  t        j                  d       d d d        | j                  t              5  t        j                  dd       d d d        | j                  t              5  t        j                  dd       d d d        | j                  t              5  t        j                  ddd       d d d        | j                  t              5  t        j                  ddd       d d d        | j	                  t        j                  ddd      d       | j	                  t        j                  ddd      d       | j	                  t        j                  dddd	
      d       | j	                  t        j                  dddd	d      d       y # 1 sw Y   xY w# 1 sw Y   [xY w# 1 sw Y   3xY w# 1 sw Y   xY w# 1 sw Y   xY w)NrY  r   r5  rO  r   r>  rY  r   rO  NNrV  rG  r^  rY  r   rO  rG  Nr  r   rh   erY  r   rO  rG  r  )r!   r  r  posonly_keywords_kwonly_optr   rE   s    r    test_posonly_keywords_kwonly_optz5ClinicFunctionalTest.test_posonly_keywords_kwonly_opt  s_   y)11!4 *y)11!Q7 *y)11!q9 *y)11!Q: *y)11Aa@ *>>q!qIK`a>>qAKMbc>>q!qANPbc>>q!qAQRSUde *)))))))))s;   F,	F9=G2G'G ,F69GGG G)c           	         | j                  t              5  t        j                  d       d d d        | j	                  t        j                  dd      d       | j	                  t        j                  dd      d       | j                  t              5  t        j                  dddd       d d d        | j                  t              5  t        j                  dd       d d d        | j	                  t        j                  ddd      d	       | j	                  t        j                  ddd
      d	       | j	                  t        j                  dddd      d       | j	                  t        j                  dddd      d       | j	                  t        j                  ddddd      d       | j	                  t        j                  ddddd      d       y # 1 sw Y   xY w# 1 sw Y   CxY w# 1 sw Y   xY w)NrY  r   )rY  r   NNNr5  rO  rG  r   r>  rh  rV  rh   ri  r^  r  rh   rk  rl  rj  )r!   r  r  posonly_keywords_opt_kwonly_optr   rE   s    r   $test_posonly_keywords_opt_kwonly_optz9ClinicFunctionalTest.test_posonly_keywords_opt_kwonly_opt  s   y)55a8 *BB1aHJbcBB1JLdey)55aAqA *y)55Q? *BB1a1MOdeBB1QOQfgBB1aaPRdeBB1a1PQRTfgBB1aaSTUWfgBB1a1PQUVWYhi *) *)))s#   G#G0G=#G-0G:=Hc                    | j                  t        j                  d      d       | j                  t        j                  dd      d       | j                  t              5  t        j                  dd       d d d        | j                  t        j                  ddd      d       | j                  t        j                  ddd      d       | j                  t        j                  dddd	
      d       | j                  t        j                  dddd	      d       | j                  t              5  t        j                  dddd	       d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)NrY  rD  r   rE  r5  rO  rF  r>  rG  rp  rI  r^  )r   r  #posonly_opt_keywords_opt_kwonly_optr!   r  rE   s    r   (test_posonly_opt_keywords_opt_kwonly_optz=ClinicFunctionalTest.test_posonly_opt_keywords_opt_kwonly_opt  s!   FFqIK`aFFq!LN`ay)99!qA *FFq!QOQ`aFFq!qQSbcFFq!QRSTVbcFFq!qTUVXdey)99!Q1E *) *) *)s   !E7E%E"%E.c                 J   | j                  t              5  t        j                          d d d        | j                  t              5  t        j                  d       d d d        | j	                  t        j                  d      d       y # 1 sw Y   cxY w# 1 sw Y   <xY w)NrY  r   rY  )r!   r  r  keyword_only_parameterr   rE   s    r   test_keyword_only_parameterz0ClinicFunctionalTest.test_keyword_only_parameter  sm    y),,. *y),,Q/ *99A>E	 *)))s   BBBB"c                 j   | j                  t              5  t        j                          d d d        | j	                  t        j                  dd      d       | j	                  t        j                  dd      d       | j	                  t        j                  dddd      d       y # 1 sw Y   xY w)NrY  r   )rY  r   r0   r5  rO  rG  )rY  r   )rO  rG  )r!   r  r  posonly_varargr   rE   s    r   test_posonly_varargz(ClinicFunctionalTest.test_posonly_vararg  s    y)$$& *11!Q7D11!q9:F11!Q1=~N	 *)s   B))B2c                 R   | j                  t              5  t        j                          d d d        | j                  t              5  t        j                  dd       d d d        | j	                  t        j                  dddd      d       y # 1 sw Y   gxY w# 1 sw Y   >xY wNrY  r   r5  rO  rG  )rY  r   rO  rG  )r!   r  r  vararg_and_posonlyr   rE   s    r   test_vararg_and_posonlyz,ClinicFunctionalTest.test_vararg_and_posonly!  su    y)((* *y)((a0 *55aAqA>R	 *)))   BBBB&c                 R   | j                  t              5  t        j                          d d d        | j                  t              5  t        j                  dd       d d d        | j	                  t        j                  dddd      d       y # 1 sw Y   gxY w# 1 sw Y   >xY wr  )r!   r  r  varargr   rE   s    r   test_varargz ClinicFunctionalTest.test_vararg(  su    y) *y)Q!$ *))!Q15~F	 *)))r  c           	         t         j                  }| j                  t        |       | j                  t        |dd       | j	                   |dd      d       | j	                   |dddd      d       | j	                   |ddddd	      d
       | j	                   |d      d       | j	                   |dd      d       y )NrY  r   r   r5  )rY  r0   TrO  rG  )rY  r  Fr  )rY  r  T)rY  r0   Fr   )r  vararg_with_defaultr!   r  r   r   s     r   test_vararg_with_defaultz-ClinicFunctionalTest.test_vararg_with_default/  s    **)R()Ra0A]3Aq!Q)>?Aq!Q!,.BCa.1a1}5r   c           	      .   t         j                  }| j                  t        |       | j                  t        |dd       | j	                   |dd      d       | j	                   |ddd      d       | j	                   |ddd      d	       | j	                   |dddd
      d       | j	                   |dddd
d      d       | j	                   |d      d       | j	                   |dd      d       | j	                   |ddd      d       y )NrY  r   r   r5  )rY  r0   r   NrO  rV  )rY  r0   r   rO  )rY  r   rO  NNrG  )rY  r  rG  Nr  )rY  r  rG  r  )rY  r0   NNr   r   )r  vararg_with_default2r!   r  r   r   s     r   test_vararg_with_default2z.ClinicFunctionalTest.test_vararg_with_default29  s    ++)R()Ra0A%56Aa-8Aq!&=>Aq!q)+?@Aq!qA.0ABa"56a1'78a1*M:r   c           	         | j                  t        j                         d       | j                  t        j                  d      d       | j                  t        j                  dd      d       | j                  t        j                  dddd      d	       | j                  t        j                  ddddd
      d       y )N)r0   Nr   r5  )r0   r   rY  )rx  r   rO  rG  )rI  Nr  )rI  r  )r   r  vararg_with_only_defaultsrE   s    r   test_vararg_with_only_defaultsz3ClinicFunctionalTest.test_vararg_with_only_defaultsF  s    <<>
K<<qA7K<<Q!DjQ<<Q1aHJ^_<<Q1a1MO`ar   c                 :    t        j                  dddddd       y )NrY  r   rO  rG  r     )kw1kw2)r  gh_32092_oobrE   s    r   test_gh_32092_oobz&ClinicFunctionalTest.test_gh_32092_oobM  s    q!Qqa8r   c                 2    t        j                  ddd       y )NrY  r   rO  )r  gh_32092_kw_passrE   s    r   test_gh_32092_kw_passz*ClinicFunctionalTest.test_gh_32092_kw_passP  s    ""1a+r   c                     d}t        j                  |      }t        j                  |       t        j                  |      }| j	                  ||       y )Nz5*A unique string is not referenced by anywhere else.*)rj   getrefcountr  gh_99233_refcountr   )r$   argarg_refcount_originarg_refcount_afters       r   test_gh_99233_refcountz+ClinicFunctionalTest.test_gh_99233_refcountS  sE    E!ooc2##C( __S1,.@Ar   c                     d}| j                  t        |      5  t        j                  dd       d d d        y # 1 sw Y   y xY w)NzVgh_99240_double_free\(\) argument 2 must be encoded string without null bytes, not strr   z b)r  r  r  gh_99240_double_free)r$   expected_errors     r   test_gh_99240_double_freez.ClinicFunctionalTest.test_gh_99240_double_freeZ  s3    r##I~>**36 ?>>s	   9Ac                    d}| j                  t        d      5  t        j                  |       d d d        | j                  t        d      5  t        j                  |       d d d        y # 1 sw Y   >xY w# 1 sw Y   y xY w)Nr   clone_f1clone_f2)r  r  r  r  r  )r$   incorrect_args     r   "test_cloned_func_exception_messagez7ClinicFunctionalTest.test_cloned_func_exception_message_  s`    ##Iz:}- ;##Iz:}- ;: ;:::s   A,A8,A58Bc                     dD ]D  }| j                  |      5  t        t        |      }| j                   |       |       d d d        F y # 1 sw Y   QxY w)N)clone_with_conv_f1clone_with_conv_f2r;   )r   r  r  r   )r$   r4   funcs      r   1test_cloned_func_with_converter_exception_messagezFClinicFunctionalTest.test_cloned_func_with_converter_exception_messagef  sG    >D4(y$/  . )( ?((r  c                     t        j                         }|j                  }t        | j                  t
        d      } ||d        ||d       y )Nno argumentsrY  r   )r  	TestClassmeth_method_no_paramsr   r  r  )r$   objmethchecks       r   test_meth_method_no_paramsz/ClinicFunctionalTest.test_meth_method_no_paramsl  sB    !!#((..	>JdAdar   c                    ddl m} t        j                         }|j                  } ||d d         ||dd         ||dd        ||d d       t        | j                  t        d      } |||dd         |||dd       y )Nr   )pyobject_vectorcallr0   r  rx  r   )r  r  r  r  r  r   r  r  )r$   r  r  r  r  s        r   test_meth_method_no_params_capiz4ClinicFunctionalTest.test_meth_method_no_params_capis  s    1!!#((D$-D"d+D"b)D$+..	>J!4t4!4v6r   N)=r,   r-   r.   localsr   dirr  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r	  r  r  r  r  r!  r&  r+  r.  r3  r7  r:  rB  rK  rN  rQ  rT  rX  r\  r`  rc  rf  rn  rs  rv  rz  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r0   r   r   r  r    s\   
HOO L #IL LD^
WO
c
Ej	CkOh	Dj	Ip	Q	K>CDD	Y	gp
?
FKZRECT
Y
C	=Yf j 
FFOSG6;b9,B7
./7r   r  c                        e Zd Z	 d Zd Zd Zy)PermutationTestsc                     d}t        t        g d            }t        t        j                  |            }| j                  ||       y )N)r0   )rO  r  r1  r1  )r  rw  r  r   permute_left_option_groupsr   r$   r   datar  s       r   test_permute_left_option_groupsz0PermutationTests.test_permute_left_option_groups  s>    
 C	N#v88>?*r   c                     d}t        t        g d            }t        t        j                  |            }| j                  ||       y )N)r0   rx  r  r1  r1  )r  rw  r  r   permute_right_option_groupsr   r  s       r    test_permute_right_option_groupsz1PermutationTests.test_permute_right_option_groups  s>    
 C	N#v99$?@*r   c           	         ddddd}ddddd}dddd	d}ddd
dd}ddddd}ddddd}ddddd}ddddd}ddddd}	|||||||||	f	}
|
D ]f  } | j                   di |5  |j                         \  }}}}t        j                  |||      }t	        |      }| j                  ||       d d d        h y # 1 sw Y   sxY w)Nr0   )r0   )leftrequiredrightr   r5  r>  )r5  rV  rV  rp  )rV  rZ  rq  )rV  rZ  )r   r   rh   rk  r   )r5  r   )rV  r   r   )r>  rV  r   )r5  r   r   r^  )rk  r  )r^  rZ  rH  )r   r   r   rh   rk  )r   r   r   rh   rk  r  )r   r  r   r   r  r   )r$   emptynoleft1noleft2noleft3noright1noright2noright3leftandright1leftandright2r~  r  r  r  r  r   permutationsr  s                     r   test_permute_optional_groupsz-PermutationTests.test_permute_optional_groups  sH   B

 FV
 K&
 K*
 
 
R
 FR
 
 J	
 Wgh=	
 F''28--//hx%==dHeT|,  2	 (' ''s   "A
B77C 	N)r,   r-   r.   r  r  r  r0   r   r   r  r    s    -	+	+N3r   r  c                   <    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
y	)
FormatHelperTestsc                     d}|D ]H  \  }}| j                  ||      5  t        j                  |      }| j                  ||       d d d        J y # 1 sw Y   UxY w)N)	)a
br  )za
b
r  )za
b r  )z
a
b

r  )z

a
b

r  )z

a

b

za

b) a
br  )z a
b r  )z 
 
 a
b 
 
 r  )r{  r   )r   r   &strip_leading_and_trailing_blank_linesr   )r$   r~  r{  r   r   s        r   +test_strip_leading_and_trailing_blank_linesz=FormatHelperTests.test_strip_leading_and_trailing_blank_lines  sX    
  'OE8EH=CCEJ  h/ >=  '==   (AA	c                     d}d}d}d}|||d}|j                         D ]I  \  }}| j                  |      5  t        j                  ||      }| j	                  ||       d d d        K y # 1 sw Y   VxY w)Nz;
            one
            two
            three
        zone
two
threez    one
    two
    threez%        one
        two
        three)r   rG     )indent)itemsr   r   normalize_snippetr   )	r$   snippetzero_indentfour_indenteight_indentexpected_outputsr  r   r  s	            r   test_normalize_snippetz(FormatHelperTests.test_normalize_snippet 	  s     	 	 	
  +{|L 0 6 6 8FHV,11'&I  2 -, !9,,s   *A,,A5	c                 t   t        j                         }| j                  |j                         d       |j	                  d       | j                  |j                         d       | j                  |j                         d       |j	                  d       | j                  |j                         d       | j                  |j                         d       |j	                  d       |j	                  d       | j                  |j                         d       | j                  |j                         d       y )NrP   r   r   r   rh   cd)r   text_accumulatorr   r   append)r$   accs     r   test_accumulatorz"FormatHelperTests.test_accumulator	  s    %%'r*

3s+r*

3s+r*

3

3t,r*r   c                     d}|D ]H  \  }}| j                  ||      5  t        j                  |      }| j                  ||       d d d        J y # 1 sw Y   UxY w)N))r0  r0  )z\abcz\\abc)z\a\bcz\\a\\bc)z\a\\bcz	\\a\\\\bc)z"abc"z\"abc\")z'a'z\'a\')r|  r   )r   r   quoted_for_c_stringr   )r$   r~  r|  r   r   s        r   test_quoted_for_c_stringz*FormatHelperTests.test_quoted_for_c_string+	  sX    
 &ND(4(;006  h/ <; &;;r  c                 Z    d}d}t        j                  |      }| j                  ||       y )Nza 
b
 c
 d 
z
a
b
 c
 d
)r   rstrip_linesr   r$   r{  r   r   s       r   test_rstrip_linesz#FormatHelperTests.test_rstrip_lines:	  s8     	 	 !!%(h'r   c                 Z    d}d}t        j                  |      }| j                  ||       y )Nz{}, {a}z{{}}, {{a}})r   format_escaper   )r$   r|  r   r   s       r   test_format_escapez$FormatHelperTests.test_format_escapeJ	  s,     ""4(h'r   c                    | j                  t        j                  dd      d       d}d}t        j                  |d      }| j                  ||       d}d}t        j                  |d      }| j                  ||       y )NrP   bar)prefixone
twozbarone
bartwo	
one
two
zbar
barone
bartwo
)r   r   indent_all_linesr  s       r   test_indent_all_linesz'FormatHelperTests.test_indent_all_linesP	      00EBBG 	
 	 %%eE:h' 	 	 %%eE:h'r   c                    | j                  t        j                  dd      d       d}d}t        j                  |d      }| j                  ||       d}d}t        j                  |d      }| j                  ||       y )NrP   foo)suffixr  zonefoo
twofoor  zfoo
onefoo
twofoo
)r   r   suffix_all_linesr  s       r   test_suffix_all_linesz'FormatHelperTests.test_suffix_all_lineso	  r  r   N)r,   r-   r.   r  r  r  r  r  r  r  r  r0   r   r   r  r    s*    0&3:+0( ((>(r   r  __main__)2	functoolsr   testr   r   test.supportr   test.support.os_helperr   r   textwrapr	   unittestr
   r_   ro  os.pathr1  r  rj   skip_if_missingimports_under_toolr   r   r   r   r   r2   r9   rB   rw   r   rN   rz   r   r   r  r  r  r*  r  _testclinicr  ImportErrorskipIfr  r  r  r,   mainr0   r   r   <module>r     s  
  $ " 1       
  
  8 $"Z""8,  -
&
9
G( 
G 0 0Q Q FMM362-8 -8`d + d N-*h -*`2&X 2&h # #:H :zi+{ i+XE  E P# d"$<=s78,, s7 >s7lg3x(( g3Ta()) a(H zHMMO yK -,h3  Is   %FF FF&%F&