
    Mh                        d Z ddlZddlZddlZ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mZ ddlmZmZ ddlmZ ddlmZ dd	lmZ dd
lmZmZ ddlmZmZ ddlm Z   ej!         ej"        e#                    Z$ e%e          Z&dddiidfe&d<   dddiidfe&d<   dddiidfe&d<    e%e          Z'de'd<    G d dej(                  Z)d Z*d Z+d Z,d Z-d  Z. G d! de          Z/d" Z0d# Z1e2d$k    rId%d&gZ3e3D ],Z4e4ej5        v r!d'e/_6        ej5        7                    e4           -e/8                                 dS dS )(z
This module is meant to run JupyterLab in a headless browser, making sure
the application launches and starts up without errors.
    N)ThreadPoolExecutor)path)aliasesflags)pathname2urlurljoin)IOLoop)StreamClosedError)WebSocketClosedError)BoolUnicode   )LabAppget_app_dir)TestEnv
BrowserApp	core_modeTzStart the app in core mode.z	core-modedev_modezStart the app in dev mode.zdev-modewatchzStart the app in watch mode.zBrowserApp.app_dirzapp-dirc                   6     e Zd ZdZ fdZ fdZ fdZ xZS )LogErrorHandlerz.A handler that exits with 1 on a logged error.c                     t                                          t          j                   |                     t
          j                   d| _        d S )N)streamF)super__init__sysstderrsetLevelloggingERRORerroredself	__class__s    X/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/jupyterlab/browser_check.pyr   zLogErrorHandler.__init__+   s?    
