
    ;e                         d Z 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mZ ddlZddlZdd	lmZ dd
lmZ  G d dej                  ZeZd\  ZZe                    eddgedd          Ze                    eddd          Ze                    eddddg          Ze                    eddd          Ze                    eddd          Z e!                    ededd          Z"e                    e"dd d!          Z#e                    e#d"d#d#          Z$e                    e"d$dd          Z%ee"d%Z& ej'        e&d&            ej'        ej(                    G d' d(ej                  Z) G d) d*ej                  Z* G d+ d,ej                  Z+ G d- d.ej                  Z,e-d/k    r ej.        d01           dS dS )2zTest browser, coverage 90%.    )browser)requiresN)mock)Func)py_extensions)deque)Tk)TreeNodec                   X    e Zd Zed             Zed             Zd Zd Zd Zd Z	d Z
dS )	ModuleBrowserTestc                     t          d           t                      | _        | j                                         t	          j        | j        t          d          | _        d S )NguiT)_utest)r   r	   rootwithdrawr   ModuleBrowser__file__mbclss    5/usr/lib/python3.11/idlelib/idle_test/test_browser.py
setUpClasszModuleBrowserTest.setUpClass   sK    44&sx$GGG    c                     | j                                          | j                                         | j                                         | `| ` d S N)r   closer   update_idletasksdestroyr   s    r   tearDownClasszModuleBrowserTest.tearDownClass   sF    !!###Hcfffr   c                     | j         }| j        } ||j        t                      |t          j        i            |                     |j        t                     | 	                    t          j                   d S r   )r   assertEqualpathr   pyclbr_modulesassertIsInstancenoder
   assertIsNotNoner   	file_open)selfr   eqs      r   	test_initzModuleBrowserTest.test_init"   sn    W
27H
6?Bbgx000W./////r   c                    | j         }|                     t          j                            t
                    |j                                                   |                     |j        	                                d           d S )NzModule Browser)
r   assertInosr"   basenamer   toptitler!   iconnamer)   r   s     r   test_settitlezModuleBrowserTest.test_settitle*   s`    Wbg&&x00"&,,..AAA**,<=====r   c                 |    | j         }|                                }|                     |t          j                   d S r   )r   rootnoder%   r   ModuleBrowserTreeItem)r)   r   rns      r   test_rootnodezModuleBrowserTest.test_rootnode/   s5    W[[]]b'"?@@@@@r   c                 H   | j         }t                      |j        _        t                      |j        _        |                                 |                     |j        j        j                   |                     |j        j        j                   |j        `|j        `d S r   )r   r   r0   r   r&   r   
assertTruecalledr3   s     r   
test_closezModuleBrowserTest.test_close4   ss    W&&



-....///FNBGOOOr   c                     d}t           D ]n}|                     |          5  | | }t          j        |          }|t          j        v}|                     ||           d d d            n# 1 swxY w Y   od S )Nz/path/to/file)ext)r   subTestr   is_browseable_extensionbrowseable_extension_blocklistr!   )r)   r"   r?   filenameactualexpecteds         r   test_is_browseable_extensionz.ModuleBrowserTest.test_is_browseable_extension=   s      	3 	3C#&& 3 3">C>> 8BBg&LL  222	3 3 3 3 3 3 3 3 3 3 3 3 3 3 3	3 	3s   ?A--A1	4A1	N)__name__
__module____qualname__classmethodr   r   r+   r4   r9   r=   rF    r   r   r   r      s        H H [H   [0 0 0> > >
A A A
, , ,3 3 3 3 3r   r   )testztest.pyC0base   	   )
end_linenoF1      C1    C2   F3f0      f1      f2   c1)rM   r[   rL   c                       e Zd Zd Zd ZdS )TransformChildrenTestc                    | 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 )NrL   r   C0(base)rO   r[   zdifferent name)r!   r   transform_childrenlistmock_pyclbr_treerM   r[   namer)   r*   	transformtcls       r   test_transform_module_childrenz4TransformChildrenTest.test_transform_module_children_   s    .	99-v6677
3R
3q6;
###
3q6;99-v6677
3q6;
###99-/?@@AA
3r   c                    | 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   rR   rO   C1())r!   r   rh   ri   rM   childrenrR   rU   rk   r[   r^   rc   rl   s       r   test_transform_node_childrenz2TransformChildrenTest.test_transform_node_childrenn   s    .	99R[))**
3R
3q6;
3q6;99R[))**
3q6;
4		"+&&''"b22222r   N)rG   rH   rI   ro   rs   rK   r   r   re   re   ]   s2          3 3 3 3 3r   re   c                   z    e Zd Zed             Zd Zd Zd Zd Zd Z	d Z
 ej        d          d	             Zd
