o
    GXh#                     @   s  d dl mZmZ d dlmZ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ed ed d dlZd dlmZ W d   n1 sIw   Y  G dd dZG d	d
 d
ZG dd dZejdddZG dd dZG dd deZG dd deZG dd deZG dd dZG dd dZG dd deZG dd deZG d d! d!eZed"Z G d#d$ d$ejZ!e"d%kre#  dS dS )&    )support
test_tools)import_helper	os_helper)TestCaseNclinic)	DSLParserc                   @      e Zd Zdd ZdS )FakeConverterc                 C   s   || _ || _d S N)nameargsselfr   r    r   :/opt/python-3.10.19/usr/lib/python3.10/test/test_clinic.py__init__   s   
zFakeConverter.__init__N)__name__
__module____qualname__r   r   r   r   r   r
          r
   c                   @      e Zd Zdd Zdd ZdS )FakeConverterFactoryc                 C   s
   || _ d S r   r   r   r   r   r   r   r         
zFakeConverterFactory.__init__c                 K   s   t | j|S r   )r
   r   )r   r   defaultkwargsr   r   r   __call__      zFakeConverterFactory.__call__N)r   r   r   r   r   r   r   r   r   r          r   c                   @   r   )FakeConvertersDictc                 C   s
   i | _ d S r   )used_convertersr   r   r   r   r   #   r   zFakeConvertersDict.__init__c                 C   s   | j |t|S r   )r"   
setdefaultr   )r   r   r   r   r   r   get&   s   zFakeConvertersDict.getN)r   r   r   r   r%   r   r   r   r   r!   "   r    r!   Cfile)languagefilenamec                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zej	j
Z
dS )
FakeClinicc                 C   s   t  | _t  | _td | _d | _i | _td| j| _	t
 | _t
 | _| t_d| _d | _| _i | _| dd | dd | dd | jj}t
d|dfd|dfd	|dfd
|dfd|dfd|dfd|dff| _d S )N r*   blockbufferr'   suppressZdocstring_prototypeZdocstring_definitionZmethoddef_defineZimpl_prototypeZparser_prototypeZparser_definitionZimpl_definition)r!   Z
convertersZlegacy_convertersr   	CLanguager(   r)   Zdestination_buffersBlockParserZblock_parsercollectionsOrderedDictmodulesZclassesr   Zline_prefixZline_suffixdestinationsadd_destinationr%   Zfield_destinations)r   dr   r   r   r   ,   s2   








zFakeClinic.__init__c                 C   s&   | j |}|stdt|  |S )NzDestination does not exist: )r4   r%   sysexitrepr)r   r   r6   r   r   r   get_destinationG   s   zFakeClinic.get_destinationc                 G   s<   || j v rtdt|  tj||| g|R  | j |< d S )NzDestination already exists: )r4   r7   r8   r9   r   ZDestination)r   r   typer   r   r   r   r5   M   s   
 zFakeClinic.add_destinationc                 C   s   |dkS )Nmoduler   r   r   r   r   is_directiveR   s   zFakeClinic.is_directivec                 C   s   || j |< d S r   )Zcalled_directivesr   r   r   r   	directiveU      zFakeClinic.directiveN)r   r   r   r   r:   r5   r=   r>   r   ClinicZ_module_and_classr   r   r   r   r*   +   s    r*   c                   @   r	   )ClinicWholeFileTestc                 C   sN   t jt d dd}d}|| }|d  }| |d | |d d S )Nr'   r)   z/*[clinic]
foo
[clinic]*/   z[clinic]*/[clinic]*/z
[clinic]*/)r   r@   r/   parse
splitlinesrstripZassertNotEqualassertEqual)r   crawZcookedZend_liner   r   r   test_eol[   s   	zClinicWholeFileTest.test_eolN)r   r   r   rJ   r   r   r   r   rA   Z   r   rA   c                   @   <   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )ClinicGroupPermuterTestc                 C   s   t |||}| || d S r   )r   permute_optional_groupsrG   )r   lmroutputcomputedr   r   r   _testp   s   zClinicGroupPermuterTest._testc                 C   s   |  dggdgdggd d S )Nstartstopstep))rU   )rT   rU   )rT   rU   rV   rS   r#   r   r   r   
test_ranget   s   z"ClinicGroupPermuterTest.test_rangec                 C   s    |  ddggdgdggd d S )Nxychattr))r[   )r[   r\   )rY   rZ   r[   )rY   rZ   r[   r\   rW   r#   r   r   r   test_add_window|      z'ClinicGroupPermuterTest.test_add_windowc                 C   s.   |  g dddggdgddgg dgd d S )	N)a1a2a3b1b2c1d1d2)e1e2e3))rd   )rb   rc   rd   )rb   rc   rd   re   rf   )r_   r`   ra   rb   rc   rd   )r_   r`   ra   rb   rc   rd   re   rf   )r_   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   rW   r#   r   r   r   test_ludicrous   s   $z&ClinicGroupPermuterTest.test_ludicrousc                 C   s    |  g g dgdgdggd d S )NabrH   )r   rk   rk   rl   rk   rl   rH   rW   r#   r   r   r   test_right_only   r^   z'ClinicGroupPermuterTest.test_right_onlyc                 C   s   dd }|  t| d S )Nc                   S   s   t dgg g  d S )Nrk   )r   rM   r   r   r   r   fn   s   zPClinicGroupPermuterTest.test_have_left_options_but_required_is_empty.<locals>.fn)assertRaisesAssertionError)r   rq   r   r   r   ,test_have_left_options_but_required_is_empty   s   zDClinicGroupPermuterTest.test_have_left_options_but_required_is_emptyN)	r   r   r   rS   rX   r]   rj   rp   rt   r   r   r   r   rL   o   s    		rL   c                   @   sD   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dS )ClinicLinearFormatTestc                 K   s"   t j|fi |}| || d S r   )r   Zlinear_formatrG   )r   inputrQ   r   rR   r   r   r   rS      s   zClinicLinearFormatTest._testc                 C      |  dd d S )Nr+   rW   r#   r   r   r   test_empty_strings      z)ClinicLinearFormatTest.test_empty_stringsc                 C   rw   )N
rW   r#   r   r   r   test_solo_newline   ry   z(ClinicLinearFormatTest.test_solo_newlinec                 C   rw   )Nz
          abc
          rW   r#   r   r   r   test_no_substitution   s   z+ClinicLinearFormatTest.test_no_substitutionc                 C      | j dddd d S )N8
          abc
          {name}
          def
          z'
          abc
          def
          r+   r   rW   r#   r   r   r   test_empty_substitution   s   
