o
    KXhO                     @   s   d dl Z d dlZd dlmZmZmZmZmZmZ d dl	Z
dZe dk r%eZeZe dd dkr2eZe ZG dd deZG dd	 d	ZG d
d dZG dd dZdd Zdd ZdS )    N)AbstractTkTesttcl_versionrequires_tclget_tk_patchlevelpixels_conv
tcl_obj_eqF)            c                   @   s   e Zd ZeeZdZdZedd Z	dd Z
dejfddZeddd	d
dZd0ddddZdd Zdd ZedddZdd ZddddZdd Zdd Zdd d!d"Zddd#d$d%Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ ZdS )1AbstractWidgetTestNFc                 C   s6   z| j W S  ty   t| jdd| _ | j  Y S w )Ntkscaling)Z_scalingAttributeErrorfloatrootcall)self r   C/opt/python-3.10.19/usr/lib/python3.10/tkinter/test/widget_tests.pyr      s   
zAbstractWidgetTest.scalingc                 C   s<   | j s| jrtdkr|S t|trdt| j|S t|S )Nr       )	
_stringifywantobjectsr   
isinstancetuplejoinmap_strstr)r   valuer   r   r   r   $   s
   
zAbstractWidgetTest._strc                 C   s    |||rd S |  ||| d S N)assertEqual)r   actualexpectedmsgeqr   r   r   assertEqual2+   s   
zAbstractWidgetTest.assertEqual2)r%   convr'   c                C   s   |||< |t u r
|}|r||}| js| js%t|tr!t|}nt|}|d u r+t}| j	|| ||d | j	|
|||d ||}| t|d | j	|d ||d d S )N)r'   r	      )	_sentinelr   r   r   r   tkinterZ_joinr    r   r(   Zcget	configurer#   len)r   widgetnamer!   r%   r)   r'   tr   r   r   
checkParam0   s    

zAbstractWidgetTest.checkParamT)	keep_origc                C   s   || }|d ur| |}| tj}|||< W d    n1 s"w   Y  |d ur4| t|j| |r?| || | n|||< | tj}|||i W d    n1 s[w   Y  |d urm| t|j| |ry| || | d S |||< d S r"   )formatZassertRaisesr,   ZTclErrorr#   r    	exceptionr-   )r   r/   r0   r!   errmsgr3   Zorigcmr   r   r   checkInvalidParamD   s&   

z$AbstractWidgetTest.checkInvalidParamc                 O   s$   |D ]}| j |||fi | qd S r"   )r2   )r   r/   r0   valueskwargsr!   r   r   r   checkParamsZ   s   zAbstractWidgetTest.checkParamsc                 O   sT   | j ||g|R i | | j||ddd | j||ddd | j||ddd d S )N zexpected integer but got ""r6   10pzexpected integer but got "10p"g	@zexpected integer but got "3.2"r;   r8   )r   r/   r0   r9   r:   r   r   r   checkIntegerParam^   s   



z$AbstractWidgetTest.checkIntegerParamr)   c                O   sL   |D ]}| j |||fd|i| q| j||ddd | j||ddd d S )Nr)   r<   z)expected floating-point number but got ""r=   spamz-expected floating-point number but got "spam"r2   r8   )r   r/   r0   r)   r9   r:   r!   r   r   r   checkFloatParamg   s   


z"AbstractWidgetTest.checkFloatParamc                 C   s`   dD ]}| j |||dd qdD ]}| j |||dd q| j||ddd | j||d	d
d d S )N)Fr   ZfalsenoZoffr   )r%   )T   trueZyesZonrF   r<   z!expected boolean value but got ""r=   rB   z%expected boolean value but got "spam"rC   )r   r/   r0   r!   r   r   r   checkBooleanParamo   s   


z$AbstractWidgetTest.checkBooleanParam)allow_emptyc                K   s>   | j ||ddddddddd	d
fi | | j||ddd d S )Nz#ff0000z#00ff00z#0000ffz#123456ZredZgreenZblueZwhiteZblackZgreyrB   zunknown color name "spam"r=   r?   )r   r/   r0   rI   r:   r   r   r   checkColorParamy   s   