S )ModuleBrowserTreeItemTestc                 B    t          j        t                    | _        d S r   )r   r7   fnamembtr   s    r   r   z$ModuleBrowserTreeItemTest.setUpClass~   s    /66r   c                 P    |                      | j        j        t                     d S r   )r!   rx   filerw   r)   s    r   r+   z#ModuleBrowserTreeItemTest.test_init   s"    .....r   c                 j    |                      | j                                        t                     d S r   )r!   rx   GetTextrw   r{   s    r   test_gettextz&ModuleBrowserTreeItemTest.test_gettext   s,    ))++U33333r   c                 `    |                      | j                                        d           d S )Npython)r!   rx   GetIconNamer{   s    r   test_geticonnamez*ModuleBrowserTreeItemTest.test_geticonname   s,    --//:::::r   c                 ^    |                      | j                                                   d S r   )r;   rx   IsExpandabler{   s    r   test_isexpandablez+ModuleBrowserTreeItemTest.test_isexpandable   s(    --//00000r   c                    t           j        j        }t           j        }t	          t
                    t           j        _        t	          t          t          g          t           _        	 |                     | j	        
                                t          t          g           |t           j        _        |t           _        d S # |t           j        _        |t           _        w xY w)Nresult)r   r#   readmodule_exrh   r   rj   r[   rM   r!   rx   listchildren)r)   save_rexsave_tcs      r   test_listchildrenz+ModuleBrowserTreeItemTest.test_listchildren   s    >/,'+3C'D'D'D$%)"b%:%:%:"	1TX2244r2h???+3GN()0G&&& ,4GN()0G&0000s   )9C C c                 t   | j         }t          t          t          g          |_        |                                \  }}|`|                     |t          j                   |                     |t          j                   | 	                    |j
        d           | 	                    |j
        d           d S )Nr   r[   rg   )rx   r   r[   rM   r   
GetSubListr%   r   ChildBrowserTreeItemr!   rk   )r)   rx   sub0sub1s       r   test_getsublistz)ModuleBrowserTreeItemTest.test_getsublist   s    hBx000^^%%
ddG$@AAAdG$@AAAD)))J/////r   idlelib.browser.file_openc                 z   | j         }t          j        dd          5  |                                 |                                 d d d            n# 1 swxY w Y   t          j        dd          5  |                                 |                    t                     d d d            d S # 1 swxY w Y   d S )Nzos.path.existsF)return_valueT)rx   r   patchOnDoubleClickassert_not_calledassert_called_once_withrw   )r)   fopenrx   s      r   test_ondoubleclickz,ModuleBrowserTreeItemTest.test_ondoubleclick   s:   hZ(u=== 	& 	&##%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& Z(t<<< 	1 	1))%000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1s#   )AAA4/B00B47B4N)rG   rH   rI   rJ   r   r+   r~   r   r   r   r   r   r   r   rK   r   r   ru   ru   |   s        7 7 [7/ / /4 4 4; ; ;1 1 1	1 	1 	10 0 0 TZ+,,	1 	1 -,	1 	1 	1r   ru   c                       e Zd Zed             Zed             Zd Zd Zd Zd Z	d Z
 ej        d          d	             Zd
S )ChildBrowserTreeItemTestc                     t           j        } |t                    | _         |t                    | _         |t                    | _        d S r   )r   r   r^   cbt_f1rU   cbt_C1rR   cbt_F1)r   CBTs     r   r   z#ChildBrowserTreeItemTest.setUpClass   s;    *SWW
SWW
SWW