z.ClinicLinearFormatTest.test_empty_substitutionc                 C   r}   )Nr~   z8
          abc
          GARGLE
          def
          ZGARGLEr   rW   r#   r   r   r   test_single_line_substitution   s   
z4ClinicLinearFormatTest.test_single_line_substitutionc                 C   r}   )Nr~   zJ
          abc
          bingle
          bungle

          def
          zbingle
bungle
r   rW   r#   r   r   r   test_multiline_substitution   s   
z2ClinicLinearFormatTest.test_multiline_substitutionN)
r   r   r   rS   rx   r{   r|   r   r   r   r   r   r   r   ru      s    
ru   c                   @   r   )InertParserc                 C      d S r   r   r   r   r   r   r   r         zInertParser.__init__c                 C   r   r   r   r   r,   r   r   r   rD      r   zInertParser.parseNr   r   r   r   rD   r   r   r   r   r      r    r   c                   @   r   )
CopyParserc                 C   r   r   r   r   r   r   r   r      r   zCopyParser.__init__c                 C   s   |j |_d S r   )rv   rQ   r   r   r   r   rD      r   zCopyParser.parseNr   r   r   r   r   r      r    r   c                   @   rK   )ClinicBlockParserTestc                 C   sj   t d }tt ||}t |}|D ]}|| q|j }||ks3J dt| d t| d S )Nzoutput != input!

output z	

 input )	r   r/   listr0   ZBlockPrinterZprint_blockfgetvaluer9   )r   rv   rQ   r(   Zblockswriterr,   r   r   r   rS      s   


(zClinicBlockParserTest._testc                 C   s   |  ||S r   rW   )r   rv   r   r   r   
round_trip   r   z ClinicBlockParserTest.round_tripc                 C      |  d d S )Nz(
    verbatim text here
    lah dee dah
r   r#   r   r   r   test_round_trip_1   r?   z'ClinicBlockParserTest.test_round_trip_1c                 C   r   )Nz
    verbatim text here
    lah dee dah
/*[inert]
abc
[inert]*/
def
/*[inert checksum: 7b18d017f89f61cf17d47f92749ea6930a3f1deb]*/
xyz
r   r#   r   r   r   test_round_trip_2   r?   z'ClinicBlockParserTest.test_round_trip_2c                 C   sN   t d }t j|dd}t||jd< t||jd< ||}| || d S )Nr'   rB   Zinertcopy)r   r/   r@   r   parsersr   rD   rG   )r   rv   rQ   r(   rH   rR   r   r   r   _test_clinic  s   

z"ClinicBlockParserTest._test_clinicc                 C   s   |  dd d S )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   r#   r   r   r   test_clinic_1	  s   	z#ClinicBlockParserTest.test_clinic_1N)	r   r   r   rS   r   r   r   r   r   r   r   r   r   r      s    
r   c                   @   sf  e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Z d=d> Z!d?d@ Z"dAdB Z#dCdD Z$dEdF Z%dGdH Z&dIdJ Z'dKdL Z(dMdN Z)dOdP Z*dQdR Z+dZdUdVZ,dWdX Z-dYS )[ClinicParserTestc                 C   sH   t t }td}|| |j\}}| d|j | d|j d S )Nzmodule os
os.accessaccessos)r   r*   r   BlockrD   
signaturesrG   r   )r   parserr,   r<   functionr   r   r   test_trivial   s   



zClinicParserTest.test_trivialc                 C   s4   |  d}|j\}}| d|j | d|j d S )Nz#
module os
os.accessr   r   )rD   r   rG   r   r   r,   r<   r   r   r   r   test_ignore_line(  s   

z!ClinicParserTest.test_ignore_linec                 C   sV   |  d}| d|j | dt|j |jd }| d|j | |jtj d S )Nz module os
os.access
   path: intr   rC   path)	parse_functionrG   r   len
parametersassertIsInstance	converterr   int_converterr   r   pr   r   r   
test_param.  s   