z"AbstractWidgetTest.checkColorParamc                 K   sH   | j ||ddddfi | tdkr| ||d | j||ddd	 d S )
NZarrowZwatchZcrossr<   )r   r	   nonerB   zbad cursor spec "spam"r=   )r;   r   r2   r8   )r   r/   r0   r:   r   r   r   checkCursorParam   s   

z#AbstractWidgetTest.checkCursorParamc                 C   s0   dd }|||< |  ||  | ||d d S )Nc                  W   s   d S r"   r   )argsr   r   r   command   s   z5AbstractWidgetTest.checkCommandParam.<locals>.commandr<   )Z
assertTruer;   )r   r/   r0   rN   r   r   r   checkCommandParam   s   z$AbstractWidgetTest.checkCommandParamr=   c                O   s   | j ||g|R i | |d u r9d|d|d d t|dkr#dnd|d f }| j||dd| d d	| }| j||d
|d d S )Nz %s "{}": must be %s%s or %sz,    ,r<   Z	ambiguousr=   ZbadrB   )r;   r   r.   r8   )r   r/   r0   r6   r9   r:   Zerrmsg2r   r   r   checkEnumParam   s   
z!AbstractWidgetTest.checkEnumParam)r)   r3   c          
      O   s   |d u r| j }|D ](}t}|}	t|tr#|	r#|	tur#t|| j }t}	| j|||f||	d| q	| j||dd|d | j||dd|d d S )Nr%   r)   Z6xzbad screen distance "6x")r6   r3   rB   zbad screen distance "spam")	_conv_pixelsr+   r   r    r   r   roundr2   r8   )
r   r/   r0   r)   r3   r9   r:   r!   r%   Zconv1r   r   r   checkPixelsParam   s(   



z#AbstractWidgetTest.checkPixelsParamc              
   C   s>   |  ||dddddd d}tdk rd }| j||d	|d
 d S )NZflatZgrooveZraisedZridgeZsolidZsunkenzHbad relief "spam": must be flat, groove, raised, ridge, solid, or sunkenr   rB   r=   )r;   r   r8   )r   r/   r0   r6   r   r   r   checkReliefParam   s   

z#AbstractWidgetTest.checkReliefParamc                 C   s@   t j| jdd}| j|||td | j||ddd d||< d S )NZimage1)Zmasterr0   rA   rB   zimage "spam" doesn't existr=   r<   )r,   Z
PhotoImager   r2   r    r8   )r   r/   r0   imager   r   r   checkImageParam   s   
z"AbstractWidgetTest.checkImageParamc                 C   s   | j |||td d S )NrA   )r2   r    )r   r/   r0   varr   r   r   checkVariableParam   s   z%AbstractWidgetTest.checkVariableParamc                 C   s`   |  | | |t t|dkr| d|f  |D ]}t|ts-| d|f   d S qd S )Nr*   zInvalid bounding box: %r)ZassertIsNotNoneZassertIsInstancer   r.   Zfailr   int)r   Zbboxitemr   r   r   assertIsBoundingBox   s   

z&AbstractWidgetTest.assertIsBoundingBoxc                 C   s   |   }| }| t|t|  |D ]}||  qtjjrUdddddd}t|}t| j	}t|| D ]}||v rJ|| |v rJ|| |v sTt
d| jj|f  q8d S d S )Nborderwidth
background
foregroundZinvalidcommandZvalidatecommand)bdbgfgZinvcmdZvcmdz%s.OPTIONS doesn't contain "%s")createkeysr#   sortedr-   testsupportverbosesetOPTIONSprint	__class____name__)r   r/   rg   kaliasesr%   r   r   r   	test_keys   s0   



