a
    åze  ã                   @   s˜  d dl mZ d dlmZ d dlZd dlmZ d dlmZ d dlm	Z	 d dl
Zd dlZd dlmZ d dlmZ G d	d
„ d
ejƒZeZd\ZZe eddged¡Ze edd¡Ze edddg¡Ze edd¡Ze edd¡Ze eded¡Ze edd¡Z e e dd¡Z!e edd¡Z"eed œZ#e $e#d!¡ e $ej%¡ G d"d#„ d#ejƒZ&G d$d%„ d%ejƒZ'G d&d'„ d'ejƒZ(G d(d)„ d)ejƒZ)e*d*kr”ej+d+d, dS )-é    )Úbrowser)ÚrequiresN)Úmock)ÚFunc)Údeque)ÚTk)ÚTreeNodec                   @   sD   e Zd Zedd„ ƒZedd„ ƒZdd„ Zdd„ Zd	d
„ Zdd„ Z	dS )ÚModuleBrowserTestc                 C   s2   t dƒ tƒ | _| j ¡  tj| jtdd| _d S )NZguiT)Z_utest)r   r   ÚrootZwithdrawr   ZModuleBrowserÚ__file__Úmb©Úcls© r   ú4/usr/lib/python3.9/idlelib/idle_test/test_browser.pyÚ
setUpClass   s    
zModuleBrowserTest.setUpClassc                 C   s*   | j  ¡  | j ¡  | j ¡  | `| ` d S ©N)r   Úcloser
   Zupdate_idletasksÚdestroyr   r   r   r   ÚtearDownClass   s    


zModuleBrowserTest.tearDownClassc                 C   sB   | j }| j}||jtƒ |tji ƒ |  |jt¡ |  	t
j¡ d S r   )r   ÚassertEqualÚpathr   ÚpyclbrZ_modulesÚassertIsInstanceÚnoder   ZassertIsNotNoner   Z	file_open)Úselfr   Úeqr   r   r   Ú	test_init!   s    zModuleBrowserTest.test_initc                 C   s6   | j }|  tj t¡|j ¡ ¡ |  |j 	¡ d¡ d S )NzModule Browser)
r   ÚassertInÚosr   Úbasenamer   ÚtopÚtitler   Ziconname©r   r   r   r   r   Útest_settitle)   s    zModuleBrowserTest.test_settitlec                 C   s    | j }| ¡ }|  |tj¡ d S r   )r   Úrootnoder   r   ÚModuleBrowserTreeItem)r   r   Zrnr   r   r   Útest_rootnode.   s    zModuleBrowserTest.test_rootnodec                 C   sR   | j }tƒ |j_tƒ |j_| ¡  |  |jjj¡ |  |jjj¡ |j`|j`d S r   )r   r   r!   r   r   r   Ú
assertTrueZcalledr#   r   r   r   Ú
test_close3   s    

zModuleBrowserTest.test_closeN)
Ú__name__Ú
__module__Ú__qualname__Úclassmethodr   r   r   r$   r'   r)   r   r   r   r   r	      s   

r	   )Útestztest.pyÚC0Úbaseé   ÚF1é   ÚC1é   Ú ÚC2é   ÚF3é	   Úf0é   Úf1é   Úf2é   Úc1é   )r/   r;   r.   c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚTransformChildrenTestc                 C   s‚   | j }tj}t|tdƒƒ}||ttgƒ ||d jdƒ ||d jdƒ t|tdƒƒ}||d jdƒ t|tdƒƒ}||g ƒ d S )Nr.   r   úC0(base)r1   r;   zdifferent name)r   r   Útransform_childrenÚlistÚmock_pyclbr_treer/   r;   Úname©r   r   Z	transformZtclr   r   r   Útest_transform_module_childrenU   s    z4TransformChildrenTest.test_transform_module_childrenc                 C   s‚   | j }tj}t|tjƒƒ}||ttgƒ ||d jdƒ ||d jdƒ t|tjƒƒ}||d jdƒ |t|t	jƒƒt
tgƒ d S )Nr   r2   r1   úC1())r   r   rE   rF   r/   Úchildrenr2   r4   rH   r;   r=   rA   rI   r   r   r   Útest_transform_node_childrend   s    z2TransformChildrenTest.test_transform_node_childrenN)r*   r+   r,   rJ   rM   r   r   r   r   rC   S   s   rC   c                   @   sZ   e Zd Zedd„ ƒZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dd„ Z
e d¡dd„ ƒZdS )ÚModuleBrowserTreeItemTestc                 C   s   t  t¡| _d S r   )r   r&   ÚfnameÚmbtr   r   r   r   r   t   s    z$ModuleBrowserTreeItemTest.setUpClassc                 C   s   |   | jjt¡ d S r   )r   rP   ÚfilerO   ©r   r   r   r   r   x   s    z#ModuleBrowserTreeItemTest.test_initc                 C   s   |   | j ¡ t¡ d S r   )r   rP   ÚGetTextrO   rR   r   r   r   Útest_gettext{   s    z&ModuleBrowserTreeItemTest.test_gettextc                 C   s   |   | j ¡ d¡ d S )NÚpython)r   rP   ÚGetIconNamerR   r   r   r   Útest_geticonname~   s    z*ModuleBrowserTreeItemTest.test_geticonnamec                 C   s   |   | j ¡ ¡ d S r   )r(   rP   ÚIsExpandablerR   r   r   r   Útest_isexpandable   s    z+ModuleBrowserTreeItemTest.test_isexpandablec                 C   sj   t jj}t j}ttdt j_tttgdt _z(|  | j	 
¡ ttg¡ W |t j_|t _n|t j_|t _0 d S )N©Úresult)r   r   Zreadmodule_exrE   r   rG   r;   r/   r   rP   Úlistchildren)r   Zsave_rexZsave_tcr   r   r   Útest_listchildren„   s    ÿz+ModuleBrowserTreeItemTest.test_listchildrenc                 C   sb   | j }tttgd|_| ¡ \}}|`|  |tj¡ |  |tj¡ |  	|j
d¡ |  	|j
d¡ d S )NrZ   r;   rD   )rP   r   r;   r/   r\   Ú
GetSubListr   r   ÚChildBrowserTreeItemr   rH   )r   rP   Zsub0Zsub1r   r   r   Útest_getsublist   s    z)ModuleBrowserTreeItemTest.test_getsublistúidlelib.browser.file_openc                 C   s   | j }tjddd  | ¡  | ¡  W d   ƒ n1 s:0    Y  tjddd* | ¡  | ¡  | t¡ W d   ƒ n1 s‚0    Y  d S )Nzos.path.existsF)Úreturn_valueT)rP   r   ÚpatchÚOnDoubleClickZassert_not_calledÚassert_calledZcalled_withrO   )r   ÚfopenrP   r   r   r   Útest_ondoubleclick™   s    &z,ModuleBrowserTreeItemTest.test_ondoubleclickN)r*   r+   r,   r-   r   r   rT   rW   rY   r]   r`   r   rc   rg   r   r   r   r   rN   r   s   