zClinicParserTest.test_paramc                 C   &   |  d}|jd }| d|j d S )Nz4module os
os.access
    follow_symlinks: bool = Truefollow_symlinksTr   r   rG   r   r   r   r   r   test_param_default6     

z#ClinicParserTest.test_param_defaultc                 C   r   )NzCmodule os
os.access
    follow_symlinks: \
   bool \
   =\
    Truer   Tr   r   r   r   r   test_param_with_continuations;  r   z.ClinicParserTest.test_param_with_continuationsc                 C   sN   |  d}|jd }| tj|j | d|jj | d}| |d d S )NzOmodule os
os.access
    follow_symlinks: int(c_default='MAXSIZE') = sys.maxsizer   ZMAXSIZEz:module os
os.access
    follow_symlinks: int = sys.maxsizez~Error on line 0:
When you specify a named constant ('sys.maxsize') as your default value,
you MUST specify a valid c_default.
)	r   r   rG   r7   maxsizer   r   Z	c_defaultparse_function_should_fail)r   r   r   sr   r   r   test_param_default_expression@  s   


z.ClinicParserTest.test_param_default_expressionc                 C   s@   |  d}|jd }| dt|j | |jd jtj d S )NzR
module os
os.access
    follow_symlinks: bool = True
    something_else: str = ''r      Zsomething_else)r   r   rG   r   r   r   r   str_converterr   r   r   r   test_param_no_docstringI  s   

z(ClinicParserTest.test_param_no_docstringc                 C      |  d}| |d d S )NzM
module os
os.access
    follow_symlinks: bool = True
    something_else: strzoError on line 0:
Can't have a parameter without a default ('something_else')
after a parameter with a default!
r   rG   r   r   r   r   r   *test_param_default_parameters_out_of_orderS  s   
z;ClinicParserTest.test_param_default_parameters_out_of_orderc                 C   s,   |  d}|jd }| d|jjd  d S )Nz0module os
os.access
    path: path_t(allow_fd=1)r      Zallow_fd)r   r   rG   r   r   r   r   r   r   !disabled_test_converter_arguments^  s   

z2ClinicParserTest.disabled_test_converter_argumentsc                 C       |  d}| d |j d S )Nzx
module os
os.stat as os_stat_fn

   path: str
       Path to be examined

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

Perform a stat system call on the given path.

  path
    Path to be examined
r   rG   strip	docstringr   r   r   r   r   test_function_docstringc  s   
z(ClinicParserTest.test_function_docstringc                 C   r   )Nz|
module foo
foo.bar
  x: int
     Documentation for x.
  y: int

This is the documentation for foo.

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

This is the documentation for foo.

  x
    Documentation for x.

Okay, we're done here.
r   r   r   r   r   %test_explicit_parameters_in_docstringv  s   

z6ClinicParserTest.test_explicit_parameters_in_docstringc                 C      |  d}| d|j d S )Nz<
module os
os.stat
    path: str
This/used to break Clinic!
z5stat($module, /, path)
--

This/used to break Clinic!)r   rG   r   r   r   r   r   Ttest_parser_regression_special_character_in_parameter_column_of_docstring_first_line  s   
zeClinicParserTest.test_parser_regression_special_character_in_parameter_column_of_docstring_first_linec                 C   r   )Nzmodule os
os.stat as os_stat_fnZ
os_stat_fn)r   rG   Z
c_basenamer   r   r   r   test_c_name  s   
zClinicParserTest.test_c_namec                 C   s   |  d}| |jtj d S )Nzmodule os
os.stat -> int)r   r   Zreturn_converterr   Zint_return_converterr   r   r   r   test_return_converter  s   
z&ClinicParserTest.test_return_converterc                 C   s8   |  d}|jd }| tjj|j | d|j d S )Nz:module os
os.access
    *
    follow_symlinks: bool = Truer   r   )r   r   rG   inspect	ParameterZKEYWORD_ONLYkindgroupr   r   r   r   	test_star  s   

zClinicParserTest.test_starc                 C   r   )Nz/module window
window.border
 [
 ls : int
 ]
 /
Zlsr   )r   r   rG   r   r   r   r   r   
test_group  r   zClinicParserTest.test_groupc                 C   \   |  d}dD ]\}}|j| }| |j| | |jtjj q| |j	 d	  d S )Nz
module curses
curses.addch
   [
   y: int
     Y-coordinate.
   x: int
     X-coordinate.
   ]
   ch: char
     Character to add.
   [
   attr: long
     Attributes for the character.
   ]
   /
))rZ   )rY   r   r[   r   )r\   r   z
addch([y, x,] ch, [attr])


  y
    Y-coordinate.
  x
    X-coordinate.
  ch
    Character to add.
  attr
    Attributes for the character.
            
r   r   rG   r   r   r   r   ZPOSITIONAL_ONLYr   r   r   r   r   r   r   r   r   r   test_left_group  s   

z ClinicParserTest.test_left_groupc                 C   r   )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.
   ]
   ]
   /
))Zy1)Zy2r   )Zx1r   )Zx2r   r   )Zattr1r   )Zattr2r   )Zattr3r   )Zattr4rC   )Zattr5rC   )Zattr6rC   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   r   r   r   test_nested_groups  s   
#
z#ClinicParserTest.test_nested_groupsc              	   C   s~   t  /}| t | | W d    n1 sw   Y  W d    | S W d    | S 1 s6w   Y  | S r   )r   captured_stdoutrr   
SystemExitr   r   )r   r   stdoutr   r   r   r     s   