zAbstractWidgetTest.test_keysr"   ) rp   
__module____qualname__staticmethodpixels_roundrU   _conv_pad_pixelsr   propertyr   r   object__eq__r(   r+   r2   r8   r;   r@   r   rD   rH   rJ   rL   rO   rS   rW   rX   rZ   r\   r_   rs   r   r   r   r   r      s:    
	

r   c                   @   s  e Zd 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d0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Z d<d= Z!d>d? Z"d@dA Z#dBdC Z$dDdE Z%dFdG Z&dHdI Z'dJdK Z(dLdM Z)dNdO Z*dPdQ Z+dRdS Z,dTdU Z-dVdW Z.dXdY Z/dZd[ Z0d\d] Z1d^d_ Z2d`da Z3dbdc Z4e5dddedfdg Z6e5dddedhdi Z7djdk Z8dlS )mStandardOptionsTests)*activebackgroundactiveborderwidthactiveforegroundanchorra   bitmapr`   compoundcursordisabledforegroundexportselectionfontrb   highlightbackgroundhighlightcolorhighlightthicknessrY   insertbackgroundinsertborderwidthinsertofftimeinsertontimeinsertwidthjumpjustifyorientpadxpadyreliefrepeatdelayrepeatintervalselectbackgroundselectborderwidthselectforegroundsetgrid	takefocustexttextvariabletroughcolor	underline
wraplengthxscrollcommandyscrollcommandc                 C      |   }| |d d S )Nr}   rf   rJ   r   r/   r   r   r   test_configure_activebackground      z4StandardOptionsTests.test_configure_activebackgroundc              
   C   $   |   }| |ddddddd d S )Nr~   r   ?g333333@r   r>   rf   rW   r   r   r   r    test_configure_activeborderwidth      z5StandardOptionsTests.test_configure_activeborderwidthc                 C   r   )Nr   r   r   r   r   r   test_configure_activeforeground   r   z4StandardOptionsTests.test_configure_activeforegroundc                 C   s*   |   }| |ddddddddd	d
 d S )Nr   nneeZsesswwZnwcenterrf   rS   r   r   r   r   test_configure_anchor  s   z*StandardOptionsTests.test_configure_anchorc                 C   2   |   }| |d d| jv r| |d d S d S )Nra   rd   rf   rJ   rm   r   r   r   r   test_configure_background  
   
z.StandardOptionsTests.test_configure_backgroundc                 C   s   |   }| |dd | |dd tjjddd}| |dd|  d| jjd	d
v r4d| j v s?| j	|dddd d S d S )Nr   Z	questheadZgray50z
python.xbmZ
imghdrdata)Zsubdir@Zaquar   ZwindowingsystemZAppKitrB   zbitmap "spam" not definedr=   )
rf   r2   ri   rj   Zfindfiler   r   r   Zwinfo_serverr8   )r   r/   filenamer   r   r   test_configure_bitmap  s   

z*StandardOptionsTests.test_configure_bitmapc              
   C   sJ   |   }| |ddddddd d| jv r#| |ddddddd d S d S )	Nr`   r   r   @r   r   r>   rc   )rf   rW   rm   r   r   r   r   test_configure_borderwidth  s   
z/StandardOptionsTests.test_configure_borderwidthc              
   C   r   )Nr   Zbottomr   leftrK   righttopr   r   r   r   r   test_configure_compound!  r   z,StandardOptionsTests.test_configure_compoundc                 C   r   )Nr   )rf   rL   r   r   r   r   test_configure_cursor&  r   z*StandardOptionsTests.test_configure_cursorc                 C   r   )Nr   r   r   r   r   r   !test_configure_disabledforeground*  r   z6StandardOptionsTests.test_configure_disabledforegroundc                 C   r   )Nr   rf   rH   r   r   r   r   test_configure_exportselection.  r   z3StandardOptionsTests.test_configure_exportselectionc                 C   s,   |   }| |dd | j|dddd d S )Nr   z3-Adobe-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*r<   zfont "" doesn't existr=   )rf   r2   r8   r   r   r   r   test_configure_font2  s   

z(StandardOptionsTests.test_configure_fontc                 C   r   )Nrb   re   r   r   r   r   r   test_configure_foreground9  r   z.StandardOptionsTests.test_configure_foregroundc                 C   r   )Nr   r   r   r   r   r   "test_configure_highlightbackground?  r   z7StandardOptionsTests.test_configure_highlightbackgroundc                 C   r   )Nr   r   r   r   r   r   test_configure_highlightcolorC  r   z2StandardOptionsTests.test_configure_highlightcolorc              	   C   s8   |   }| |dddddd | j|ddd| jd d S )	Nr   r   r   r   r   r>   r   rT   )rf   rW   r2   rU   r   r   r   r   !test_configure_highlightthicknessG  s   