+++gm$$$    c                     t          |d          r0|j        )t          |j        d         t          t          f          rdS t                                          |          S )Nexc_infor   F)hasattrr(   
isinstancer
   r   r   filterr#   recordr$   s     r%   r+   zLogErrorHandler.filter0   s\     FJ''	+6?1-0ACW/XYY , 5ww~~f%%%r&   c                 X    d| _         t                                          |           d S )NT)r!   r   emitr,   s     r%   r/   zLogErrorHandler.emit=   s&    Vr&   )__name__
__module____qualname____doc__r   r+   r/   __classcell__r$   s   @r%   r   r   (   sp        88    
& & & & &        r&   r   c                 `    t          j                                        t          | |           dS )a
  Synchronous entry point to run a test function.
    func is a function that accepts an app url as a parameter and returns a result.
    func can be synchronous or asynchronous.  If it is synchronous, it will be run
    in a thread, so asynchronous is preferred.
    N)r	   currentspawn_callbackrun_test_async)appfuncs     r%   run_testr<   B   s*     N##NC>>>>>r&   c                   K   t                      }| j                            |           t                      }|                                 | j                            d           t          | d          r#t          dt          | j	                            }n| j
        }t          j        |          r ||          }ng| j                            d           t          j                    }t                      }|                    |||          }t          j        |g          }	 | d{V  nX# t$          $ rK}	| j                            d           | j                            t+          |	                     Y d}	~	nd}	~	ww xY w| j                            d           d}
|j        rd	}
| j                            d
           n| j                            d           | j                            d           	 | j                                         | j                                         |                                 n@# t$          $ r3}	| j                            t+          |	                     d	}
Y d}	~	nd}	~	ww xY wt5          j        d           t9          j        |
           dS # t5          j        d           t9          j        |
           w xY w)zRun a test against the application.
    func is a function that accepts an app url as a parameter and returns a result.
    func can be synchronous or asynchronous.  If it is synchronous, it will be run
    in a thread, so asynchronous is preferred.
    zRunning async testbrowser_open_filezfile:z&Using thread pool executor to run testNz!Caught exception during the test:zTest Completer   r   zExiting with 1 due to errorszExiting normallyzStopping server...   )r   log
addHandlerr   startinfor)   r   r   r>   display_urlinspectiscoroutinefunctionasyncioget_event_loopr   run_in_executorwait	Exceptioncriticalerrorstrr!   http_serverstopio_looptimesleepos_exit)r:   r;   handler	env_patchurltestloopexecutortaskeresults              r%   r9   r9   K   s      GGw		IOOGLL%&&& s'(( g|C,ABBCCo "4(( $tCyy=>>>%''%''##HdC88|TF##







   <===c!ff GLL!!!F )78888'(((GLL%&&&	   c!ff 	
1
 	
1
sJ   )D2 2
F<AFF?AI J0 
J)I>9J0 >JJ0 0*Kc                    K   t          j        | i | d{V }|                                 d{V \  }}|j        dk    r4t	          t          |           dz   t          |j                  z             ||fS )zRun an asynchronous commandNr   z exited with )rG   create_subprocess_execcommunicate
returncodeRuntimeErrorrN   )cmdkwargsprocstdoutr   s        r%   run_async_processrh      s      /?????????D++--------NFF!3s88o5DO8L8LLMMM6>r&   c                   K   t           j                            dd          }|dvrd}t          j        t                      d          }t          j        t          j        |d                    slt          j        |          s&t          j        t          j        |                     t          g d|           d{V  t          g d	|           d{V  t          d
dd|g|           d{V  t          j
        t          j        t          d          t          j        |d                     t          dd| g|           d{V  dS )-Run the browser test and return an exit code.JLAB_BROWSER_TYPEchromium   webkitfirefoxrl   browser_testnode_modulesnpminitz-ycwdNrs   installzplaywright@^1.9.2npx
playwrightrx   browser-test.jsnode)rT   environgetospjoinr   existsmakedirsrh   shutilcopyhererX   browsertargets      r%   run_browserr      sr     jnn0*==G777Xkmm^44F:chv~6677 Uz&!! 	*K(())) 5 5 56BBBBBBBBBB G G GVTTTTTTTTTT
UL)WE6
R
R
RRRRRRRR
K01138FDU3V3VWWW
V%6<&
I
I
IIIIIIIIIIr&   c                 L   t           j                            dd          }|dvrd}t          j        t                      d          }t          j        t          j        |d                    sDt          j        |           t          j	        g d|           t          j	        g d|           t          j	        d	d
d|g|           t          j        t          j        t          d          t          j        |d                     t          j        dd| g|          S )rj   rk   rl   rm   rp   rq   rr   ru   rw   ry   rz   rx   r{   r|   )rT   r}   r~   r   r   r   r   r   
subprocesscallr   r   r   
check_callr   s      r%   run_browser_syncr      s   jnn0*==G777Xkmm^44F:chv~6677 M
F---6::::???VLLLLOUL)W=6JJJJ
K01138FDU3V3VWWW &*;S!AvNNNNr&   c                   z     e Zd ZdZe ZdZddiZ eddd          Zd	Z	e
ZeZ ed          Z fd
Z fdZ xZS )r   zAn app the launches JupyterLab and waits for it to start up, checking for
    JS console errors, JS errors, and Python logged errors.
    Fbase_urlz/foo/z
/lab?resetTz'The default URL to redirect to from `/`)confighelpz	127.0.0.1c                     | j                             di            d| j         d         d<   d| j         d         d<   d| j         d         d<   t                                                       d S )Npage_config_dataTbrowserTestFbuildAvailableexposeAppInBrowser)settings
setdefaultr   initialize_settingsr"   s    r%   r   zBrowserApp.initialize_settings   sp      !3R888;?()-8>C()*:;BF()*>?##%%%%%r&   c                     d }| j         rt          j        dk    rt          nt          }t          | j        |           t                                                       d S )Nc                      dS )Nr    )argsre   s     r%   r;   z,BrowserApp.initialize_handlers.<locals>.func   s    1r&   nt)	test_browserrT   namer   r   r<   	serverappr   initialize_handlers)r#   r;   r$   s     r%   r   zBrowserApp.initialize_handlers   sc    	 	 	  	H')w$##KD&&&##%%%%%r&   )r0   r1   r2   r3   r   open_browserserverapp_configr   default_urlip
test_flagsr   test_aliasesr   r   r   r   r   r4   r5   s   @r%   r   r      s          DL"G,',t:cdddK	BEG4::L& & & & && & & & & & & & &r&   c                  "    t           t          dgS )N)moduler:   )r0   r   r   r&   r%    _jupyter_server_extension_pointsr      s    
3344r&   c                      ddigS )Nr   zjupyterlab.browser_checkr   r   r&   r%   _jupyter_server_extension_pathsr      s    1233r&   __main__z--no-browser-testz--no-chrome-testF)9r3   rG   rE   r   rT   r   r   r   rR   concurrent.futuresr   r   r   jupyter_server.serverappr   r   jupyter_server.utilsr   r   tornado.ioloopr	   tornado.iostreamr
   tornado.websocketr   	traitletsr   r   labappr   r   tests.test_appr   abspathdirname__file__r   dictr   r   StreamHandlerr   r<   r9   rh   r   r   r   r   r   r0   skip_optionsoptionargvr   removelaunch_instancer   r&   r%   <module>r      s   
    				      



  1 1 1 1 1 1       3 3 3 3 3 3 3 3 6 6 6 6 6 6 6 6 ! ! ! ! ! ! . . . . . . 2 2 2 2 2 2 # # # # # # # # ' ' ' ' ' ' ' ' # # # # # #s{;3;x(())T%[[
(;*=>@]^
; '*d);<>Z[
: $wo68VW
7 tG}}.Y     g+   4? ? ?8 8 8v  J J J"O O O & & & & & & & &B5 5 54 4 4 z');<L $ $SX&+J#HOOF###      r&   