z+ClinicParserTest.parse_function_should_failc                 C   r   )Nz|
module foo
foo.two_top_groups_on_left
    [
    group1 : int
    ]
    [
    group2 : int
    ]
    param: int
            zpError on line 0:
Function two_top_groups_on_left has an unsupported group configuration. (Unexpected state 2.b)
r   r   r   r   r   0test_disallowed_grouping__two_top_groups_on_left$  s   
zAClinicParserTest.test_disallowed_grouping__two_top_groups_on_leftc                 C   r   )Nz}
module foo
foo.two_top_groups_on_right
    param: int
    [
    group1 : int
    ]
    [
    group2 : int
    ]
            r   r#   r   r   r   1test_disallowed_grouping__two_top_groups_on_right4  r?   zBClinicParserTest.test_disallowed_grouping__two_top_groups_on_rightc                 C   r   )Nz
module foo
foo.parameter_after_group_on_right
    param: int
    [
    [
    group1 : int
    ]
    group2 : int
    ]
            r   r#   r   r   r   8test_disallowed_grouping__parameter_after_group_on_rightA  r?   zIClinicParserTest.test_disallowed_grouping__parameter_after_group_on_rightc                 C   r   )Nz
module foo
foo.group_after_parameter_on_left
    [
    group2 : int
    [
    group1 : int
    ]
    ]
    param: int
            r   r#   r   r   r   7test_disallowed_grouping__group_after_parameter_on_leftN  r?   zHClinicParserTest.test_disallowed_grouping__group_after_parameter_on_leftc                 C   r   )Nz`
module foo
foo.empty_group
    [
    [
    ]
    group2 : int
    ]
    param: int
            r   r#   r   r   r   -test_disallowed_grouping__empty_group_on_left[  r?   z>ClinicParserTest.test_disallowed_grouping__empty_group_on_leftc                 C   r   )Nz`
module foo
foo.empty_group
    param: int
    [
    [
    ]
    group2 : int
    ]
            r   r#   r   r   r   .test_disallowed_grouping__empty_group_on_rightg  r?   z?ClinicParserTest.test_disallowed_grouping__empty_group_on_rightc                 C   s.   |  d}| d|j | dt|j d S )Nz 
module foo
foo.bar

Docstring

zbar($module, /)
--

Docstringr   r   rG   r   r   r   r   r   r   r   test_no_parameterss  s   
z#ClinicParserTest.test_no_parametersc                 C   s4   | j dddd}| d|j | dt|j d S )NzL
module foo
class foo.Bar "unused" "notneeded"
foo.Bar.__init__

Docstring

r   rC   )signatures_in_blockfunction_indexzBar()
--

Docstringr   r   r   r   r   r   test_init_with_no_parameters~  s
   	z-ClinicParserTest.test_init_with_no_parametersc                 C   r   )Nz!
module foo
foo.bar => int
    /
r   r#   r   r   r   test_illegal_module_line  r?   z)ClinicParserTest.test_illegal_module_linec                 C   r   )Nz!
module foo
foo.bar as 935
    /
r   r#   r   r   r   test_illegal_c_basename  r?   z(ClinicParserTest.test_illegal_c_basenamec                 C   r   )Nz 
module foo
foo.bar
    *
    *
r   r#   r   r   r   test_single_star  r?   z!ClinicParserTest.test_single_starc                 C   r   )Nz
module foo
foo.bar
    *
r   r#   r   r   r   Ktest_parameters_required_after_star_without_initial_parameters_or_docstring  r?   z\ClinicParserTest.test_parameters_required_after_star_without_initial_parameters_or_docstringc                 C   r   )Nz*
module foo
foo.bar
    *
Docstring here.
r   r#   r   r   r   Mtest_parameters_required_after_star_without_initial_parameters_with_docstring  r?   z^ClinicParserTest.test_parameters_required_after_star_without_initial_parameters_with_docstringc                 C   r   )Nz(
module foo
foo.bar
    this: int
    *
r   r#   r   r   r   Mtest_parameters_required_after_star_with_initial_parameters_without_docstring  r?   z^ClinicParserTest.test_parameters_required_after_star_with_initial_parameters_without_docstringc                 C   r   )Nz3
module foo
foo.bar
    this: int
    *
Docstring.
r   r#   r   r   r   Itest_parameters_required_after_star_with_initial_parameters_and_docstring  r?   zZClinicParserTest.test_parameters_required_after_star_with_initial_parameters_and_docstringc                 C   r   )Nz 
module foo
foo.bar
    /
    /
r   r#   r   r   r   test_single_slash  r?   z"ClinicParserTest.test_single_slashc                 C   r   )Nz<
module foo
foo.bar
   x: int
   y: int
   *
   z: int
   /
r   r#   r   r   r   test_mix_star_and_slash  r?   z(ClinicParserTest.test_mix_star_and_slashc                 C   r   )Nz%
module foo
foo.bar
    /
    x: int
r   r#   r   r   r   1test_parameters_not_permitted_after_slash_for_now  r?   zBClinicParserTest.test_parameters_not_permitted_after_slash_for_nowc                 C   r   )Nzk
  module foo
  foo.bar
    x: int
      Nested docstring here, goeth.
    *
    y: str
  Not at column 0!