z6StandardOptionsTests.test_configure_highlightthicknessc                 C   r   )NrY   rf   rZ   r   r   r   r   test_configure_imageN  r   z)StandardOptionsTests.test_configure_imagec                 C   r   )Nr   r   r   r   r   r   test_configure_insertbackgroundR  r   z4StandardOptionsTests.test_configure_insertbackgroundc              
   C   r   )Nr   r   r   r   r   r   r>   r   r   r   r   r    test_configure_insertborderwidthV  r   z5StandardOptionsTests.test_configure_insertborderwidthc                 C      |   }| |dd d S )Nr   d   rf   r@   r   r   r   r   test_configure_insertofftime[     z1StandardOptionsTests.test_configure_insertofftimec                 C   r   )Nr   r   r   r   r   r   r   test_configure_insertontime_  r   z0StandardOptionsTests.test_configure_insertontimec                 C       |   }| |ddddd d S )Nr   r   r   r   r>   r   r   r   r   r   test_configure_insertwidthc     z/StandardOptionsTests.test_configure_insertwidthc                 C   r   )Nr   r   r   r   r   r   test_configure_jumpg  r   z(StandardOptionsTests.test_configure_jumpc                 C   s4   |   }| j|dddddd | j|dddd d S )	Nr   r   r   r   z6bad justification "{}": must be left, right, or centerr=   r<   z:ambiguous justification "": must be left, right, or center)rf   rS   r8   r   r   r   r   test_configure_justifyk  s   

z+StandardOptionsTests.test_configure_justifyc                 C   s2   |   }| t|d | j | |ddd d S )Nr   Z
horizontalZvertical)rf   r#   r    Zdefault_orientrS   r   r   r   r   test_configure_orientt  s   z*StandardOptionsTests.test_configure_orientc              
   C   (   |   }| j|dddddd| jd d S )Nr   r   皙@ffffff@r   12mrA   rf   rW   rx   r   r   r   r   test_configure_padxy     
z(StandardOptionsTests.test_configure_padxc              
   C   r   )Nr   r   r   r   r   r   rA   r   r   r   r   r   test_configure_pady~  r   z(StandardOptionsTests.test_configure_padyc                 C   r   )Nr   rf   rX   r   r   r   r   test_configure_relief  r   z*StandardOptionsTests.test_configure_reliefc                 C      |   }| |ddd d S )Nr     r   r   r   r   r   test_configure_repeatdelay     z/StandardOptionsTests.test_configure_repeatdelayc                 C   r   )Nr   r   r   r   r   r   r   r   test_configure_repeatinterval  r   z2StandardOptionsTests.test_configure_repeatintervalc                 C   r   )Nr   r   r   r   r   r   test_configure_selectbackground  r   z4StandardOptionsTests.test_configure_selectbackgroundc                 C   r   )Nr   r   r   r   r>   r   r   r   r   r    test_configure_selectborderwidth  r   z5StandardOptionsTests.test_configure_selectborderwidthc                 C   r   )Nr   r   r   r   r   r   test_configure_selectforeground  r   z4StandardOptionsTests.test_configure_selectforegroundc                 C   r   )Nr   r   r   r   r   r   test_configure_setgrid  r   z+StandardOptionsTests.test_configure_setgridc                 C      |   }| |dddd d S )NstateZactivedisabledZnormalr   r   r   r   r   test_configure_state     z)StandardOptionsTests.test_configure_statec                 C   r   )Nr   01r<   rf   r;   r   r   r   r   test_configure_takefocus  r   z-StandardOptionsTests.test_configure_takefocusc                 C   r   )Nr   r<   z
