
]c           @   s  d  Z  d d l m Z 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 d d l Z d d l Z d d l m Z d d l m Z m Z m Z 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! m" Z" d d l# m$ Z$ d d l% m& Z& y d d l' m( Z( Wn! e) k
 rd d l* m( Z( n Xy e+ Wn e, k
 re- Z+ n Xy d d l. m/ Z/ m0 Z0 Wn' e) k
 rd d l1 m/ Z/ m0 Z0 n Xe2 Z3 e j4 d d k re5 Z3 n  e j6 d  Z7 e j6 d  Z8 e j9 j: e;  Z< e j4 d Z= d   Z> d   Z? d   Z@ d   ZA d   ZB d   ZC d   ZD e jE jF d d g d eG d  d!  f d" eG d  d!  f d# eG d  d!  f d$ eG d  d!  f d% eG d  d!  f e= d& k  r9d' eG d  d! d( d d) e5 d* e5  f n$ d+ eG d  d! d( d d) e5 d* e5  f d, eG d  d!  f e= d& k  rd- eG d  d!  f n d. eG d  d!  f e= d& k  rd/ eG d  d! d* e5  f n d0 eG d  d! d* e5  f d1 eG d  d!  f d2 eG d  d!  f d3 eG d  d!  f d4 eG d  d!  f d5 eG d  d!  f g  d6    ZH d7   ZI e jE jJ e3 d8 d9 d:    ZK d; e f d<     YZL d= e f d>     YZM d S(?   s1   
Module with tests for the execute preprocessor.
i(   t	   b64encodet	   b64decodeNi   (   t   PreprocessorTestsBasei   (   t   ExecutePreprocessort   CellExecutionErrort	   executenbt   DeadKernelErrori   (   t   ResourcesDict(   t
   TraitError(   t   NotebookNode(   t   KernelSpecManager(   t
   strip_ansi(   t   modified_env(   t   string_types(   t   ProcessPool(   t   Empty(   t	   MagicMockt   patchi    s   0x[0-9a-f]{7,9}s   <ipython-input-\d+-[0-9a-f]+>c         C   sE   y& t  t |  j d    j d  SWn t t f k
 r@ |  SXd  S(   Nt   ascii(   R    R   t   encodet   decodet
   ValueErrort	   TypeError(   t   b64_text(    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   normalize_base64=   s    &c         C   sV   t    } t | _ x" |  D] } t | | |  |  q Wi  | _ i  | _ i  | _ | S(   s"   Make an instance of a preprocessor(   R   t   Truet   enabledt   setattrt   _display_id_mapt   widget_statet   widget_buffers(   t   optst   preprocessort   opt(    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   build_preprocessorF   s    					c   
      C   s   t  j |    } t j | d  } Wd QXt |  } t j |  } x1 | j D]& } d | k rk | d =n  g  | d <qO Wt i d d 6d d 6  | | |  \ } }	 Wd QX| | f S(	   su   Loads and runs a notebook, returning both the version prior to
    running it and the version after running it.

    i   Nt   execution_countt   outputst   80t   COLUMNSt   24t   LINES(	   t   iot   opent   nbformatt   readR"   t   copyt   deepcopyt   cellsR   (
   t   filenameR   t	   resourcest   ft   input_nbR    t   cleaned_input_nbt   cellt	   output_nbt   _(    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   run_notebookS   s    
c             sn   d  t      j i d d 6i d d 6d 6  f d      f d         f d	   } | S(
   s  
    This function prepares a preprocessor object which has a fake kernel client
    to mock the messages sent over zeromq. The mock kernel client will return
    the messages passed into this wrapper back from `preproc.kc.iopub_channel.get_msg`
    callbacks. It also appends a kernel idle message to the end of messages.

    This allows for testing in with following call expectations:

    @prepare_cell_mocks({
        'msg_type': 'stream',
        'header': {'msg_type': 'stream'},
        'content': {'name': 'stdout', 'text': 'foo'},
    })
    def test_message_foo(self, preprocessor, cell_mock, message_mock):
        preprocessor.kc.iopub_channel.get_msg()
        # =>
        # {
        #     'msg_type': 'stream',
        #     'parent_header': {'msg_id': 'fake_id'},
        #     'header': {'msg_type': 'stream'},
        #     'content': {'name': 'stdout', 'text': 'foo'},
        # }
        preprocessor.kc.iopub_channel.get_msg()
        # =>
        # {
        #     'msg_type': 'status',
        #     'parent_header': {'msg_id': 'fake_id'},
        #     'content': {'execution_state': 'idle'},
        # }
        preprocessor.kc.iopub_channel.get_msg() # => None
        message_mock.call_count # => 3
    t   fake_idt   statust   msg_typet   idlet   execution_statet   contentc              s   t  d i i   d 6d 6 S(   Nt   return_valuet   msg_idt   parent_header(   R   (    (   t	   parent_id(    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   shell_channel_message_mock   s    c       	      s:   t  d g    D]& }  t j i i  d 6d 6|   ^ q  S(   Nt   side_effectR@   RA   (   R   R   t   merge_dicts(   t   msg(   t   messagesRB   (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   iopub_messages_mock   s    c            s+   t  j         f d    } | S(   Nc      	      s   t  d d d g   } t i   } i | g d 6| _    } t d t d |  d t d     d t d	    | _  | _   |  | | |  S(
   sW  
            This inner function wrapper populates the preprocessor object with
            the fake kernel client. This client has it's iopub and shell
            channels mocked so as to fake the setup handshake and return
            the messages passed into prepare_cell_mocks as the run_cell loop
            processes them.
            t   sources   "foo" = "bar"R$   R/   t   iopub_channelt   get_msgt   shell_channelt   executeR?   (   R	   R"   t   nbR   t   kcRB   (   t   selft	   cell_mockR    t   message_mock(   t   funcRH   RB   RC   (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   test_mock_wrapper   s    			(   t	   functoolst   wraps(   RS   RT   (   RH   RB   RC   (   RS   sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   prepared_wrapper   s    '(   t   listt   append(   RG   RW   (    (   RH   RG   RB   RC   sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   prepare_cell_mocksi   s    !"c         C   s  t  |   }  d |  k r" |  d =n  d |  k rN t j t d |  d  |  d <n  d |  j d i   k r t j t d |  d d  |  d d <n  d |  j d i   k r d |  d d d <n  xs |  j d i   j   D]Y \ } } t | t  r t j	 j
 d	 k r| j d
 d  } n  t |  |  d | <q q Wd |  k r|g  |  d D]! } t j t d t |   ^ qH} | |  d <n  |  S(   s,   
    Normalizes outputs for comparison.
    t   metadatat   texts	   <HEXADDR>s
   text/plaint   datas(   application/vnd.jupyter.widget-view+jsons
   <MODEL_ID>t   model_idi   s   u's   't	   tracebacks   <IPY-INPUT>(   t   dictt   ret   subt   addr_patt   gett   itemst
   isinstanceR   t   syst   version_infot   majort   replaceR   t   ipython_input_patR   (   t   outputt   keyt   valuet   linet   tb(    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   normalize_output   s&    
 (%/c         C   s   |  d } | d } t  |  t  |  k s2 t  x t | |  D] \ } } | j d g   } | j d g   } t t t |   } t t t |   }	 | |	 k s t  | j d d   }
 | j d d   } |
 | k sB t  qB Wd  S(   NR/   R$   R#   (   t   lent   AssertionErrort   zipRd   RX   t   mapRq   t   None(   t   expectedt   actualt   expected_cellst   actual_cellst   expected_cellt   actual_cellt   expected_outputst   actual_outputst   normalized_expected_outputst   normalized_actual_outputst   expected_execution_countt   actual_execution_count(    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   assert_notebooks_equal   s    

c          C   s7   t    }  t    |  d <t j j t d  |  d d <|  S(   s[   Prepare a notebook resources dictionary for executing test notebooks in the `files` folder.R[   t   filest   path(   R   t   osR   t   joint   current_dir(   t   res(    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   notebook_resources   s    	t
   input_nameR   s   Clear Output.ipynbt   kernel_namet   pythons   Empty Cell.ipynbs   Factorials.ipynbs   HelloWorld.ipynbs   Inline Image.ipynbi   s   Interrupt-IPY6.ipynbt   timeoutt   interrupt_on_timeoutt   allow_errorss   Interrupt.ipynbs   JupyterWidgets.ipynbs)   Skip Exceptions with Cell Tags-IPY6.ipynbs$   Skip Exceptions with Cell Tags.ipynbs   Skip Exceptions-IPY6.ipynbs   Skip Exceptions.ipynbs	   SVG.ipynbs   Unicode.ipynbs   UnicodePy3.ipynbs   update-display-id.ipynbs   Check History in Memory.ipynbc         C   sD   t  j j t d |   } t | | t    \ } } t | |  d S(   sH   Runs a series of test notebooks and compares them to their actual outputR   N(   R   R   R   R   R8   R   R   (   R   R   t
   input_fileR3   R6   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   test_run_all_notebooks   s    c   
      C   s   t  d d  } d } t j j t d |  } t   } t i t |  d 6  g  d D]3 } t j	 d t
 d	 | j d
 |  | | f  ^ qW } g  | D] } | j   ^ q g  | D] } | j d d  ^ q Wd QX|  j   }	 |	 j d k s t  d S(   s   Two notebooks should be able to be run simultaneously without problems.

    The two notebooks spawned here use the filesystem to check that the other notebook
    wrote to the filesystem.R   R   s   Parallel Execute {label}.ipynbR   t   NBEXECUTE_TEST_PARALLEL_TMPDIRt   At   Bt   targett   argst   labelR   i   Nt    (   R   R   (   R`   R   R   R   R   R   R   t   strt	   threadingt   ThreadR8   t   formatt   startt
   readouterrt   errRs   (
   t   capfdt   tmpdirR   R   R   R   R   t   threadst   tt   captured(    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   test_parallel_notebooks  s    	=)t   reasons   Not tested for Python 2c         C   s  t  d d d d  } d } t j j t d |  } t   j   } t j j t d  | d d <t | | |  t d	 d
  n } g  t	 d d  D]* } | j
 t d | | | f d d ^ q } x$ t |  D] \ } }	 |	 j   q WWd QX|  j   }
 |
 j d k st  d S(   s   Ensure that when many IPython kernels are run in parallel, nothing awful happens.

    Specifically, many IPython kernels when run simultaneously would enocunter errors
    due to using the same SQLite history database.
    R   R   R   i   s   HelloWorld.ipynbR   R[   R   t   max_workersi   i    i   R   i   NR   (   R`   R   R   R   R   R   t   build_resourcesR8   R   t   ranget   schedulet	   enumeratet   resultR   R   Rs   (   R   R   R   R   R   t   poolt   it   futurest   indext   futureR   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   test_many_parallel_notebooks+  s    =t   TestExecutec           B   s   e  Z d  Z d Z d   Z d   Z d   Z e j	 j
 d e   j   k d d d    Z d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s&   Contains test functions for execute.pyc         C   s   t  i   d S(   s)   Can a ExecutePreprocessor be constructed?N(   R"   (   RP   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   test_constructorL  s    c         C   s[   t  d t d d   } t j j   } | j | d i  \ } } d | j k sW t  d  S(   NR   R   R   R1   t   language_info(   R"   R`   R+   t   v4t   new_notebookt
   preprocessR[   Rs   (   RP   R    RN   R7   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   test_populate_language_infoP  s    c         C   s[   t  j j t d d  } |  j   } d | d d <t | i  |  \ } } t | |  d S(   s1   Can the kernel be started when the path is empty?R   s   HelloWorld.ipynbR   R[   R   N(   R   R   R   R   R   R8   R   (   RP   R0   R   R3   R6   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   test_empty_pathV  s
    t   python3R   s   requires a python3 kernelspecc      	   C   s   t  j j t d d  } |  j   } t | i d d 6|  \ } } t | |  t j t	  $ t | i d d 6|  \ } } Wd QXd S(   s   Can kernel in nb metadata be found when an empty string is passed?

        Note: this pattern should be discouraged in practice.
        Passing in no kernel_name to ExecutePreprocessor is recommended instead.
        R   s   UnicodePy3.ipynbR   R   N(   R   R   R   R   R   R8   R   t   pytestt   raisesR   Rv   (   RP   R0   R   R3   R6   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   test_empty_kernel_name^  s    c         C   s   t  j j t d d  } |  j   } t  j j |  | d d <t | t d t  |  \ } } |  j	 t
 | d  d  |  j	 t
 | d d d	  d  | d d d	 d } |  j	 | d
 d  |  j	 | d d  |  j	 | d d  d S(   s   Test disabling standard inputR   s   Disable Stdin.ipynbR[   R   R   R/   i   i    R$   t   output_typet   errort   enamet   StdinNotImplementedErrort   evaluesH   raw_input was called, but this frontend does not support input requests.N(   R   R   R   R   R   t   dirnameR8   R`   R   t   assertEqualRr   (   RP   R0   R   R3   R6   Rl   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   test_disable_stdinm  s    !"c      	   C   sq   t  j j t d d  } |  j   } t  j j |  | d d <t j t   t	 | t
 d d  |  Wd QXd S(   s:   Check that an error is raised when a computation times outR   s   Interrupt.ipynbR[   R   R   i   N(   R   R   R   R   R   R   R   R   t   TimeoutErrorR8   R`   (   RP   R0   R   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   test_timeout  s
    c      	   C   sz   t  j j t d d  } |  j   } t  j j |  | d d <d   } t j t   t	 | t
 d |  |  Wd QXd S(   s:   Check that an error is raised when a computation times outR   s   Interrupt.ipynbR[   R   c         S   s   d S(   Ni
   (    (   RI   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   timeout_func  s    R   N(   R   R   R   R   R   R   R   R   R   R8   R`   (   RP   R0   R   R   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   test_timeout_func  s    	c   
      C   s  t  j j t d d  } t j | d   } t j | d  } Wd QX|  j   } t  j j	 |  | d d <t
 i d d	 6 } y | | i   \ } } Wn t k
 r n X| j   \ } } t j | d
  D }	 t |	 _ t j t  # | j | i  d | \ } } Wd QXWd QXd S(   s?   Check that an error is raised when the kernel is_alive is falseR   s   Interrupt.ipynbt   ri   NR[   R   i   R   t   is_alivet   km(   R   R   R   R   R)   R*   R+   R,   R   R   R"   R   t   start_new_kernelR   t   objectt   FalseR?   R   R   R   R   (
   RP   R0   R2   R3   R   R    R6   R   RO   t
   alive_mock(    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   test_kernel_death  s    	c      	   C   s   t  j j t d d  } |  j   } t  j j |  | d d <t j t   } t	 | t
 d t  |  |  j t | j  t  t j d k r d t | j  k s t  n' d j d	 d
  t | j  k s t  Wd QXd S(   sK   
        Check that conversion halts if ``allow_errors`` is False.
        R   s   Skip Exceptions.ipynbR[   R   R   i   i    u   # üñîçø∂ét   utf8Rj   N(   i   i    (   R   R   R   R   R   R   R   R   R   R8   R`   R   t   assertIsInstanceR   Rn   Rg   Rh   Rs   R   (   RP   R0   R   t   exc(    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   test_allow_errors  s    c      	   C   s   t  j j t d d  } |  j   } t  j j |  | d d <t j t   } t	 | t
 d t  |  |  j t | j  t  t j d k r d t | j  k s t  n' d j d	 d
  t | j  k s t  Wd QXd S(   s   
        Check that conversion halts if the ``force_raise_errors`` traitlet on
        ExecutePreprocessor is set to True.
        R   s$   Skip Exceptions with Cell Tags.ipynbR[   R   t   force_raise_errorsi   i    u   # üñîçø∂éR   Rj   N(   i   i    (   R   R   R   R   R   R   R   R   R   R8   R`   R   R   R   Rn   Rg   Rh   Rs   R   (   RP   R0   R   R   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   test_force_raise_errors  s    	c         C   s*  d d l  m } t j j t d d  } t j |   } t j	 | d  } Wd  QXt
 i | d 6 } t j |  } x1 | j D]& } d | k r | d =n  g  | d <q~ Wt i d	 d
 6d d 6   | | |  j    \ } }	 Wd  QX| j j   }
 x0 |
 D]( \ } } |  j | d d j |   q Wd  S(   Ni   (   t   FakeCustomKernelManagerR   s   HelloWorld.ipynbi   t   kernel_manager_classR#   R$   R%   R&   R'   R(   i    s   {} was called(   t   fake_kernelmanagerR   R   R   R   R   R)   R*   R+   R,   R"   R-   R.   R/   R   R   t   expected_methodsRe   t   assertNotEqualR   (   RP   R   R0   R2   R3   R    R4   R5   R6   R7   Rw   t   methodt
   call_count(    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   test_custom_kernel_manager  s"    
c            s   g   d t  f    f d     Y  t j j t  } t j j | d d  } t j |   } t j	 | d  } Wd  QXt
 j |  }     } | j | i   d }  i d d 6d	 d
 6d d 6g k s t  t | |  d  S(   Nt   WrappedPreProcc              s   e  Z    f d    Z RS(   c            s8   t    |   j | | |  } | r4  j |  n  | S(   N(   t   supert   process_messageRY   (   RP   RF   R5   t
   cell_indexR   (   R   R$   (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyR     s    (   t   __name__t
   __module__R   (    (   R   R$   (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyR     s   R   s   HelloWorld.ipynbi   i    t   stdoutt   namet   streamR   s   Hello World
R\   (   R   R   R   R   t   __file__R   R)   R*   R+   R,   R-   R.   R   Rs   R   (   RP   R   R0   R2   R3   t   originalt   wppt   executed(    (   R   R$   sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   test_process_message_wrapper  s    	'c         C   s}   t  j j t d d  } t j |   } t j | d  } Wd  QXt j	 |  } t
 | t  j j |   } t | |  d  S(   NR   s   HelloWorld.ipynbi   (   R   R   R   R   R)   R*   R+   R,   R-   R.   R   R   R   (   RP   R0   R2   R3   R   R   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   test_execute_function  s    c         C   s[  t  j j t d d  } t d d  } |  j   } t  j j |  | d d <t | | |  \ } } g  | d D]) } | d D] } | j d	 i   ^ q~ qp } g  | D]  }	 d
 |	 k r |	 d
 d ^ q }
 | d d d } xR |
 D]J } | d | } d | k st	  d | k st	  d | k s t	  q Wd | k sEt	  d | k sWt	  d S(   sG   Runs a test notebook with widgets and checks the widget state is saved.R   s   JupyterWidgets.ipynbR   R   R[   R   R/   R$   R]   s(   application/vnd.jupyter.widget-view+jsonR^   t   widgetss)   application/vnd.jupyter.widget-state+jsont   statet
   model_namet   model_modulet   version_majort   version_minorN(
   R   R   R   R   R`   R   R   R8   Rd   Rs   (   RP   R   R   R   R3   R6   R5   Rl   t   output_dataR]   t	   model_idst   wdatat   kt   d(    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   test_widgets	  s(    )
 N(   R   R   t   __doc__Rv   t   maxDiffR   R   R   R   t   markt   xfailR
   t   find_kernel_specsR   R   R   R   R   R   R   R   R   R   R   (    (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyR   H  s"   													t   TestRunCellc           B   s	  e  Z d  Z e   d    Z e i d d 6i d d 6d 6i d d 6d 6i d	 d
 6d d 6d 6 d    Z e i d d 6i d d 6d 6i d d 6d 6 d    Z e i d d 6i d d 6d 6i d	 d
 6d d 6d 6i d d 6i d d 6d 6i d d
 6d d 6d 6 d    Z e   d    Z e i d d 6i d d 6d 6i d	 d
 6d d 6d 6i d d 6i d d 6d 6i d d
 6d d 6d 6 d    Z	 e i d d 6i d d 6d 6i  d 6 d    Z
 e i d d 6i d d 6d 6i d	 d
 6d d 6d 6i d d 6i d d 6d 6i d d
 6d d 6d 6 d    Z e i d d 6i d d 6d 6i d	 d
 6d d 6d 6i d d 6i d d 6d 6i  d 6 d    Z e i d d 6i d d 6d 6i d	 d
 6d d 6d 6i d d 6i d d 6d 6i e d 6d 6 d    Z e i d d 6i d d 6d 6i d	 d
 6d d 6d 6i d d 6i d d 6d 6i e d 6d 6i d d 6i d d 6d 6i d d
 6d d 6d 6 d    Z e i d d 6i d d 6d 6i d	 d
 6d d 6d 6i d d 6i d d 6d 6i e d 6d 6i d  d 6i d  d 6d 6i i d! d" 6d# 6i d d 6d$ 6d 6 d%    Z e i d d 6i d d 6d 6i d& d' 6d 6 d(    Z e i d d 6i d d 6d 6i d& d' 6d	 d
 6d d 6d 6 d)    Z e i d* d 6i d* d 6d 6i d+ d, 6i i d d 6d- 6d$ 6d 6 d.    Z e i d* d 6i d* d 6d 6d/ g d0 6i d+ d, 6i i d d 6d- 6d1 g d2 6d$ 6d 6 d3    Z e i d* d 6i d* d 6d 6i d+ d, 6i d d 6d$ 6d 6 d4    Z e i d5 d 6i d5 d 6d 6i i d! d" 6d# 6i d d 6d$ 6d& d' 6d 6 d6    Z e i d5 d 6i d5 d 6d 6i i d+ d7 6d8 6i d! d" 6d# 6i d d 6d$ 6d& d' 6d 6 d9    Z e i d: d 6i d: d 6d 6i i d! d" 6d# 6i d d 6d$ 6d 6 d;    Z e i d: d 6i d: d 6d 6i i d+ d7 6d8 6i d! d" 6d# 6i d d 6d$ 6d 6 d<    Z e i d: d 6i d: d 6d 6i i d+ d7 6d8 6i d! d" 6d# 6i d d 6d$ 6d 6i d: d 6i d: d 6d 6i i d= d7 6d8 6i d> d? 6d# 6i d@ d 6d$ 6d 6i d: d 6i d: d 6d 6i i d+ d7 6d8 6i dA dB 6d# 6i dC d 6dD dE 6d$ 6d 6 dF    Z e i d  d 6i d  d 6d 6i i d! d" 6d# 6i d d 6d$ 6d 6 dG    Z e i d: d 6i d: d 6d 6i i d+ d7 6d8 6i dA dB 6d# 6i dC d 6dD dE 6d$ 6d 6i d  d 6i d  d 6d 6i i dH d7 6d8 6i dA dB 6d# 6i dC d 6dD dE 6d$ 6d 6 dI    Z e i d: d 6i d: d 6d 6i i d+ d7 6d8 6i d! d" 6d# 6i d d 6d$ 6d 6i d  d 6i d  d 6d 6i i d+ d7 6d8 6i dA dB 6d# 6i dC d 6dD dE 6d$ 6d 6 dJ    Z e i dK d 6i dK d 6d 6i d dL 6d dM 6dN g dO 6d 6 dP    Z RS(Q   s8   Contains test functions for ExecutePreprocessor.run_cellc         C   s;   | j  |  | j d k s" t  | j g  k s7 t  d  S(   Ni   (   t   run_cellR   Rs   R$   (   RP   R    RQ   RR   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   test_idle_message+  s    R   R;   t   execute_replyt   headert   wrong_parentR@   RA   R   R   t   fooR\   R>   c         C   s;   | j  |  | j d k s" t  | j g  k s7 t  d  S(   Ni   (   R  R   Rs   R$   (   RP   R    RQ   RR   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   test_message_for_wrong_parent3  s    R:   t   busyR=   c         C   s;   | j  |  | j d k s" t  | j g  k s7 t  d  S(   Ni   (   R  R   Rs   R$   (   RP   R    RQ   RR   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   test_busy_message@  s    t   stderrt   barc         C   s   t  d t    | j j _ d | _ t j t   | j	 |  Wd  QX| j
 d k s\ t  |  j | j i d d 6d d 6d d	 6i d d 6d
 d 6d d	 6g  d  S(   NRD   i   i   R   R   R   R   R  R\   R  R  (   R   R   RO   RL   RK   R   R   R   R   R  R   Rs   t   assertListEqualR$   (   RP   R    RQ   RR   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   test_deadline_exec_replyL  s    	c         C   s<   t    | _ t | _ t j t   | j |  Wd  QXd  S(   N(   R   RD   R   t   raise_on_iopub_timeoutR   R   R   R  (   RP   R    RQ   RR   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   test_deadline_iopubd  s    	c         C   s   t  | j  d  t   g | _ t d i i | j d 6d 6 | j j _ t | _	 t
 j t   | j |  Wd  QX| j d k s t  |  j | j i d d 6d d	 6d
 d 6i d d 6d d	 6d d 6g  d  S(   NiR?   R@   RA   i   R   R   R   R   R  R\   R  R  (   RX   RD   R   R   RB   RO   RL   RK   R   R  R   R   R   R  R   Rs   R  R$   (   RP   R    RQ   RR   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   test_eventual_deadline_iopubm  s     #	t   execute_inputc         C   s;   | j  |  | j d k s" t  | j g  k s7 t  d  S(   Ni   (   R  R   Rs   R$   (   RP   R    RQ   RR   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   test_execute_input_message  s    c         C   si   | j  |  | j d k s" t  |  j | j i d d 6d d 6d d 6i d d 6d d 6d	 d 6g  d  S(
   Ni   R   R   R   R   R  R\   R  R  (   R  R   Rs   R  R$   (   RP   R    RQ   RR   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   test_stream_messages  s
    
t   clear_outputc         C   s;   | j  |  | j d k s" t  | j g  k s7 t  d  S(   Ni   (   R  R   Rs   R$   (   RP   R    RQ   RR   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   test_clear_output_message  s    
t   waitc         C   sc   | j  |  | j d k s" t  |  j | j  | j i d d 6d d 6d d 6g k s_ t  d  S(   Ni   R   R   R   R   R  R\   (   R  R   Rs   t
   assertTruet   clear_before_next_outputR$   (   RP   R    RQ   RR   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   test_clear_output_wait_message  s
    
c         C   sc   | j  |  | j d k s" t  | j s2 t  | j i d d 6d d 6d d 6g k s_ t  d  S(   Ni   R   R   R  R   R  R\   (   R  R   Rs   R  R$   (   RP   R    RQ   RR   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt+   test_clear_output_wait_then_message_message  s
    t   update_display_datat   metabart   metafooR[   R]   c         C   sb   | j  |  | j d k s" t  | j s1 t  | j i d d 6d d 6d d 6g k s^ t  d  S(   Ni   R   R   R   R   R  R\   (   R  R   Rs   R  R$   (   RP   R    RQ   RR   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt2   test_clear_output_wait_then_update_display_message  s
    i*   R#   c         C   sP   | j  |  | j d k s" t  | j d k s7 t  | j g  k sL t  d  S(   Ni   i*   (   R  R   Rs   R#   R$   (   RP   R    RQ   RR   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   test_execution_count_message  s    c         C   sh   | j  |  | j d k s" t  | j d k s7 t  | j i d d 6d d 6d d 6g k sd t  d  S(	   Ni   i*   R   R   R   R   R  R\   (   R  R   Rs   R#   R$   (   RP   R    RQ   RR   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt(   test_execution_count_with_stream_message  s
    t   commt   foobart   comm_idR   c         C   sl   | j  |  | j d k s" t  |  j | j i i d d 6d 6 | j sS t  | j g  k sh t  d  S(   Ni   R  R  R$  (   R  R   Rs   R   R   R   R$   (   RP   R    RQ   RR   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   test_widget_comm_message  s
    	!t   123t   buffersR   t   buffer_pathsc         C   s   | j  |  | j d k s" t  | j i i d d 6d 6k sE t  | j i i d d 6d d 6d	 d	 6g d 6k sy t  | j g  k s t  d  S(
   Ni   R  R  R$  t   MTIzR]   t   base64t   encodingR   (   R  R   Rs   R   R   R$   (   RP   R    RQ   RR   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   test_widget_comm_buffer_message(  s    #	+c         C   s[   | j  |  | j d k s" t  | j s2 t  | j sB t  | j g  k sW t  d  S(   Ni   (   R  R   Rs   R   R   R$   (   RP   R    RQ   RR   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   test_unknown_comm_message?  s
    
t   execute_resultc         C   s   | j  |  | j d k s" t  | j d k s7 t  | j i d d 6i d d 6d 6i d d	 6d
 6d d 6g k sy t  | j s t  d  S(   Ni   i*   R/  R   R  R  R[   R  R  R]   R#   (   R  R   Rs   R#   R$   R   (   RP   R    RQ   RR   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   test_execute_result_messageR  s    
	t
   display_idt	   transientc         C   s   | j  |  | j d k s" t  | j d k s7 t  | j i d d 6i d d 6d 6i d d	 6d
 6d d 6g k sy t  d | j k s t  d  S(   Ni   i*   R/  R   R  R  R[   R  R  R]   R#   R$  (   R  R   Rs   R#   R$   R   (   RP   R    RQ   RR   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt(   test_execute_result_with_display_messagej  s    	t   display_datac         C   sq   | j  |  | j d k s" t  | j i d d 6i d d 6d 6i d d 6d	 6g k s] t  | j sm t  d  S(
   Ni   R4  R   R  R  R[   R  R  R]   (   R  R   Rs   R$   R   (   RP   R    RQ   RR   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt$   test_display_data_without_id_message  s    	c         C   sv   | j  |  | j d k s" t  | j i d d 6i d d 6d 6i d d 6d	 6g k s] t  d
 | j k sr t  d  S(   Ni   R4  R   R  R  R[   R  R  R]   R$  (   R  R   Rs   R$   R   (   RP   R    RQ   RR   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   test_display_data_message  s    
	t   foobar_othert   metabar_othert   metafoo_othert	   bar_othert   metabar2t   metafoo2t   bar2t	   foobarbazt   bazc         C   s   | j  |  | j d k s" t  | j i d d 6i d d 6d 6i d d 6d	 d
 6d 6i d d 6i d d 6d 6i d d 6d 6i d d 6i d d 6d 6i d d 6d	 d
 6d 6g k s t  d | j k s t  d  S(   Ni   R4  R   R;  R<  R[   R=  R  R>  R?  R]   R8  R9  R:  R$  (   R  R   Rs   R$   R   (   RP   R    RQ   RR   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt!   test_display_data_same_id_message  s    	$c         C   sK   | j  |  | j d k s" t  | j g  k s7 t  | j sG t  d  S(   Ni   (   R  R   Rs   R$   R   (   RP   R    RQ   RR   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt+   test_update_display_data_without_id_message  s    t   foobar2c         C   s}   | j  |  | j d k s" t  | j i d d 6i d d 6d 6i d d 6d	 d
 6d 6g k sd t  d | j k sy t  d  S(   Ni   R4  R   R;  R<  R[   R=  R  R>  R?  R]   R$  (   R  R   Rs   R$   R   (   RP   R    RQ   RR   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt,   test_update_display_data_mismatch_id_message  s    	$c         C   s}   | j  |  | j d k s" t  | j i d d 6i d d 6d 6i d d 6d	 d
 6d 6g k sd t  d | j k sy t  d  S(   Ni   R4  R   R;  R<  R[   R=  R  R>  R?  R]   R$  (   R  R   Rs   R$   R   (   RP   R    RQ   RR   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt    test_update_display_data_message  s    	$R   R   R   t   BoomR_   c         C   s]   | j  |  | j d k s" t  | j i d d 6d d 6d d 6d g d	 6g k sY t  d  S(
   Ni   R   R   R  R   R  R   RE  R_   (   R  R   Rs   R$   (   RP   R    RQ   RR   (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   test_error_message  s    	(   R   R   R   RZ   R  R	  R  R  R  R  R  R  R  R   R  R  R   R!  R"  R&  R-  R.  R0  R3  R5  R6  R@  RA  RC  RD  RF  (    (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyR  (  s  $		$	$	$	$2
+(
!!2!(2(((N   R   R+  R    R   R-   t   globR)   R   Ra   R   t   multiprocessingt   mpR+   Rg   R   RU   t   baseR   RM   R   R   R   R   t   exporters.exporterR   t   IPythont	   traitletsR   R	   t   jupyter_client.kernelspecR
   t   nbconvert.filtersR   t   testpathR   t   ipython_genutils.py3compatR   t   pebbleR   t   queueR   t   ImportErrort   QueueR   t	   NameErrort   RuntimeErrort   unittest.mockR   R   t   mockR   t   PY3Rh   R   t   compileRc   Rk   R   R   R   R   t	   IPY_MAJORR   R"   R8   RZ   Rq   R   R   R   t   parametrizeR`   R   R   t   skipifR   R   R  (    (    (    sI   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_execute.pyt   <module>   s   "
						R					3$!'$
	