zV
bar($module, /, x, *, y)
--

Not at column 0!

  x
    Nested docstring here, goeth.
r   r   r   r   r   test_function_not_at_column_0  s   
	z.ClinicParserTest.test_function_not_at_column_0c                    sJ   t  }t| d _ fdd jd< td} | |  j d S )NFc                      s   t  ddS )NflagT)setattrr   r   r   r   <lambda>  s    z1ClinicParserTest.test_directive.<locals>.<lambda>Zsetflag)r*   r   r   Z
directivesr   r   rD   Z
assertTrue)r   rH   r,   r   r   r   test_directive  s   

zClinicParserTest.test_directivec                 C   s.   |  d}|j\}}| |jd jtj d S )Nz module os
os.access
   path: "s"r   )rD   r   r   r   r   r   r   r   r   r   r   test_legacy_converters  s   

z'ClinicParserTest.test_legacy_convertersc                 C   s&   t  }t|}t|}|| |S r   )r*   r   r   r   rD   )r   textrH   r   r,   r   r   r   rD     s
   

zClinicParserTest.parserC   r   c                 C   sP   |  |}|j}| t|| t|d tjsJ t|| tjs$J || S )Nr   )rD   r   rG   r   
isinstancer   ZModuleZFunction)r   r   r   r   r,   r   r   r   r   r     s   
zClinicParserTest.parse_functionc              	   C   s   |  ttjd |  ttjd t %}| t tj	dddd W d    n1 s/w   Y  W d    n1 s>w   Y  |  |
 d d S )Nz<Unspecified>z<Null>zThe igloos are melting!z	clown.txtE   )r)   Zline_numberz>Error in file "clown.txt" on line 69:
The igloos are melting!
)rG   r9   r   unspecifiedZNULLr   r   rr   r   Zfailr   )r   r   r   r   r   test_scaffolding  s   
z!ClinicParserTest.test_scaffoldingN)rC   r   ).r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rD   r   r   r   r   r   r   r     sX    	
	(L		
r   c                   @   s   e Zd ZdZdd ZdS )ClinicExternalTestNc           	   	   C   s"  t d}t|ddd}| }W d    n1 sw   Y  t W}tj|d}t|ddd}|	| W d    n1 sCw   Y  t
|j}t| t|ddd}| }W d    n1 siw   Y  t
|j}W d    n1 s~w   Y  | || | || d S )Nzclinic.testrP   zutf-8)encodingzclinic.test.cw)r   Zfindfileopenreadr   Ztemp_dirr   r   joinwritestatst_mtime_nsr   Z
parse_filerG   )	r   sourcer   Zorig_contentsZtmp_dirZtestfileZold_mtime_nsZnew_contentsZnew_mtime_nsr   r   r   test_external  s$   




z ClinicExternalTest.test_external)r   r   r   ZmaxDiffr  r   r   r   r   r     s    r   Z_testclinicc                   @   sn  e Zd Ze dd eeD  dd Zdd Zdd Z	d	d
 Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Z d7d8 Z!d9d: Z"d;d< Z#d=d> Z$d?d@ Z%dAdB Z&dCdD Z'dEdF Z(dGdH Z)dIdJ Z*dKdL Z+dMdN Z,dOdP Z-dQdR Z.dSdT Z/dUS )VClinicFunctionalTestc                 c   s(    | ]}| d r|tt|fV  qdS )Ztest_N)
startswithgetattr	ac_tester).0r   r   r   r   	<genexpr>;  s    
zClinicFunctionalTest.<genexpr>c                 C   st   |  t t  W d    n1 sw   Y  | tddd | tg dg df | tdd d S )Nr   rC   r   rC   zwhatever class)r   N)rr   	TypeErrorr
  Zobjects_converterrG   r#   r   r   r   test_objects_converter>  s   
z+ClinicFunctionalTest.test_objects_converterc                 C   J   |  t td W d    n1 sw   Y  | tdd d S )Nr      BytesObject)r  )rr   r  r
  Zbytes_object_converterrG   r#   r   r   r   test_bytes_object_converterE     z0ClinicFunctionalTest.test_bytes_object_converterc                 C   sT   |  t td W d    n1 sw   Y  td}| t||f d S )Nr   s   ByteArrayObject)rr   r  r
  Zbyte_array_object_converter	bytearrayrG   )r   Zbyte_arrr   r   r    test_byte_array_object_converterJ  s
   z5ClinicFunctionalTest.test_byte_array_object_converterc                 C   r  )Nr   unicode)r  )rr   r  r
  Zunicode_converterrG   r#   r   r   r   test_unicode_converterP  r  z+ClinicFunctionalTest.test_unicode_converterc                 C   s|   |  t tddd W d    n1 sw   Y  | t d | tdg dd | tddd	id
