σ
¬X[c           @@ sκ  d  Z  d d l m Z m Z d d l m Z d d l m 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 Z y d d l m Z Wn! e k
 rί d d l m Z n Xd 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 m  Z  e j! e j" e#   Z$ e j% d d k  Z& d   Z' d   Z( d   Z) d e* f d     YZ+ d e  f d     YZ, d e, f d     YZ- d   Z. e/ d k rζe0 j1   n  d S(   s7   A lab app that runs a sub process for a demo or a test.i    (   t   print_functiont   absolute_import(   t   path(   t   joinN(   t   patch(   t   Unicode(   t	   py3compat(   t   TemporaryDirectory(   t   write_kernel_spec(   t
   ProcessAppi   c          @ sy   t  j d d    t j t j   d   t t j   d d  d   }  |  j d  Wd QXt j	   f d      S(	   s6   Create a temporary directory with some file structure.t   prefixt   mock_contentst   srcs   temp.txtt   wt   helloNc           @ s   t  j   t  S(   N(   t   shutilt   rmtreet   True(    (   t   root_dir(    s8   lib/python2.7/site-packages/jupyterlab/tests/test_app.pyt   <lambda>*   s    (
   t   tempfilet   mkdtempt   ost   mkdirt   ospR   t   opent   writet   atexitt   register(   t   fid(    (   R   s8   lib/python2.7/site-packages/jupyterlab/tests/test_app.pyt   _create_notebook_dir$   s    !c           @ s,   t  j d d    t j   f d      S(   s,   Create a temporary directory for workspaces.R
   t   mock_workspacesc           @ s   t  j   t  S(   N(   R   R   R   (    (   R   (    s8   lib/python2.7/site-packages/jupyterlab/tests/test_app.pyR   1   s    (   R   R   R   R   (    (    (   R   s8   lib/python2.7/site-packages/jupyterlab/tests/test_app.pyt   _create_workspaces_dir.   s    c          C@ sΈ   i t  j d d d d g d 6d d 6d d	 6}  t j } t | j   d
 d  } t j |  t t | d  d   } | j	 t
 j |    Wd  QXt | j   d
 d  } t |  d  S(   Ns   -ms   jupyterlab.tests.echo_kernels   -fs   {connection_file}t   argvs   Echo Kernelt   display_namet   echot   languaget   kernelss   kernel.jsonR   t   ipython(   t   syst
   executablet   jupyter_coret   pathst   pjoint   jupyter_data_dirR   t   makedirsR   R   t   jsont   dumpsR   (   t   kernel_jsonR*   t
   kernel_dirt   ft   ipykernel_dir(    (    s8   lib/python2.7/site-packages/jupyterlab/tests/test_app.pyt   _install_kernels5   s    
	t	   _test_envc           B@ s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   su   Set Jupyter path variables to a temporary directory

    Useful as a context manager or with explicit start/stop
    c         C@ s  t    |  _ } t j t j i t | j d  d 6t | j d  d 6t | j d  d 6t | j d  d 6 |  _ |  j j	   t j
 t j d	 t | j d
 d  g d t | j d d
 d  g d t | j d d  g d t | j d d d  g |  _ |  j j	   d  S(   Nt   jupytert   JUPYTER_CONFIG_DIRt   jupyter_datat   JUPYTER_DATA_DIRt   jupyter_runtimet   JUPYTER_RUNTIME_DIRR&   t
   IPYTHONDIRt   SYSTEM_JUPYTER_PATHt   sharet   ENV_JUPYTER_PATHt   envt   SYSTEM_CONFIG_PATHt   etct   ENV_CONFIG_PATH(   R   t   test_dirR   t   dictR   t   environR+   t   namet	   env_patcht   startt   multipleR)   R*   t
   path_patch(   t   selft   td(    (    s8   lib/python2.7/site-packages/jupyterlab/tests/test_app.pyRI   P   s    	!c         C@ s+   |  j  j   |  j j   |  j j   d  S(   N(   RH   t   stopRK   RD   t   cleanup(   RL   (    (    s8   lib/python2.7/site-packages/jupyterlab/tests/test_app.pyRN   b   s    c         C@ s   |  j    |  j j S(   N(   RI   RD   RG   (   RL   (    (    s8   lib/python2.7/site-packages/jupyterlab/tests/test_app.pyt	   __enter__g   s    
c         G@ s   |  j    d  S(   N(   RN   (   RL   t   exc_info(    (    s8   lib/python2.7/site-packages/jupyterlab/tests/test_app.pyt   __exit__k   s    (   t   __name__t
   __module__t   __doc__RI   RN   RP   RR   (    (    (    s8   lib/python2.7/site-packages/jupyterlab/tests/test_app.pyR5   J   s
   			t   ProcessTestAppc           B@ s\   e  Z d  Z e d  Z e e    Z e e    Z d   Z	 d   Z
 d   Z d   Z RS(   sI   A process app for running tests, includes a mock contents directory.
    t   *c         C@ s*   t    |  _ |  j j   t j |   d  S(   N(   R5   RH   RI   R	   t   __init__(   RL   (    (    s8   lib/python2.7/site-packages/jupyterlab/tests/test_app.pyRX   v   s    c         C@ s   d S(   s   Disable server extensionsN(    (   RL   (    (    s8   lib/python2.7/site-packages/jupyterlab/tests/test_app.pyt   init_server_extensions{   s    c         C@ s3   t    d |  j _ |  j |  j _ t j |   d  S(   NR#   (   R4   t   kernel_managert   default_kernel_namet   workspaces_dirt
   lab_configR	   RI   (   RL   (    (    s8   lib/python2.7/site-packages/jupyterlab/tests/test_app.pyRI      s    c         C@ s{   |  j  j   |  j j   |  j j   y t j | j    Wn6 t k
 rv } |  j j	 t
 |   t j d  n Xd  S(   Ni   (   t   http_serverRN   t   io_loopRH   R   t   _exitt   resultt	   Exceptiont   logt   errort   str(   RL   t   futuret   e(    (    s8   lib/python2.7/site-packages/jupyterlab/tests/test_app.pyt   _process_finished   s    (   RS   RT   RU   R   t   allow_originR   t   notebook_dirR    R\   RX   RY   RI   Rh   (    (    (    s8   lib/python2.7/site-packages/jupyterlab/tests/test_app.pyRV   o   s   			t   KarmaTestAppc           B@ s/   e  Z d  Z e d  Z e d  Z d   Z RS(   s9   A notebook app that runs the jupyterlab karma tests.
    s   src/*.spec.ts*t    c      	   C@ su  |  j  j d } t |  d d  } t d |  j d | d t |  d d  } |  j } t | d d	  } t j	 j
 t | d   s t j t | d   n  t | d
  ! } | j d t j |   Wd QXt j   } | j d d d | j   \ } }	 | j p|  j }
 t j t | |
   } | sMd } t | |
 | f   n  t t | d    } t j |  } Wd QX| d j d d  } t j t t d d d |   } t j
 |  sΣt d |   n  t rϊ| j d  } | j d  } n  t j j    } | | d <| j! d t" j# |
   | j! d |  |  j } d d g t$ j% d } | t d | d |  f S(    s   Get the command to run.t   terminals_availablet   tokenRl   t   baseUrlt   terminalsAvailablet   foot   bart   builds   injector.jsR   sd  
            require('es6-promise/dist/es6-promise.js');
            require('@phosphor/widgets/style/index.css');

            var node = document.createElement('script');
            node.id = 'jupyter-config-data';
            node.type = 'application/json';
            node.textContent = '%s';
            document.body.appendChild(node);
            Ns	   --patternt   actiont   stores$   No files matching "%s" found in "%s"s   package.jsonRG   s   @jupyterlab/test-s   ..t   packagessa   No source package directory found for "%s", use the pattern "@jupyterlab/test-<package_dir_name>"s   utf-8t   KARMA_INJECT_FILEt   KARMA_FILE_PATTERNt   KARMA_COVER_FOLDERt   karmaRI   i   R@   t   cwd(&   t   web_appt   settingst   getattrRE   t   connection_urlRe   t   karma_base_dirR+   R   R   t   existsR-   R   R   R.   R/   t   argparset   ArgumentParsert   add_argumentt   parse_known_argst   patternt   karma_patternt   globt
   ValueErrort   loadt   replaceR   t   realpatht   HEREt   PY2t   encodeRF   t   copyt
   setdefaultR   t   unicode_to_strR'   R!   (   RL   Rp   Rn   t   configR{   t   karma_inject_fileR   t   parsert   argsR!   R   t   filest   msgt   dataRG   t   folderR@   t   cmd(    (    s8   lib/python2.7/site-packages/jupyterlab/tests/test_app.pyt   get_command   sL    			!
	(   RS   RT   RU   R   R   R   R   (    (    (    s8   lib/python2.7/site-packages/jupyterlab/tests/test_app.pyRk      s   c         C@ s@   t  j t  j  t j   } |  | _ | j g   | j   d S(   s2   Run a karma test in the given base directory.
    N(   t   loggingt   disablet   WARNINGRk   t   instanceR   t
   initializeRI   (   t   base_dirt   app(    (    s8   lib/python2.7/site-packages/jupyterlab/tests/test_app.pyt	   run_karmaΡ   s
    	t   __main__(2   RU   t
   __future__R    R   R   R   R   t   os.pathR   R+   R   R   R   R.   R   R'   R   R   t   unittest.mockR   t   ImportErrort   mockt	   traitletsR   t   ipython_genutilsR   t   ipython_genutils.tempdirR   t   ipykernel.kernelspecR   R)   t   jupyterlab_launcher.process_appR	   R   t   dirnamet   __file__R   t   version_infoR   R   R    R4   t   objectR5   RV   Rk   R€   RS   t   TestAppt   launch_instance(    (    (    s8   lib/python2.7/site-packages/jupyterlab/tests/test_app.pyt   <module>   sB   	
		%!A	