r   c                     | ` | `| `d S r   )r   r   r   r   s    r   r   z&ChildBrowserTreeItemTest.tearDownClass   s    J
CJJJr   c                     | j         } || j        j        d           |                     | j        j                    || j        j        d           |                     | j        j                   d S )Nrq   r^   )r!   r   rk   assertFalse
isfunctionr   r;   )r)   r*   s     r   r+   z"ChildBrowserTreeItemTest.test_init   sn    
4;V$$$/000
4;T"""./////r   c                     |                      | j                                        d           |                      | j                                        d           d S )Nz
class C1()zdef f1(...))r!   r   r}   r   r{   s    r   r~   z%ChildBrowserTreeItemTest.test_gettext   sP    ,,..===,,..>>>>>r   c                     |                      | j                                        d           |                      | j                                        d           d S )Nfolderr   )r!   r   r   r   r{   s    r   r   z)ChildBrowserTreeItemTest.test_geticonname   sP    0022H===0022H=====r   c                    |                      | j                                                   |                      | j                                                   |                     | j                                                   d S r   )r;   r   r   r   r   r   r{   s    r   r   z*ChildBrowserTreeItemTest.test_isexpandable   sj    00223330022333113344444r   c                 <   | j         }t          j        }| j                                        }|                     |d         |            |t          |          d            ||d         j        d            || j                                        g            d S )Nr   rO   ra   )	r!   r   r   r   r   r%   lenrk   r   )r)   r*   r   	f1sublists       r   r   z(ChildBrowserTreeItemTest.test_getsublist   s    *K**,,	ilC000
3y>>1
9Q<d###
4;!!##R(((((r   r   c                    t          j                    x}|j        _        | j                                         |                                 |                                 |                    | j        j        j	                   d S r   )
r   Mockr   gotoliner   r   assert_calledassert_called_withobjlineno)r)   r   gotos      r   r   z+ChildBrowserTreeItemTest.test_ondoubleclick   sq    -1Y[[8u!*!!### 677777r   N)rG   rH   rI   rJ   r   r   r+   r~   r   r   r   r   r   r   rK   r   r   r   r      s          [ / / [/0 0 0? ? ?> > >5 5 5
	) 	) 	) TZ+,,8 8 -,8 8 8r   r   c                       e Zd ZdZd ZdS )NestedChildrenTestzFTest that all the nodes in a nested tree are added to the BrowserTree.c                    t                      }g }g d}t          j        }|                     |t                     |t
                    f           |r|                                }|                                }|                    |           |                     |j	        |
                                           |                     |                                d           |                     |                                |g k               |                    |j	                   ||                     ||           d S )N)	r[   rg   r^   rc   rR   rq   ra   rX   rZ   )r   r   )r   r   r   extendr[   rM   popleftr   r-   rk   r}   r   assertIsr   appendr!   )r)   queueactual_namesexpected_namesr   cbsublists          r   test_nestedzNestedChildrenTest.test_nested   s#         *cc"ggss2ww'((( 	)BmmooGLL!!!MM"'2::<<000MM"..**,@AAAMM"//++W];;;(((  	) 	~66666r   N)rG   rH   rI   __doc__r   rK   r   r   r   r      s)        LL7 7 7 7 7r   r   __main__   )	verbosity)/r   idlelibr   test.supportr   unittestr   idlelib.idle_test.mock_idler   idlelib.utilr   collectionsr   os.pathr.   r#   tkinterr	   idlelib.treer
   TestCaser   r   modulerw   ClassrM   _nest_functionrR   _nest_classrU   rX   rZ   Functionr[   r^   ra   rc   rj   rh   rr   re   ru   r   r   rG   mainrK   r   r   <module>r      s           ! ! ! ! ! !        , , , , , , & & & & & &               ! ! ! ! ! !23 23 23 23 23) 23 23 23l !XXfdVHeQ1X==r4A&&^^BaRD))^^Ba##r4A&&[[ubR[88r4R((r4R((^^Bb"%%B''   +V 4 4 4  2; ' ' '3 3 3 3 3H- 3 3 3>11 11 11 11 11 1 11 11 11h28 28 28 28 28x0 28 28 28l7 7 7 7 7* 7 7 74 zHMA r   