d d S )NFz	not a int)TTTr+      )FFT)z	not emptyr   rC   r   )TTF)rr   r  r
  Zbool_converterrG   r#   r   r   r   test_bool_converterU  s   z(ClinicFunctionalTest.test_bool_converterc                 C   s   |  t td W d    n1 sw   Y  |  t td W d    n1 s/w   Y  g d}tdd |D }| t | g d}tdd |D }| tj| | d S )Nr   s   ab)   A         	   
            "   '   ?   \       c                 s       | ]}t |V  qd S r   ordr  rH   r   r   r   r  b      z;ClinicFunctionalTest.test_char_converter.<locals>.<genexpr>)   1   2   3   4   5   6   7   8   9   0   a   b   c   dc                 s   r(  r   r)  r+  r   r   r   r  e  r,  )rr   r  r
  Zchar_convertertuplerG   )r   charsZexpectedr   r   r   test_char_converter\  s   z(ClinicFunctionalTest.test_char_converterc                 C   s6  ddl m} | t td W d    n1 sw   Y  | t t|d  W d    n1 s7w   Y  | t td|d  W d    n1 sTw   Y  | t tg  W d    n1 snw   Y  | t d | tdd|d d | tdd|d d d d	 d S )
Nr   )	UCHAR_MAXr   r      "   8   r   r   r   r   {   r   r   rD  )	_testcapir>  rr   OverflowErrorr
  Zunsigned_char_converterr  rG   )r   r>  r   r   r   test_unsigned_char_converterh      &z1ClinicFunctionalTest.test_unsigned_char_converterc                 C   s   ddl m}m} | t t|d  W d    n1 sw   Y  | t t|d  W d    n1 s;w   Y  | t tg  W d    n1 sUw   Y  | tdd | tdd d S )Nr   )SHRT_MINSHRT_MAXr   .rL    )rN  )	rF  rJ  rK  rr   rG  r
  Zshort_converterr  rG   )r   rJ  rK  r   r   r   test_short_converterv  s   z)ClinicFunctionalTest.test_short_converterc                 C   6  ddl m} | t td W d    n1 sw   Y  | t t|d  W d    n1 s7w   Y  | t td|d  W d    n1 sTw   Y  | t tg  W d    n1 snw   Y  | t d | tdd|d d | tdd|d d d d	 d S )
Nr   )	USHRT_MAXr   r   r?  rC  r   rD  rE  )	rF  rQ  rr   
ValueErrorr
  Zunsigned_short_converterrG  r  rG   )r   rQ  r   r   r   test_unsigned_short_converter  rI  z2ClinicFunctionalTest.test_unsigned_short_converterc                 C   s   ddl m}m} | t t|d  W d    n1 sw   Y  | t t|d  W d    n1 s;w   Y  | t tddd W d    n1 sWw   Y  | t tg  W d    n1 sqw   Y  | t d | tdddddt	df d S )Nr   )INT_MININT_MAXr   rC   r   )r@  rA  -   3)
rF  rT  rU  rr   rG  r
  r   r  rG   r*  )r   rT  rU  r   r   r   test_int_converter  s   $z'ClinicFunctionalTest.test_int_converterc                 C   rP  )
Nr   )UINT_MAXr   r   r?  rC  r   rD  rE  )	rF  rY  rr   rR  r
  Zunsigned_int_converterrG  r  rG   )r   rY  r   r   r   test_unsigned_int_converter  rI  z0ClinicFunctionalTest.test_unsigned_int_converterc                 C      ddl m}m} | t t|d  W d    n1 sw   Y  | t t|d  W d    n1 s;w   Y  | t tg  W d    n1 sUw   Y  | t d | tdd d S )Nr   )LONG_MINLONG_MAXr   r@  rL  rM  )	rF  r\  r]  rr   rG  r
  Zlong_converterr  rG   )r   r\  r]  r   r   r   test_long_converter     z(ClinicFunctionalTest.test_long_converterc                 C   rP  )
