o
    IXhb*                     @   s\  d dl Z d dlZd dlZd dl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ZdZG dd	 d	ejZG d
d dZG dd deejZG dd deejZG dd deejZG dd deejZG dd deejZG dd deejZG dd deejZG dd deejZG dd dejZG dd dejZed kre  dS dS )!    N)mock)support)import_helper)	os_helperzhttp://www.example.comtestc                   @   s   e Zd Zdd ZdddZdS )	PopenMockc                 C      dS Nr    selfr
   r
   >/opt/python-3.10.19/usr/lib/python3.10/test/test_webbrowser.pypoll      zPopenMock.pollNc                 C   r   r	   r
   )r   Zsecondsr
   r
   r   wait   r   zPopenMock.waitN)__name__
__module____qualname__r   r   r
   r
   r
   r   r      s    r   c                   @   s   e Zd Zegi dddZdS )CommandTestMixin)argskwc          
      C   s   t  }t| td| | jtd}t|||i | tjjd d }| 	|d t |
d |D ]}	| |	| |
||	 q2| 	|| dS )aj  Given a web browser instance method name along with arguments and
        keywords for same (which defaults to the single argument URL), creates
        a browser instance from the class pointed to by self.browser, calls the
        indicated instance method with the indicated arguments, and compares
        the resulting options and arguments passed to Popen by the browser
        instance against the 'options' and 'args' lists.  Options are compared
        in a position independent fashion, and the arguments are compared in
        sequence order to whatever is left over after removing the options.

        Popen)namer   N)r   r   Zpatch
subprocessbrowser_classCMD_NAMEgetattrr   Z	call_argsassertEqualpopassertInindex)
r   methr   r   options	argumentspopenbrowserZ
popen_argsoptionr
   r
   r   _test   s   
zCommandTestMixin._testN)r   r   r   URLr(   r
   r
   r
   r   r      s    r   c                   @      e Zd ZejZdd ZdS )GenericBrowserCommandTestc                 C      | j dg tgd d S Nopenr#   r$   r(   r)   r   r
   r
   r   	test_open7      
z#GenericBrowserCommandTest.test_openN)r   r   r   
webbrowserGenericBrowserr   r1   r
   r
   r
   r   r+   3       r+   c                   @   r*   )BackgroundBrowserCommandTestc                 C   r,   r-   r0   r   r
   r
   r   r1   A   r2   z&BackgroundBrowserCommandTest.test_openN)r   r   r   r3   ZBackgroundBrowserr   r1   r
   r
   r
   r   r6   =   r5   r6   c                   @   2   e Zd ZejZdd Zdd Zdd Zdd Z	d	S )
ChromeCommandTestc                 C   r,   r-   r0   r   r
   r
   r   r1   K   r2   zChromeCommandTest.test_openc                 C      | j dtddg tgd d S Nr.   FZ	autoraiser   r#   r$   r(   dictr)   r   r
   r
   r   test_open_with_autoraise_falseP      
z0ChromeCommandTest.test_open_with_autoraise_falsec                 C      | j ddgtgd d S Nopen_newz--new-windowr/   r0   r   r
   r
   r   test_open_newU      
zChromeCommandTest.test_open_newc                 C   r,   Nopen_new_tabr/   r0   r   r
   r
   r   test_open_new_tabZ   r2   z#ChromeCommandTest.test_open_new_tabN)
r   r   r   r3   ZChromer   r1   r?   rD   rH   r
   r
   r
   r   r8   G       r8   c                   @   r7   )
MozillaCommandTestc                 C   r,   r-   r0   r   r
   r
   r   r1   d   r2   zMozillaCommandTest.test_openc                 C   r9   r:   r=   r   r
   r
   r   r?   i   r@   z1MozillaCommandTest.test_open_with_autoraise_falsec                 C      | j dg dtgd d S )NrC   z-new-windowr/   r0   r   r
   r
   r   rD   n      
z MozillaCommandTest.test_open_newc                 C   rK   )NrG   z-new-tabr/   r0   r   r
   r
   r   rH   s   rL   z$MozillaCommandTest.test_open_new_tabN)