any stringr   r   r   r   r   test_configure_text  r   z(StandardOptionsTests.test_configure_textc                 C   &   |   }t| j}| |d| d S )Nr   )rf   r,   Z	StringVarr   r\   r   r/   r[   r   r   r   test_configure_textvariable     z0StandardOptionsTests.test_configure_textvariablec                 C   r   )Nr   r   r   r   r   r   test_configure_troughcolor  r   z/StandardOptionsTests.test_configure_troughcolorc                 C   r   )Nr   r   rF   
   r   r   r   r   r   test_configure_underline  r   z-StandardOptionsTests.test_configure_underlinec                 C   r   )Nr   r   r   r   r   r   r   test_configure_wraplength  r   z.StandardOptionsTests.test_configure_wraplengthc                 C   r   )Nr   rf   rO   r   r   r   r   test_configure_xscrollcommand  r   z2StandardOptionsTests.test_configure_xscrollcommandc                 C   r   )Nr   r  r   r   r   r   test_configure_yscrollcommand  r   z2StandardOptionsTests.test_configure_yscrollcommandc                 C   r   )NrN   r  r   r   r   r   test_configure_command  r   z+StandardOptionsTests.test_configure_commandc                 C   r   )NZindicatoronr   r   r   r   r   test_configure_indicatoron  r   z/StandardOptionsTests.test_configure_indicatoronc                 C   r   )NZ	offreliefr   r   r   r   r   test_configure_offrelief  r   z-StandardOptionsTests.test_configure_offreliefc                 C   r   )NZ
overreliefr   r   r   r   r   test_configure_overrelief  r   z.StandardOptionsTests.test_configure_overreliefc                 C   r   )NZselectcolorr   r   r   r   r   test_configure_selectcolor  r   z/StandardOptionsTests.test_configure_selectcolorc                 C   r   )NZselectimager   r   r   r   r   test_configure_selectimage  r   z/StandardOptionsTests.test_configure_selectimager   r	   c                 C   r   )NZtristateimager   r   r   r   r   test_configure_tristateimage  s   z1StandardOptionsTests.test_configure_tristateimagec                 C   r   )NZtristatevalueZ
unknowable)rf   r2   r   r   r   r   test_configure_tristatevalue  s   z1StandardOptionsTests.test_configure_tristatevaluec                 C   r   )Nvariable)rf   r,   Z	DoubleVarr   r\   r   r   r   r   test_configure_variable  r   z,StandardOptionsTests.test_configure_variableN)9rp   rt   ru   ZSTANDARD_OPTIONSr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r	  r
  r  r  r   r  r  r  r   r   r   r   r|      sp    	

r|   c                   @      e Zd Zdd Zdd ZdS )IntegerSizeTestsc                 C   r   )Nheightr   r   r   r   r   r   r   test_configure_height  r   z&IntegerSizeTests.test_configure_heightc                 C   r   )Nwidth  nr   r   r   r   r   r   test_configure_width  r   z%IntegerSizeTests.test_configure_widthNrp   rt   ru   r  r  r   r   r   r   r        r  c                   @   r  )PixelSizeTestsc              
   C   r   )Nr  r   gLY@gfffffY@r  r   Z3cr   r   r   r   r   r       z$PixelSizeTests.test_configure_heightc              
   C   r   )Nr  r  gfffff6y@gIy@r  r   Z5ir   r   r   r   r   r    r  z#PixelSizeTests.test_configure_widthNr  r   r   r   r   r    r  r  c                     s    fdd}|S )Nc                    sn    j D ]1}d| }t |s4D ]}t||r"t |t||  nq|f fdd	}||_t || q S )NZtest_configure_c                    s"   |   }||  td| jf )NzOption "%s" is not tested in %s)rf   AssertionErrorrp   )r   optionr/   clsr   r   ri     s
   z5add_standard_options.<locals>.decorator.<locals>.test)rm   hasattrsetattrgetattrrp   )r!  r  Z
methodnameZsource_classri   source_classesr   r   	decorator  s   


z'add_standard_options.<locals>.decoratorr   )r&  r'  r   r%  r   add_standard_options  s   r(  c                  C   s*   t jjrt } td| dd d S d S )Nzpatchlevel =infoZ
patchlevel)ri   rj   rk   r,   ZTclrn   r   )Ztclr   r   r   setUpModule  s   r*  )Zunittestr,   Ztkinter.test.supportr   r   r   r   r   r   Ztest.supportri   Znoconvr    rV   rw   r]   rz   r+   r   r|   r  r  r(  r*  r   r   r   r   <module>   s(    
 P  