Nr   )	ULONG_MAXr   r   r?  rC  r   rD  rE  )	rF  ra  rr   rR  r
  Zunsigned_long_converterrG  r  rG   )r   ra  r   r   r   test_unsigned_long_converter  rI  z1ClinicFunctionalTest.test_unsigned_long_converterc                 C   r[  )Nr   )	LLONG_MIN	LLONG_MAXr   r^  rL  rM  )	rF  rc  rd  rr   rG  r
  Zlong_long_converterr  rG   )r   rc  rd  r   r   r   test_long_long_converter  r`  z-ClinicFunctionalTest.test_long_long_converterc                 C   rP  )
Nr   )
ULLONG_MAXr   r   r?  rC  r   rD  rE  )	rF  rf  rr   rR  r
  Zunsigned_long_long_converterrG  r  rG   )r   rf  r   r   r   !test_unsigned_long_long_converter  rI  z6ClinicFunctionalTest.test_unsigned_long_long_converterc                 C   s   ddl m}m} | t t|d  W d    n1 sw   Y  | t t|d  W d    n1 s;w   Y  | t tg  W d    n1 sUw   Y  | t d | tddd d d S )Nr   PY_SSIZE_T_MINPY_SSIZE_T_MAXr   r?  rC   r   rC   rB  )	rF  ri  rj  rr   rG  r
  Zpy_ssize_t_converterr  rG   r   ri  rj  r   r   r   test_py_ssize_t_converter  s   z.ClinicFunctionalTest.test_py_ssize_t_converterc                 C   s   ddl m}m} | t tg  W d    n1 sw   Y  | t d | tddd d | t||d |d |||f | t||d |d |||f d S )Nr   rh  r?  r   rC   rk  i  )rF  ri  rj  rr   r  r
  Zslice_index_converterrG   rl  r   r   r   test_slice_index_converter  s   z/ClinicFunctionalTest.test_slice_index_converterc                 C   s|   |  t td W d    n1 sw   Y  |  t tg  W d    n1 s/w   Y  | t d d S )Nr   r^  )rr   rR  r
  Zsize_t_converterr  rG   r#   r   r   r   test_size_t_converter  s   z*ClinicFunctionalTest.test_size_t_converterc                 C   Z   |  t tg  W d    n1 sw   Y  | t d | tdd d S N)g      )@      ࿩rr  )rr   r  r
  Zfloat_converterrG   r#   r   r   r   test_float_converter  
   z)ClinicFunctionalTest.test_float_converterc                 C   rp  rq  )rr   r  r
  Zdouble_converterrG   r#   r   r   r   test_double_converter  ru  z*ClinicFunctionalTest.test_double_converterc                 C   s   |  t tg  W d    n1 sw   Y  | ttddtddf | ttdtdf | tdd | tdd d S )Nr   rC   z-1-2jrr  rs  
   )rw  )rr   r  r
  Zpy_complex_converterrG   complexr#   r   r   r   test_py_complex_converter  s    z.ClinicFunctionalTest.test_py_complex_converterc                 C   s   |  t td W d    n1 sw   Y  |  t tddd W d    n1 s1w   Y  |  t tddd W d    n1 sMw   Y  | tdddd | tdddd | tddd	d
 d S )Nr   rk   rl   rH      b br8  ro   r9  c crk   rl   r{  )rr   r  r
  r   rR  rG   r#   r   r   r   test_str_converter  s   z'ClinicFunctionalTest.test_str_converterc                 C   s   |  t td W d    n1 sw   Y  | tdddd |  t tddd W d    n1 s<w   Y  | tddttdgd | tddttddtdgd	 | tddd
d	 d S )Nr   rk   rl   rH   ro   rz  r8  r   r|  s   c c)rr   r  r
  Zstr_converter_encodingrG   r  r*  r#   r   r   r   test_str_converter_encoding  s    "z0ClinicFunctionalTest.test_str_converter_encodingc                 C   sV   |  t tdd W d    n1 sw   Y  | tdtg dd d S )Nrk   rl   abcr   rC   r   )s   abcs   )rr   r  r
  Zpy_buffer_converterrG   r  r#   r   r   r   test_py_buffer_converter#  s    z-ClinicFunctionalTest.test_py_buffer_converterc                 C   sD   |  tddd |  tjdddd |  tjdddd d S )Nr   rC   r  rl   rn   )rG   r
  keywordsr#   r   r   r   test_keywords(  s   z"ClinicFunctionalTest.test_keywordsc                 C   sf   |  t tdd W d    n1 sw   Y  | tjdddd | tjdddd d S )Nr   rC   r  r  rn   )rr   r  r
  Zkeywords_kwonlyrG   r#   r   r   r   test_keywords_kwonly-  s
   z)ClinicFunctionalTest.test_keywords_kwonlyc                 C   s   |  tdd |  tddd |  tdddd |  tjdddd |  tjddddd |  tjddd	d
 |  tjddddd d S )Nr   r   NNrC   r   rC   Nr   r  r  rH   rk   rH   r   Nr   ro   )rG   r
  Zkeywords_optr#   r   r   r   test_keywords_opt3  s   z&ClinicFunctionalTest.test_keywords_optc                 C   s   |  tdd |  tddd | t tddd W d    n1 s*w   Y  |  tjdddd |  tjddddd |  tjddd	d
 |  tjdddddd d S )Nr   r   NNNrC   r   rC   NNr   r  r  r   rC   r   Nr  )r   Nr   N   rk   rl   rH   r6   r   rC   r   r  )rG   r
  Zkeywords_opt_kwonlyrr   r  r#   r   r   r   test_keywords_opt_kwonly<  s   z-ClinicFunctionalTest.test_keywords_opt_kwonlyc                 C   s   |  tdd | t tdd W d    n1 sw   Y  |  tjdddd |  tjdddd |  tjdddd	d
 d S )Nr   r  rC   r  r  r   r  r  ro   r  )rG   r
  Zkeywords_kwonly_optrr   r  r#   r   r   r   test_keywords_kwonly_optF  s   z-ClinicFunctionalTest.test_keywords_kwonly_optc                 C   s   |  t td W d    n1 sw   Y  |  t tjddd W d    n1 s1w   Y  | tddd | tjdddd d S )Nr   rC   rn   r  r  )rr   r  r
  Zposonly_keywordsrG   r#   r   r   r   test_posonly_keywordsN  s   z*ClinicFunctionalTest.test_posonly_keywordsc                 C   s   |  t td W d    n1 sw   Y  |  t tdd W d    n1 s0w   Y  |  t tjddd W d    n1 sLw   Y  | tjdddd d S )Nr   rC   rn   r  r  )rr   r  r
  Zposonly_kwonlyrG   r#   r   r   r   test_posonly_kwonlyV  s   z(ClinicFunctionalTest.test_posonly_kwonlyc                 C   s   |  t td W d    n1 sw   Y  |  t tddd W d    n1 s1w   Y  |  t tjdddd W d    n1 sNw   Y  | tjddddd | tjddddd d S )Nr   rC   r   ro   r  r  rl   rH   )rr   r  r
  Zposonly_keywords_kwonlyrG   r#   r   r   r   test_posonly_keywords_kwonly_  s   z1ClinicFunctionalTest.test_posonly_keywords_kwonlyc                 C   s   |  t td W d    n1 sw   Y  | tddd | tdddd | tddddd | tjdddd | tjdddd	d |  t tjddddd
 W d    n1 skw   Y  | tjdddddd d S )Nr   rC   r  r   r  r  r  r  r  r  rl   rH   r6   )rr   r  r
  Zposonly_keywords_optrG   r#   r   r   r   test_posonly_keywords_opti  s   z.ClinicFunctionalTest.test_posonly_keywords_optc                 C   s   |  tdd |  tddd |  tdddd |  tddddd | t tjddd	 W d    n1 sAw   Y  |  tjdddd
d |  tjdddddd | t tjddddd W d    d S 1 syw   Y  d S )Nr   r  rC   r  r   r  r  r  r  r  rH   r6   r  )rG   r
  Zposonly_opt_keywords_optrr   r  r#   r   r   r   test_posonly_opt_keywords_optu  s   "z2ClinicFunctionalTest.test_posonly_opt_keywords_optc                 C   s   |  t td W d    n1 sw   Y  |  t tdd W d    n1 s0w   Y  | tjdddd | tjddddd | tjddddd	d
 |  t tjddddd W d    d S 1 ssw   Y  d S )Nr   rC   r  r  r   r  r  r  r  r  r  )rr   r  r
  Zposonly_kwonly_optrG   r#   r   r   r   test_posonly_kwonly_opt  s   "z,ClinicFunctionalTest.test_posonly_kwonly_optc                 C   s   |  tdd |  tddd | t tddd W d    n1 s*w   Y  | t tjddd W d    n1 sFw   Y  |  tjddddd |  tjdddd	d
d d S )Nr   r  rC   r  r   r  r  r  r  r  r  )rG   r
  Zposonly_opt_kwonly_optrr   r  r#   r   r   r   test_posonly_opt_kwonly_opt  s   z0ClinicFunctionalTest.test_posonly_opt_kwonly_optc              	   C   s~  |  t td W d    n1 sw   Y  |  t tdd W d    n1 s0w   Y  |  t tjddd W d    n1 sLw   Y  |  t tddd W d    n1 shw   Y  |  t tjdddd W d    n1 sw   Y  | tjddddd | tjddddd | tjdddd	d
d | tjdddd	ddd d S )Nr   rC   r  r   ro   r  r   rC   r   NNr  r  r  r   rC   r   r  Nr  rH   r6   er   rC   r   r  r  )rr   r  r
  Zposonly_keywords_kwonly_optrG   r#   r   r   r    test_posonly_keywords_kwonly_opt  s&    z5ClinicFunctionalTest.test_posonly_keywords_kwonly_optc              	   C   sp  |  t td W d    n1 sw   Y  | tddd | tjdddd |  t tdddd W d    n1 sGw   Y  |  t tjddd W d    n1 scw   Y  | tjddddd	 | tjdddd
d	 | tjdddddd | tjdddddd | tjddddddd | tjddddddd d S )Nr   rC   )r   rC   NNNr  r   r  rn   r  r  r  r6   r  r  r  )r6   r  r  r  )rr   r  r
  Zposonly_keywords_opt_kwonly_optrG   r#   r   r   r   $test_posonly_keywords_opt_kwonly_opt  s"    z9ClinicFunctionalTest.test_posonly_keywords_opt_kwonly_optc                 C   s   |  tdd |  tddd | t tjddd W d    n1 s*w   Y  |  tdddd |  tjddddd |  tjdddd	d
d |  tjdddd	dd | t tdddd	 W d    d S 1 syw   Y  d S )Nr   r  rC   r  r  r   r  r  r  r  r  r  )rG   r
  Z#posonly_opt_keywords_opt_kwonly_optrr   r  r#   r   r   r   (test_posonly_opt_keywords_opt_kwonly_opt  s   "z=ClinicFunctionalTest.test_posonly_opt_keywords_opt_kwonly_optc                 C   s~   |  t t  W d    n1 sw   Y  |  t td W d    n1 s.w   Y  | tjddd d S )Nr   rm   )r   )rr   r  r
  Zkeyword_only_parameterrG   r#   r   r   r   test_keyword_only_parameter  s   
z0ClinicFunctionalTest.test_keyword_only_parameterc                 C   sB   d}|  t| tdd W d    d S 1 sw   Y  d S )NzVgh_99240_double_free\(\) argument 2 must be encoded string without null bytes, not strrk   z b)ZassertRaisesRegexr  r
  Zgh_99240_double_free)r   Zexpected_errorr   r   r   test_gh_99240_double_free  s   "z.ClinicFunctionalTest.test_gh_99240_double_freeN)0r   r   r   localsupdatedirr
  r  r  r  r  r  r=  rH  rO  rS  rX  rZ  r_  rb  re  rg  rm  rn  ro  rt  rv  ry  r}  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   r  :  sZ    	
	

r  __main__)$testr   r   Ztest.supportr   r   Zunittestr   r1   r   Zos.pathr   r7   Zskip_if_missingZimports_under_toolr   r   r
   r   r!   r@   rH   r*   rA   rL   ru   r   r   r   r   r   import_moduler
  r  r   mainr   r   r   r   <module>   sJ   
/04=   ~
   