r   r   r   r3   ZMozillar   r1   r?   rD   rH   r
   r
   r
   r   rJ   `   rI   rJ   c                   @   r7   )
NetscapeCommandTestc                 C       | j dddgdtgd d S )Nr.   -raise-remoteopenURL({})r/   r(   formatr)   r   r
   r
   r   r1   }      

zNetscapeCommandTest.test_openc                 C   s(   | j dtddddgdtgd d S )Nr.   Fr;   -noraiserP   rQ   r<   )r(   r>   rS   r)   r   r
   r
   r   r?      s   

z2NetscapeCommandTest.test_open_with_autoraise_falsec                 C   rN   )NrC   rO   rP   openURL({},new-window)r/   rR   r   r
   r
   r   rD      rT   z!NetscapeCommandTest.test_open_newc                 C   rN   )NrG   rO   rP   openURL({},new-tab)r/   rR   r   r
   r
   r   rH      rT   z%NetscapeCommandTest.test_open_new_tabN)
r   r   r   r3   ZNetscaper   r1   r?   rD   rH   r
   r
   r
   r   rM   y   rI   rM   c                   @   r7   )
GaleonCommandTestc                 C   rA   )Nr.   -nr/   r0   r   r
   r
   r   r1      rE   zGaleonCommandTest.test_openc                 C   s"   | j dtddddgtgd d S )Nr.   Fr;   rU   rY   r<   r=   r   r
   r
   r   r?      s   
z0GaleonCommandTest.test_open_with_autoraise_falsec                 C   rA   )NrC   -wr/   r0   r   r
   r
   r   rD      rE   zGaleonCommandTest.test_open_newc                 C   rA   )NrG   rZ   r/   r0   r   r
   r
   r   rH      rE   z#GaleonCommandTest.test_open_new_tabN)
r   r   r   r3   ZGaleonr   r1   r?   rD   rH   r
   r
   r
   r   rX      rI   rX   c                   @   r7   )
OperaCommandTestc                 C   r,   r-   r0   r   r
   r
   r   r1      r2   zOperaCommandTest.test_openc                 C   r9   r:   r=   r   r
   r
   r   r?      r@   z/OperaCommandTest.test_open_with_autoraise_falsec                 C   rA   rB   r0   r   r
   r
   r   rD      rE   zOperaCommandTest.test_open_newc                 C   r,   rF   r0   r   r
   r
   r   rH      r2   z"OperaCommandTest.test_open_new_tabN)
r   r   r   r3   ZOperar   r1   r?   rD   rH   r
   r
   r
   r   r[      rI   r[   c                   @   r7   )
ELinksCommandTestc                 C      | j ddgdtgd d S Nr.   rP   rQ   r/   rR   r   r
   r
   r   r1      s   


zELinksCommandTest.test_openc                 C   r]   r^   rR   r   r
   r
   r   r?         

z0ELinksCommandTest.test_open_with_autoraise_falsec                 C   r]   )NrC   rP   rV   r/   rR   r   r
   r
   r   rD      r_   zELinksCommandTest.test_open_newc                 C   r]   )NrG   rP   rW   r/   rR   r   r
   r
   r   rH      r_   z#ELinksCommandTest.test_open_new_tabN)
r   r   r   r3   ZElinksr   r1   r?   rD   rH   r
   r
   r
   r   r\      s    r\   c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )BrowserRegistrationTestc                 C   s    t j| _g t _t j| _i t _d S r   )r3   	_tryorder_saved_tryorder	_browsers_saved_browsersr   r
   r
   r   setUp   s   
zBrowserRegistrationTest.setUpc                 C   s   | j t_| jt_d S r   )rb   r3   ra   rd   rc   r   r
   r
   r   tearDown   s   z BrowserRegistrationTest.tearDownc                 C   s   G dd d}g }i }|  tj| |  tj| td| dg}|d g|d< |  tj| |  tj| | }|d urGtjd|||d ntd|| |rUddg}nddg}||g|d< |  tj| |  tj| d S )Nc                   @      e Zd ZdS )zCBrowserRegistrationTest._check_registration.<locals>.ExampleBrowserNr   r   r   r
   r
   r
   r   ExampleBrowser       ri   Example1example1Zexample2	preferred)r   r3   ra   rc   register)r   rn   ri   Zexpected_tryorderZexpected_browsersinstancer
   r
   r   _check_registration   s,   

z+BrowserRegistrationTest._check_registrationc                 C      | j dd d S )NFrm   rq   r   r
   r
   r   test_register     z%BrowserRegistrationTest.test_registerc                 C   s   | j d d d S )Nrm   rs   r   r
   r
   r   test_register_default
  ru   z-BrowserRegistrationTest.test_register_defaultc                 C   rr   )NTrm   rs   r   r
   r
   r   test_register_preferred  ru   z/BrowserRegistrationTest.test_register_preferredN)	r   r   r   re   rf   rq   rt   rv   rw   r
   r
   r
   r   r`      s    r`   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )
ImportTestc                 C   s   t d}| |j | |j G dd d}|d| | |j | |jd d | |j | 	d|j | |jd |d g d S )Nr3   c                   @   rg   )z0ImportTest.test_register.<locals>.ExampleBrowserNrh   r
   r
   r
   r   ri     rj   ri   rk   rl   )
r   import_fresh_moduleassertIsNonera   assertFalserc   ro   Z
assertTruer   r    )r   r3   ri   r
   r
   r   rt     s   
zImportTest.test_registerc                 C   sh   t d}| |j | |j | |j |d W d    n1 s'w   Y  | 	|j d S )Nr3   Zfakebrowser)
r   rz   r{   ra   r|   rc   ZassertRaisesErrorgetZassertIsNotNone)r   r3   r
   r
   r   test_get   s   
zImportTest.test_getc                 C   s@   t d}tjtj }||d |	| |
tj d S )Nr3   )r   rz   ospathbasenamesys
executablelowerro   r4   r~   )r   r3   r   r
   r
   r   test_synthesize)  s   
zImportTest.test_synthesizec              
   C   s   t d}z| j}W n |jtfy( } z| t| W Y d }~nd }~ww t	 }||d< t d}|  W d    d S 1 sFw   Y  d S )Nr3   BROWSER)
r   rz   r~   r   r}   AttributeErrorskipTeststrr   EnvironmentVarGuard)r   r3   r&   errenvr
   r
   r   test_environment/  s   



"zImportTest.test_environmentc              
   C   s  t d}z|  ||jd j}W n |jttfy1 } z| t	| W Y d }~nd }~ww t
 }||d< t d}| | j| W d    n1 sSw   Y  t
 }tj|d< t d}| | jtj W d    d S 1 s|w   Y  d S )Nr3   ry   r   )r   rz   r~   ra   r   r}   r   
IndexErrorr   r   r   r   r   r   r   )r   r3   Zleast_preferred_browserr   r   r
   r
   r   test_environment_preferred:  s$   





"z%ImportTest.test_environment_preferredN)r   r   r   rt   r   r   r   r   r
   r
   r
   r   rx     s    	rx   __main__)r3   Zunittestr   r   r   r   r   r   Ztest.supportr   r   r)   r   Z	MagicMockr   r   ZTestCaser+   r6   r8   rJ   rM   rX   r[   r\   r`   rx   r   mainr
   r
   r
   r   <module>   s4    	

5<