rN   c                   @   s^   e Zd Zedd„ ƒZedd„ ƒZdd„ Zdd„ Zd	d
„ Zdd„ Z	dd„ Z
e d¡dd„ ƒZdS )ÚChildBrowserTreeItemTestc                 C   s(   t j}|tƒ| _|tƒ| _|tƒ| _d S r   )r   r_   r=   Úcbt_f1r4   Úcbt_C1r2   Úcbt_F1)r   ÚCBTr   r   r   r   ©   s    

z#ChildBrowserTreeItemTest.setUpClassc                 C   s   | ` | `| `d S r   )rj   ri   rk   r   r   r   r   r   °   s    z&ChildBrowserTreeItemTest.tearDownClassc                 C   sB   | j }|| jjdƒ |  | jj¡ || jjdƒ |  | jj¡ d S )NrK   r=   )r   rj   rH   ÚassertFalseZ
isfunctionri   r(   )r   r   r   r   r   r   ´   s
    z"ChildBrowserTreeItemTest.test_initc                 C   s(   |   | j ¡ d¡ |   | j ¡ d¡ d S )Nz
class C1()zdef f1(...))r   rj   rS   ri   rR   r   r   r   rT   »   s    z%ChildBrowserTreeItemTest.test_gettextc                 C   s(   |   | j ¡ d¡ |   | j ¡ d¡ d S )NÚfolderrU   )r   rj   rV   ri   rR   r   r   r   rW   ¿   s    z)ChildBrowserTreeItemTest.test_geticonnamec                 C   s4   |   | j ¡ ¡ |   | j ¡ ¡ |  | j ¡ ¡ d S r   )r(   rj   rX   ri   rm   rk   rR   r   r   r   rY   Ã   s    z*ChildBrowserTreeItemTest.test_isexpandablec                 C   sX   | j }tj}| j ¡ }|  |d |¡ |t|ƒdƒ ||d jdƒ || j ¡ g ƒ d S )Nr   r1   r?   )	r   r   r_   ri   r^   r   ÚlenrH   rk   )r   r   rl   Z	f1sublistr   r   r   r`   È   s    
z(ChildBrowserTreeItemTest.test_getsublistra   c                 C   s>   t  ¡  }|j_| j ¡  | ¡  | ¡  | | jjj	¡ d S r   )
r   ZMockrb   Zgotolinerk   rd   re   Zassert_called_withÚobjÚlineno)r   rf   Zgotor   r   r   rg   Ó   s
    
z+ChildBrowserTreeItemTest.test_ondoubleclickN)r*   r+   r,   r-   r   r   r   rT   rW   rY   r`   r   rc   rg   r   r   r   r   rh   §   s   

rh   c                   @   s   e Zd Zdd„ ZdS )ÚNestedChildrenTestc                 C   s    t ƒ }g }g d¢}tj}| |tƒ|tƒf¡ |r| ¡ }| ¡ }| |¡ |  |j	| 
¡ ¡ |  | ¡ d¡ |  | ¡ |g k¡ | |j	¡ q.|  ||¡ d S )N)	r;   rD   r=   rA   r2   rK   r?   r7   r9   )rU   rn   )r   r   r_   Úextendr;   r/   Úpopleftr^   r   rH   rS   rV   ZassertIsrX   Úappendr   )r   ÚqueueZactual_namesZexpected_namesrl   ÚcbZsublistr   r   r   Útest_nestedà   s    
zNestedChildrenTest.test_nestedN)r*   r+   r,   rx   r   r   r   r   rr   Ý   s   rr   Ú__main__é   )Ú	verbosity),Zidlelibr   Ztest.supportr   Zunittestr   Zidlelib.idle_test.mock_idler   Úcollectionsr   Zos.pathr   r   Útkinterr   Zidlelib.treer   ZTestCaser	   r   ÚmodulerO   ZClassr/   Z_nest_functionr2   Z_nest_classr4   r7   r9   ZFunctionr;   r=   r?   rA   rG   rE   rL   rC   rN   rh   rr   r*   Úmainr   r   r   r   Ú<module>   s<   -
56
