
    YdI                    |   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mZ d dlmZ d dlmZ d dlmZm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 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(m)Z) d dl*m+Z+ ddl,m-Z-  ej\                  d      Z/ej`                  jc                  e2      Z3 ej\                  d      Z4 ej\                  d      Z5dejl                  d<   g dZ7dUdZ8ddiddddZ9ddiddid d!d id"Z: G d# d$e      Z;d%ed&e jx                  fd'Z=d( Z>dVd)Z?d* Z@dVd+ZAdd,d-ZBd. ZCd/ ZDd0 ZEd1 ZFej                  j                  d2d3gd4d5d6ifd7d5d6ifd8d5d6ifd9d5d6ifd:d5d6ifd;d5d6ifd<d5d6ifd=d5d6ifd>d5d6ifd?d5d6ifd@d5d6ifdAd5d6ifg      dB        ZIdC ZJej                  j                  ej                  dDk(  dEF      dG        ZMdH ZNdI ZOdJ ZPdK ZQdL ZRdM ZSej                  j                   eTed          dNk  dOF      dP        ZU G dQ dRe-      ZV G dS dTe-      ZWy)W    N)	b64decode	b64encodeEmpty)Any)	MagicMockMock)flaky)KernelClientKernelManager)version_info)KernelSpecManager)
strip_ansi)NotebookNode)modified_env)
TraitError)NotebookClientexecute)CellExecutionError   )NBClientTestsBasez0x[0-9a-f]{7,9}zM(<ipython-input-\d+-[0-9a-f]+>|<IPY-INPUT>) in (<module>|<cell line: \d>\(\))zU((Cell|Input) In\s?\[\d+\]|<IPY-INPUT>), (in )?(line \d|<module>|<cell line: \d>\(\))1PYDEVD_DISABLE_FILE_VALIDATION)on_cell_starton_cell_executeon_cell_completeon_cell_executedon_cell_erroron_notebook_starton_notebook_completeon_notebook_errorc                    |rt         D ci c]  }|t                }}nt         D ci c]  }|t                }}| |t        d      t	        |       }|j                         D ]  \  }}t        |||        ||fS c c}w c c}w )Nz,Cannot pass nb and executor at the same time)hook_methods	AsyncMockr   RuntimeErrorr   itemssetattr)nbexecutorasync_hookskeyhookskvs          </usr/lib/python3/dist-packages/nbclient/tests/test_client.pyget_executor_with_hooksr0   <   s    -9:cik!::-9:cik!::	~MNN!"%  1!Q U? ;:s
   A?Bmsg_idfake_idokstatusexecution_countparent_headercontentr5   errorexecute_replymsg_type)r8   r9   r<   headerc                       e Zd Zy)r$   N)__name__
__module____qualname__     r/   r$   r$   V   s    rC   r$   objreturnc                     	 t        j                         }t        j
                  |      }|j                  |        |S # t        $ r, t        j                         }t        j                  |       Y ]w xY w)N)loop)asyncioget_running_loopr%   new_event_loopset_event_loopFuture
set_result)rD   rG   futures      r/   make_futurerO   Z   se    %'') %^^6F
cM  %%%'t$%s   ? 2A43A4c                     	 t        t        | j                  d                  j                  d      S # t        t
        f$ r | cY S w xY w)Nascii)r   r   encodedecode
ValueError	TypeError)b64_texts    r/   normalize_base64rW   e   sD    8??7#;<=DDWMM	" s   14 AAc                    t        |       5 }t        j                  |d      }ddd       t        j                        }|j
                  D ]  }d|v r|d= g |d<    |rd|i|}t        |fi |}t        j                         5  t        j                  dt               t        dd	d
      5  |j                         }ddd       ddd       |fS # 1 sw Y   xY w# 1 sw Y   !xY w# 1 sw Y   |fS xY w)uLoads and runs a notebook, returning both the version prior to
    running it and the version after running it.

       Nr6   outputs	resourcesignoreactioncategory8024COLUMNSLINES)opennbformatreadcopydeepcopycellsr   warningscatch_warningssimplefilterFutureWarningr   r   	filenameoptsr\   finput_nbcleaned_input_nbcellr)   	output_nbs	            r/   run_notebookrx   n   s   
 
h '1==A&' }}X. && $&'Y
 Y/$/.7$7H		 	 	" +XFdT:; 	+ ((*I	+	+ Y)' '"	+ 	+	+ Ys/   C*C,/C  C,C C)	%C,,C8c                     t        |  S N)rx   )argss    r/   run_notebook_wrapperr|      s     rC   c                   K   t        |       5 }t        j                  |d      }ddd       t        j                        }|j
                  D ]  }d|v r|d= g |d<    |rd|i|}t        |fi |}t        ddd      5  |j                          d{   }ddd       ||fS # 1 sw Y   xY w7 # 1 sw Y   |fS xY ww)	rY   rZ   Nr6   r[   r\   ra   rb   rc   )	rf   rg   rh   ri   rj   rk   r   r   async_executerp   s	            r/   async_run_notebookr      s     
 
h '1==A&' }}X. && $&'Y
 Y/$/.7$7H 
$6	7 3"0022	3 Y#' ' 33 YsF   CB&ACB4B2B4C&B/+C2B44C 9
C	reply_msgc                 |     dt        |      j                  dddid        fdfdfd}|S )	aE  
    This function prepares a executor 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.
    r2   r5   execution_stateidle)r<   r9   c            
      n    t        t        t        j                  d iddddxs i                   S )Nr1   r3   r   r4   r7   return_valuer$   rO   r   merge_dicts)	parent_idr   s   r/   shell_channel_message_mockz6prepare_cell_mocks.<locals>.shell_channel_message_mock   sF     $!--*2I)>.2q#I O

 
	
rC   c                      t        D  cg c]%  } t        t        j                  ddii|             ' c}       S c c} w )Nr8   r1   )side_effectr   )msgmessagesr   s    r/   iopub_messages_mockz/prepare_cell_mocks.<locals>.iopub_messages_mock   sQ      $
  %11?XyDY2Z\_`
 	
s   *=c                 J     t        j                          fd       }|S )Nc           
      v   t        di dg       } G d dt              }t        j                  j	                         } ||      }|g|j
                  _                }t        t        |      t         	             t              t        t        d            	      |_	        |_
         | |||      S )
aV  
            This inner function wrapper populates the executor object with
            the fake kernel client. This client has its iopub and shell
            channels mocked so as to fake the setup handshake and return
            the messages passed into prepare_cell_mocks as the execute_cell loop
            processes them.
            "foo" = "bar"codesourcemetadata	cell_typer[   c                       e Zd ZU eed<   y)kprepare_cell_mocks.<locals>.prepared_wrapper.<locals>.test_mock_wrapper.<locals>.NotebookClientWithParentIDr   N)r?   r@   rA   str__annotations__rB   rC   r/   NotebookClientWithParentIDr      s    rC   r   )get_msgr   T)iopub_channelshell_channelr   is_alive)r   r   rg   v4new_notebookr(   rk   r   rO   kcr   )
self	cell_mockr   r(   r)   message_mockfuncr   r   r   s
         r/   test_mock_wrapperzGprepare_cell_mocks.<locals>.prepared_wrapper.<locals>.test_mock_wrapper   s     %&vrI^  ))+B1"5H!*HKK /0L#'='0J0LM!y9"D0AB	HK "+Hh	<@@rC   )	functoolswraps)r   r   r   r   r   s   ` r/   prepared_wrapperz,prepare_cell_mocks.<locals>.prepared_wrapper   s(    			A 
	A< ! rC   )listappend)r   messages_inputr   r   r   r   r   s   `  @@@@r/   prepare_cell_mocksr      sC     IN#HOO7H&6QRS

 !D rC   c                    t        |       } d| v r| d= d| v r!t        j                  t        d| d         | d<   d| j	                  di       v r't        j                  t        d| d   d         | d   d<   d| j	                  di       v rd| d   d   d<   d	| j	                  di       v r!t        j                  | d   d	         | d   d	<   | j	                  di       j                         D ]'  \  }}t        |t              st        |      | d   |<   ) d
| v rjg }| d
   D ][  }t        j                  t        dt        |            }t        j                  t        dt        |            }|j                  |       ] || d
<   | S )z,
    Normalizes outputs for comparison.
    r   textz	<HEXADDR>z
text/plaindata(application/vnd.jupyter.widget-view+jsonz
<MODEL_ID>model_idzimage/svg+xml	tracebackz<IPY-INPUT>)dictresubaddr_patget	xmltodictparser&   
isinstancer   rW   ipython_input_patr   ipython8_input_patr   )outputr+   valuetblines        r/   normalize_outputr      s    &\FV:+vf~Fvvzz&"--')vvhVF^T`Ea'bv|$1VZZ5KKQ]vAB:N&**VR00*3//&.:Y*Zv'jj,224 :
UeS!"25"9F6N3: f;' 	D66+]Jt<LMD66,mZ=MNDIIdO	 !{MrC   c                    | d   }|d   }t        |      t        |      k(  sJ t        ||      D ]  \  }}|j                  dg       }|j                  dg       }t        t	        t
        |            }t        t	        t
        |            }	||	k(  sJ |j                  dd       }
|j                  dd       }|
|k(  rJ  y )Nrk   r[   r6   )lenzipr   r   mapr   )expectedactualexpected_cellsactual_cellsexpected_cellactual_cellexpected_outputsactual_outputsnormalized_expected_outputsnormalized_actual_outputsexpected_execution_countactual_execution_counts               r/   assert_notebooks_equalr     s    g&N'?L~#l"3333&).,&G B"{
 ),,Y;$B7&*3/?AQ+R&S#$(-=~)N$O!*.GGGG#0#4#45F#M !,1BD!I'+AAAABrC   c                  R    ddt         j                  j                  t        d      iiS )zk
    Prepare a notebook resources dictionary for executing test
    notebooks in the ``files`` folder.
    r   pathfiles)osr   joincurrent_dirrB   rC   r/   notebook_resourcesr   (  s#    
 k7!CDEErC   c                     dg}| j                         D cg c]	  }||vs| }}t        j                  j                  |      S c c}w )NzO[IPKernelApp] WARNING | debugpy_stream undefined, debugging will not be enabled)
splitlinesr   linesepr   )
err_outputallowed_linesr   filtered_results       r/   filter_messages_on_error_outputr   0  sM     	ZM )3(=(=(?]4}C\t]O]::???++ ^s
   	AA
input_namerr   zOther Comms.ipynbkernel_namepythonzClear Output.ipynbzEmpty Cell.ipynbzFactorials.ipynbHelloWorld.ipynbzInline Image.ipynbz"Skip Execution with Cell Tag.ipynbz	SVG.ipynbzUnicode.ipynbUnicodePy3.ipynbzupdate-display-id.ipynbzCheck History in Memory.ipynbc                     t         j                  j                  t        d|       }t	        ||t                     \  }}t        ||       y)zHRuns a series of test notebooks and compares them to their actual outputr   N)r   r   r   r   rx   r   r   )r   rr   
input_filert   rw   s        r/   test_run_all_notebooksr   :  s;    & k7J?J&z49K9MNHi8Y/rC   c           
         ddi}d}t         j                  j                  t        d|      }t	               }t        dt        |      i      5  dD cg c]0  }t        j                  t        |j                  |      ||f      2 }}|D ]  }|j                           |D ]  }|j                  d	
        	 ddd       | j                         }	t        |	j                        dk(  sJ yc c}w # 1 sw Y   9xY w)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   Parallel Execute {label}.ipynbr   NBEXECUTE_TEST_PARALLEL_TMPDIRABlabel)targetr{      timeoutN )r   r   r   r   r   r   r   	threadingThreadrx   formatstart
readouterrr   err)
capfdtmpdirrr   r   r   resr   threadstcaptureds
             r/   test_parallel_notebooksr  R  s     8$D1Jk7J?J

C	7VE	F  $
 L
8I8IPU8I8VX\^a7bc
 
  	AGGI	 	AFF2F	 !H*8<<8B>>>
 s   C15C,2C1,C11C:ntz!warns about event loop on Windowsreasonc                    ddd}d}t         j                  j                  t        d|      }t	               j                         }t         j                  j                  t        d      |d   d<   t        j                         5  t        j                  dt        	       t        |||       t        j                  j                  d
      5 }|j                  t        t!        d      D cg c]  }|||f	 c}       ddd       ddd       | j#                         }t%        |j&                        dk(  sJ yc c}w # 1 sw Y   AxY w# 1 sw Y   ExY w)Ensure that when many IPython kernels are run in parallel, nothing awful happens.

    Specifically, many IPython kernels when run simultaneously would encounter errors
    due to using the same SQLite history database.
    r      r   r   r   r   r   r   r]   r^      )max_workers   Nr   )r   r   r   r   r   build_resourcesrl   rm   rn   ro   rx   
concurrentfuturesProcessPoolExecutorr   r|   ranger   r   r   )r  rr   r   r   r  r)   ir  s           r/   test_many_parallel_notebooksr  k  s!    $2D#Jk7J?J


-
-
/C ggll;@C
OF		 	 	" \XF 	Zs+333B 	\hLL-QVWXQY/ZAT30G/Z[	\\ !H*8<<8B>>> 0[	\ 	\\ \s7   A	E	D=*D86D==E	8D==E	E		Ec                 `   ddid}t         j                  j                  t        d|      t	               t        dt        |      i      5  fd}t        j                   |              ddd       | j                         }t        |j                        dk(  sJ y# 1 sw Y   4xY w)	r   r   r   r   r   r   c                     K   dD  cg c]  } t        j                  |             ! }} t        j                  |  d {    y c c} w 7 
w)Nr   r   )r   r   rH   gather)r   tasksr   rr   r  s     r/   	run_tasksz0test_async_parallel_notebooks.<locals>.run_tasks  s[      ( #:#4#45#4#A4ME  ..%(((	 )s   A$A	AAANr   )r   r   r   r   r   r   r   rH   runr   r   r   )r  r  r   r  r  r   rr   r  s        @@@r/   test_async_parallel_notebooksr    s     8$D1Jk7J?J

C	7VE	F 	!	) 	IK 	! !H*8<<8B>>>	! 	!s   "B$$B-c                    dddd}t         j                  j                  t        d|      t	               j                         t         j                  j                  t        d      d   d<   t               fd}t        j                   |              | j                         }t        |j                        d	k(  sJ y
)r  r   r  r  r   r   r   r   c                     K   t        d      D  cg c]  } t               }} t        j                  |  d {    y c c} w 7 
w)NrZ   )r  r   rH   r  )r  r  r   rr   r  s     r/   r  z5test_many_async_parallel_notebooks.<locals>.run_tasks  sC     DI!HMq#Jc:MMnne$$$ N$s   A	AA	AA	r   N)r   r   r   r   r   r  rx   rH   r  r   r   r   )r  r   r  r  r   rr   r  s       @@@r/   "test_many_async_parallel_notebooksr"    s     $2D#Jk7J?J


-
-
/C ggll;@C
OF T3'% KK	!H*8<<8B>>>rC   c                     ddi} d}t         j                  j                  t        d|      }t	               }t        || |      \  }}d }|d   d   d   d	   } ||d
         } ||d         }	 ||d         }
 ||d         } ||d   d   d   d   d         } ||d   d   d   d   d         }t        j                  d      }||z
  |k  sJ |	|z
  |k  sJ |
|z
  |k  sJ ||z
  |k  sJ y)zCompare the execution timing information stored in the cell with the
    actual time it took to run the cell. Also check for the cell timing string
    format.r   r   zSleep1s.ipynbr   c                 F    d}t         j                   j                  | |      S )Nz%Y-%m-%dT%H:%M:%S.%fZ)datetimestrptime)stime_formats     r/   get_time_from_strz0test_execution_timing.<locals>.get_time_from_str  s     -  ))![99rC   rk   r   r   	executionziopub.status.busyziopub.execute_inputzshell.execute_replyziopub.status.idler  r[   r   r      d   )millisecondsN)r   r   r   r   r   rx   r%  	timedelta)rr   r   r   r  rt   rw   r)  execution_timingstatus_busyexecute_inputr;   status_idle
cell_startcell_enddeltas                  r/   test_execution_timingr6    sK    8$D Jk7J?J

C&z4=Hi: !)!,Z8E#$45H$IJK%&67L&MNM%&67L&MNM#$45H$IJK"9W#5a#8#CA#Fv#NOJ 7!3A!6y!A!!DV!LMHC0E#e+++:%---8#e+++!E)))rC   c                      t         j                  j                         } t        |       }|j	                         5  |j
                  J 	 d d d        |j
                  J y # 1 sw Y   xY wrz   )rg   r   r   r   setup_kernelr   )r(   r)   s     r/   test_synchronous_setup_kernelr9    sa    		!	!	#Bb!H				  '{{&&&' ;;	' 's   A!!A*c                     t         j                  j                         } t               }t	        | |      }|j                          |j                         }|J |j                          |j                          |j                          y )Nkm)
rg   r   r   r   r   start_new_kernelstart_new_kernel_clientshutdowncleanup_resourcesstop_channelsr(   r<  r)   r   s       r/   &test_startnewkernel_with_kernelmanagerrC    sn    		!	!	#B	BbR(H		)	)	+B>> KKMrC   c                     t         j                  j                         } t               }t	        | |      }|j                         }|j                  g k(  sJ |j                          |j                  dgk(  sJ |j                          |j                  dgk(  sJ |j                          |j                          |j                          y )Nr;  z#--HistoryManager.hist_file=:memory:)rg   r   r   r   r   clientextra_argumentsr=  r?  r@  rA  rB  s       r/   *test_start_new_kernel_history_file_settingrG    s    		!	!	#B	BbR(H	B ##r)))##(M'NNNN##(M'NNNN KKMrC      zrequires client 7+c                      G d dt               } t        j                  j                         }t	               }| |_        t        ||      }|j                          |j                  sJ |j                  J t        j                  t              5 }|j                          d d d        t        j                  j                   d         dk(  sJ |j"                  J |j                  J |j                  rJ y # 1 sw Y   [xY w)Nc                   @    e Zd Z	 	 	 	 	 d
dedededededdfdZdd	Zy)Ltest_start_new_kernel_client_cleans_up_kernel_on_failure.<locals>.FakeClientshelliopubstdinhbcontrolrE   Nc                     t        d      )N	Any error)	Exception)r   rL  rM  rN  rO  rP  s         r/   start_channelsz[test_start_new_kernel_client_cleans_up_kernel_on_failure.<locals>.FakeClient.start_channels	  s     K((rC   c                      y rz   rB   r   s    r/   rA  zZtest_start_new_kernel_client_cleans_up_kernel_on_failure.<locals>.FakeClient.stop_channels  s    rC   )TTTTT)rE   N)r?   r@   rA   boolrT  rA  rB   rC   r/   
FakeClientrK    sW      	)	) 	) 		)
 	) 	) 	)	rC   rX  r;  r   rR  )r   rg   r   r   r   client_factoryr   r=  
has_kernelr<  pytestraisesrS  r>  r   r   r{   r   )rX  r(   r<  r)   r   s        r/   8test_start_new_kernel_client_cleans_up_kernel_on_failurer]    s    \  
	!	!	#B	B"BbR(H===;;"""	y	! +S((*+ syy~~a ![000;;;;}}}+ +s   C<<Dc                   L   e Zd ZdZdZd Zd Zd Zej                  j                  d e       j                         vd      d	        Zd
 Zd Zd Zd Zed        Zd Zd Zd Zd Zd Zd Zd Zd Zej                  j9                         d        Zd Zd Zd Z d Z!d Z"y)TestExecutez&Contains test functions for execute.pyNc                 R    t        t        j                  j                                y rz   )r   rg   r   r   rV  s    r/   test_constructorzTestExecute.test_constructor,  s    x{{//12rC   c                     t         j                  j                         }t        |d      }|j	                         }d|j
                  v sJ y )Nr   )r   language_info)rg   r   r   r   r   r   )r   r(   r)   s      r/   test_populate_language_infoz'TestExecute.test_populate_language_info/  s@    [[%%'!"(;"++---rC   c                     t         j                  j                  t        dd      }| j	                         }d|d   d<   t        |i |      \  }}t        ||       y)z1Can the kernel be started when the path is empty?r   r   r   r   r   N)r   r   r   r   r  rx   r   r   rq   r  rt   rw   s        r/   test_empty_pathzTestExecute.test_empty_path5  sR    77<<W6HI""$"$J*8R=)x3rC   python3zrequires a python3 kernelspecr	  c                 *   t         j                  j                  t        dd      }| j	                         }t        |ddi|      \  }}t        ||       t        j                  t              5  t        |ddi|      \  }}ddd       y# 1 sw Y   yxY w)zCan 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 NotebookClient is recommended instead.
        r   r   r   r   N)
r   r   r   r   r  rx   r   r[  r\  r   rf  s        r/   test_empty_kernel_namez"TestExecute.test_empty_kernel_name=  s     77<<W6HI""$*8mR5H#N)x3]]:& 	U".x-9NPS"THi	U 	U 	Us   -B		Bc                    t         j                  j                  t        dd      }| j	                         }t         j                  j                  |      |d   d<   t        |ddi|      \  }}| j                  t        |d         d       | j                  t        |d   d	   d
         d       |d   d	   d
   d	   }| j                  |d   d       | j                  |d   d       | j                  |d   d       y)zTest disabling standard inputr   zDisable Stdin.ipynbr   r   allow_errorsTrk   r   r   r[   output_typer:   enameStdinNotImplementedErrorevaluezHraw_input was called, but this frontend does not support input requests.N)	r   r   r   r   r  dirnamerx   assertEqualr   )r   rq   r  rt   rw   r   s         r/   test_disable_stdinzTestExecute.test_disable_stdinN  s    77<<W6KL""$"$''//(";J*8nd5KSQ) 	Yw/0!4Yw/29=>B7#A&y1!4.8*DE8V	
rC   c                    t         j                  j                  t        dd      }| j	                         }t         j                  j                  |      |d   d<   t        j                  t              5 }t        |ddi|       ddd       | j                  t        j                  j                  d         d	       y# 1 sw Y   <xY w)
:Check that an error is raised when a computation times outr   Interrupt.ipynbr   r   r   r   Nr   zA cell timed out while it was being executed, after 1 seconds.
The message was: Cell execution timed out.
Here is a preview of the cell contents:
-------------------
while True: continue
-------------------
)r   r   r   r   r  rq  r[  r\  TimeoutErrorrx   rr  r   r   r{   )r   rq   r  r   s       r/   test_timeoutzTestExecute.test_timeoutc  s    77<<W6GH""$"$''//(";J]]<( 	8CIq>37	8		q!"		
	8 	8s   4B??Cc                 8   t         j                  j                  t        dd      }| j	                         }t         j                  j                  |      |d   d<   d }t        j                  t              5  t        |d|i|       ddd       y# 1 sw Y   yxY w)ru  r   rv  r   r   c                      y)N
   rB   )r   s    r/   timeout_funcz3TestExecute.test_timeout_func.<locals>.timeout_func|  s    rC   r|  N)
r   r   r   r   r  rq  r[  r\  rw  rx   )r   rq   r  r|  s       r/   test_timeout_funczTestExecute.test_timeout_funcv  s    77<<W6GH""$"$''//(";J	 ]]<( 	HNL#A3G	H 	H 	Hs   7BBc                 ~   t         j                  j                         }t        |dt              }|j                         }d|j                  v sJ |j                         5  |j                  J |j                  |j                  j                               }|J d|d   d   v sJ 	 d d d        y # 1 sw Y   y xY w)Nr   )r   kernel_manager_classrc  namer9   )rg   r   r   r   r   r   r   r8  r   wait_for_replykernel_info)r   r(   r)   info_msgs       r/   test_sync_kernel_managerz$TestExecute.test_sync_kernel_manager  s    [[%%'!"(Q^_"++---""$ 	B;;***..x{{/F/F/HIH'''Xi0AAAA		B 	B 	Bs   !AB33B<c                 |   t         j                  j                  t        dd      }t	        |      5 }t        j                  |d      }ddd       | j                         }t         j                  j                  |      |d   d<   t        d      }t        j                  t              5  |j                          ddd       |j                         }d	 }||_        t        j                  t         t        f      5  |j                         \  }}ddd       y# 1 sw Y   xY w# 1 sw Y   kxY w# 1 sw Y   yxY w)
zVCheck that an error is raised when the kernel is_alive is false after a cell timed outr   rv  rZ   Nr   r   r   r   c                     K   yw)NFrB   rB   rC   r/   r   z=TestExecute.test_kernel_death_after_timeout.<locals>.is_alive  s	     s   )r   r   r   r   rf   rg   rh   r  rq  r   r[  r\  rw  r   create_kernel_managerr   r%   )	r   rq   rs   rt   r  r)   r<  r   rw   s	            r/   test_kernel_death_after_timeoutz+TestExecute.test_kernel_death_after_timeout  s    77<<W6GH(^ 	+q}}Q*H	+""$"$''//(";J!(A6]]<( 		++-	  ]]L,78 	5"*"2"2"4Hi	5 	5%	+ 	+	 		5 	5s#   D+D&=D2D#&D/2D;c                 L   t         j                  j                  t        dd      }t	        |      5 }t        j                  |d      }ddd       t              }t        j                  t              5  |j                          ddd       y# 1 sw Y   GxY w# 1 sw Y   yxY w)ziCheck that an error is raised when the kernel is_alive is false during a cell
        execution.
        r   Autokill.ipynbrZ   N)r   r   r   r   rf   rg   rh   r   r[  r\  r%   r   r   rq   rs   rt   r)   s        r/   "test_kernel_death_during_executionz.TestExecute.test_kernel_death_during_execution  s     77<<W6FG(^ 	+q}}Q*H	+ "(+]]<( 		 		+ 	+
	 	s   B4BBB#c                    t         j                  j                  t        dd      }| j	                         }t         j                  j                  |      |d   d<   t        j                  t              5 }t        |ddi|       ddd       t        t        j                        t              sJ t        t        |j                              }t        j                  j!                  d      sd	|v sJ yy# 1 sw Y   sxY w)
zK
        Check that conversion halts if ``allow_errors`` is False.
        r   zSkip Exceptions.ipynbr   r   rl  FNwin   # üñîçø∂é)r   r   r   r   r  rq  r[  r\  r   rx   r   r   r   r   sysplatform
startswithr   rq   r  excexc_strs        r/   test_allow_errorszTestExecute.test_allow_errors  s     77<<W6MN""$"$''//(";J]]-. 	A#NE#:C@	A #cii.#...S^, ||&&u-&'111 .	A 	As   4C66C?c                 P   t         j                  j                  t        dd      }| j	                         }t         j                  j                  |      |d   d<   t        j                  t              5 }t        |ddi|       ddd       t        t        j                              }d|v sJ t        j                  j                  d	      sd
|v sJ d|v sJ d|v sJ d|v sJ d|v sJ dj                  g d      |v sJ dj                  g d      |v sJ y# 1 sw Y   xY w)z~
        Check that conversion halts if the ``force_raise_errors`` traitlet on
        NotebookClient is set to True.
        r   z$Skip Exceptions with Cell Tags.ipynbr   r   force_raise_errorsTNzException: messager  r  stderrstdoutzhello
z	errorred

)r   z----- stdout -----hello---)r   z----- stderr -----errorredr  )r   r   r   r   r  rq  r[  r\  r   rx   r   r   r   r  r  r  r  s        r/   test_force_raise_errorsz#TestExecute.test_force_raise_errors  s,   
 77<<W6\]""$"$''//(";J]]-. 	F#$8$#?E	F S^, $w... ||&&u-&'1117"""7"""G###w&&&yyCDOOOyyFG7RRR%	F 	Fs   4DD%c                    t         j                  j                  t        dd      }t	        |      5 }t        j                  |d      }d d d        t        | j                               }|j                  d       |j                  }|J |j                  d       ||j                  k(  sJ |j                  dd       ||j                  k7  sJ y # 1 sw Y   xY w)	Nr   r   rZ   r\   F
cleanup_kcT)reset_kcr  r   r   r   r   rf   rg   rh   r   r  r   r   )r   rq   rs   rt   r)   r   s         r/   test_reset_kernel_clientz$TestExecute.test_reset_kernel_client  s    77<<W6HI(^ 	+q}}Q*H	+ "**,

 	E*[[~~E*X[[   $59 X[[   )	+ 	+s   CCc                 l   t         j                  j                  t        dd      }t	        |      5 }t        j                  |d      }d d d        t        | j                               }|j                          |j                  J |j                  d       |j                  J y # 1 sw Y   cxY w)Nr   r   rZ   r  Fr  r  r  s        r/   test_cleanup_kernel_clientz&TestExecute.test_cleanup_kernel_client  s    77<<W6HI(^ 	+q}}Q*H	+ "**,

 	{{"""E* {{&&&	+ 	+s   B**B3c                 <   ddl m} t        j                  j	                  t
        dd      }t        |      5 }t        j                  |d      }d d d        t        j                        }|j                  D ]  }d|v r|d= g |d<    t        || j                         |      }t        d	d
d      5  |j                          d d d        |j                   j#                         }|D ]  \  }	}
| j%                  |
d|	 d        y # 1 sw Y   xY w# 1 sw Y   PxY w)Nr   )FakeCustomKernelManagerr   r   rZ   r6   r[   )r\   r  ra   rb   rc   r   z was called)fake_kernelmanagerr  r   r   r   r   rf   rg   rh   ri   rj   rk   r   r  r   r   expected_methodsr&   assertNotEqual)r   r  rq   rs   rt   ru   rv   r)   r   method
call_counts              r/   test_custom_kernel_managerz&TestExecute.test_custom_kernel_manager  s   ?77<<W6HI(^ 	+q}}Q*H	+  ==2$** 	!D D(*+ DO	!
 "**,!8
 dT:; 		 +;;AAC"* 	GFJ
A&/EF	G+	+ 	+ 	 	s   D2DDDc                   	 g 	 G 	fddt               }t        j                  j                  t              }t        j                  j                  |dd      }t        |      5 }t        j                  |d      }d d d        t        j                        } ||      }|j                         }	dddd	gk(  sJ t        ||       y # 1 sw Y   OxY w)
Nc                   "     e Zd Z fdZ xZS )@TestExecute.test_process_message_wrapper.<locals>.WrappedPreProcc                 P    t         |   |||      }|rj                  |       |S rz   )superprocess_messager   )r   r   rv   
cell_indexresult	__class__r[   s        r/   r  zPTestExecute.test_process_message_wrapper.<locals>.WrappedPreProc.process_message.  s*    0dJGNN6*rC   )r?   r@   rA   r  __classcell__)r  r[   s   @r/   WrappedPreProcr  -  s     rC   r  r   r   rZ   r  streamzHello World
)r  rm  r   )r   r   r   rq  __file__r   rf   rg   rh   ri   rj   r   r   )
r   r  r   rq   rs   rt   originalwppexecutedr[   s
            @r/   test_process_message_wrapperz(TestExecute.test_process_message_wrapper*  s    	^ 	 ggooh/77<<W6HI(^ 	+q}}Q*H	+ ==*X&;;=HX_````x2	+ 	+s   $C		Cc                 N   t         j                  j                  t        dd      }t	        |      5 }t        j                  |d      }d d d        t        j                        }t        |t         j                  j                  |            }t        ||       y # 1 sw Y   TxY w)Nr   r   rZ   )r   r   r   r   rf   rg   rh   ri   rj   r   rq  r   )r   rq   rs   rt   r  r  s         r/   test_execute_functionz!TestExecute.test_execute_function@  sz    77<<W6HI(^ 	+q}}Q*H	+ ==*8RWW__X%>?x2	+ 	+s   BB$c           	         t         j                  j                  t        dd      }ddi}| j	                         }t         j                  j                  |      |d   d<   t        |||      \  }}|d   D cg c]  }|d   D ]  }|j                  d	i          }}}|D 	cg c]  }	d
|	v r|	d
   d    }
}	|d   d   d   }|
D ]  }|d   |   }d|v sJ d|v sJ d|v rJ  d|v sJ d|v sJ yc c}}w c c}	w )zGRuns a test notebook with widgets and checks the widget state is saved.r   zJupyterWidgets.ipynbr   r   r   r   rk   r[   r   r   r   widgetsz)application/vnd.jupyter.widget-state+jsonstate
model_namemodel_moduleversion_majorversion_minorN)r   r   r   r   r  rq  rx   r   )r   r   rr   r  rt   rw   rv   r   output_datar   	model_idswdatar-   ds                 r/   test_widgetszTestExecute.test_widgetsK  s\    WW\\+w8NO
x(""$"$''//*"=J*:tSA) 09/A
'+PTU^P_
FLFJJvr"
"
 
 $
9TA ;<ZH
	 
 *%i01\] 	 Agq!A1$$$!Q&&&a<<		 
 %'''%'''#

s   7#C/!C5c                 (   t         j                  j                  t        dd      }t	        |      5 }t        j                  |d      }d d d        t              \  }}|j                          |d   j                          |d   j                          |d   j                          |d   j                          |d	   j                          |d
   j                          |d   j                          |d   j                          y # 1 sw Y   xY wNr   r   rZ   r(   r   r   r   r   r   r   r    r!   r   r   r   r   rf   rg   rh   r0   r   assert_called_onceassert_not_calledr   rq   rs   rt   r)   r,   s         r/   test_execution_hookzTestExecute.test_execution_hookg      77<<W6HI(^ 	+q}}Q*H	+1X>%o113 335 !446 !446o002!"557$%88:!"446	+ 	+   DDc                    t         j                  j                  t        dd      }t	        |      5 }t        j                  |d      }d d d        t              \  }}t        j                  t              5  |j                          d d d        |d   j                          |d   j                          |d   j                          |d   j                          |d	   j                          |d
   j                          |d   j                          |d   j                          y # 1 sw Y   xY w# 1 sw Y   xY wNr   zError.ipynbrZ   r  r   r   r   r   r   r   r    r!   r   r   r   r   rf   rg   rh   r0   r[  r\  r   r   r  r  r  s         r/   test_error_execution_hook_errorz+TestExecute.test_error_execution_hook_errorv     77<<WmD(^ 	+q}}Q*H	+1X>%]]-. 		o113 335 !446 !446o113!"557$%88:!"446	+ 	+	 	   D*8D6*D36D?c                    t         j                  j                  t        dd      }t	        |      5 }t        j                  |d      }d d d        t              \  }}t        j                  t              5  |j                          d d d        |d   j                          |d   j                          |d   j                          |d   j                          |d	   j                          |d
   j                          |d   j                          |d   j                          y # 1 sw Y   xY w# 1 sw Y   xY w)Nr   r  rZ   r  r   r   r   r   r   r   r    r!   )r   r   r   r   rf   rg   rh   r0   r[  r\  r%   r   r  r  r  s         r/   test_error_notebook_hookz$TestExecute.test_error_notebook_hook  s   77<<W6FG(^ 	+q}}Q*H	+1X>%]]<( 		o113 335 !446 !335o002!"557$%88:!"557	+ 	+	 	r  c                 (   t         j                  j                  t        dd      }t	        |      5 }t        j                  |d      }d d d        t              \  }}|j                          |d   j                          |d   j                          |d   j                          |d   j                          |d	   j                          |d
   j                          |d   j                          |d   j                          y # 1 sw Y   xY wr  r  r  s         r/   test_async_execution_hookz%TestExecute.test_async_execution_hook  r  r  c                    t         j                  j                  t        dd      }t	        |      5 }t        j                  |d      }d d d        t              \  }}t        j                  t              5  |j                          d d d        |d   j                          |d   j                          |d   j                          |d   j                          |d	   j                          |d
   j                          |d   j                          |d   j                          y # 1 sw Y   xY w# 1 sw Y   xY wr  r  r  s         r/   test_error_async_execution_hookz+TestExecute.test_error_async_execution_hook  r  r  )#r?   r@   rA   __doc__maxDiffra  rd  rg  r[  markxfailr   find_kernel_specsrj  rs  rx  r}  r  r
   r  r  r  r  r  r  r  r  r  skipr  r  r  r  r  r  rB   rC   r/   r_  r_  '  s    0G3.4 [[*,>>@@.  U	U
*
&
H	B 5 502"S8!2'(G:3,	3 [[( (677 8 77rC   r_  c                   	   e Zd ZdZ e       d        Z edddiddidd	d
d      d        Z edddiddid      d        Z edddidd	d
ddddiddd
d      d        Z e       d        Z	 edddidd	d
ddddiddd
d      d        Z
 edddii d      d        Z edddidd	d
ddddiddd
d      d        Z edddidd	d
ddddii d      d        Z edddidd	d
ddddiddid      d        Z edddidd	d
ddddiddiddddiddd
d      d        Z edddidd	d
ddddiddidd dd id!d"id	did#d      d$        Z edddid%d&id      d'        Z edddid%d&id      d(        Z edddid&dd	d)d      d*        Z ed+dd+id,d-d	diid.d      d/        Z ed+dd+id0gd,d	did1ggd2d.d3      d4        Z ed+dd+id0gd,d	did1ggd2d.d3d+dd+id0gd,d5d6id7ggd2d.d3      d8        Z ed+dd+id,d	did.d      d9        Z ed:dd:id!d"id	did&d;d      d<        Z ed:dd:id=d,id!d"id	did&d>d      d?        Z ed@dd@id!d"id	did#d      dA        Z ed@dd@id=d,id!d"id	didBd      dC        Z ed@dd@id=d,id!d"id	didBdd@dd@id=dDidEdFid	dGidBdd@dd@id=d,idHdIid6dJdKdBd      dL        Z ed dd id!d"id	did#d      dM        Z ed@dd@id=d,idHdIid6dJdKdBdd dd id=dNidHdIid6dJdKdBd      dO        Z ed@dd@id=d,id!d"id	didBdd dd id=d,idHdIid6dJdKdBd      dP        Z edQddQid	ddRgdSd      dT        Z  edQddQid	ddRgdSddddiddQidU      dV        Z! edQddQid	ddRgdSddddiddWidU      dX        Z" edddiddQidU      dY        Z# edddidQdZd[dU      d\        Z$ edddiddQidU      d]        Z% edddiddQidU      d^        Z& edddiddQidU      d_        Z' e       d`        Z( edQddQid	ddRgdSddddiddQidU      da        Z) edddiddQidU      db        Z* e       dc        Z+ edQddQid	ddRgdSddddiddQidU      dd        Z, edddidded
ddddiddfd
ddddidd5d
ddddidd6d
d      dg        Z-yh)iTestRunCellz7Contains test functions for NotebookClient.execute_cellc                 l    |j                  |d       |j                  dk(  sJ |j                  g k(  sJ y )Nr   r   execute_cellr  r[   r   r)   r   r   s       r/   test_idle_messagezTestRunCell.test_idle_message  s:    i+&&!+++  B&&&rC   r  r<   r;   r1   wrong_parentr  foo)r  r   )r<   r=   r8   r9   c                 l    |j                  |d       |j                  dk(  sJ |j                  g k(  sJ y Nr   r  r  r  s       r/   test_message_for_wrong_parentz)TestRunCell.test_message_for_wrong_parent  <     	i+&&!+++  B&&&rC   r5   r   busy)r<   r=   r9   c                 l    |j                  |d       |j                  dk(  sJ |j                  g k(  sJ y r  r  r  s       r/   test_busy_messagezTestRunCell.test_busy_message  s<     	i+&&!+++  B&&&rC   r  barc                 <   d }||j                   j                  _        d|_        t	        j
                  t              5  |j                  |d       d d d        |j                  dk(  sJ | j                  |j                  dddddd	d
dg       y # 1 sw Y   AxY w)Nc                 T   K   t        j                  |        d {    t        7 
wrz   )rH   sleepr   r   s    r/   r   z5TestRunCell.test_deadline_exec_reply.<locals>.get_msg  s"     --(((K )s   (&(r   r   r+  r  r  r  rm  r  r   r  r  )r   r   r   r   r[  r\  rw  r  r  assertListEqualr[   )r   r)   r   r   r   s        r/   test_deadline_exec_replyz$TestRunCell.test_deadline_exec_reply  s    	 -4!!)]]<( 	0!!)Q/	0 &&!+++ ((EJ ((EJ	
	0 	0s   BBc                     t               |_        d|_        t        j                  t
              5  |j                  |d       d d d        y # 1 sw Y   y xY w)NTr   )r   r   raise_on_iopub_timeoutr[  r\  rw  r  r  s       r/   test_deadline_iopubzTestRunCell.test_deadline_iopub   sG     $)7 *.']]<( 	0!!)Q/	0 	0 	0s   AAc                    d } |t        |j                        d d       |_        t        t        dd|j                  ii            |j
                  j                  _        d|_        t        j                  t              5  |j                  |d       d d d        |j                  dk\  sJ | j                  |j                  d	d
ddd	dddg       y # 1 sw Y   AxY w)Nc              3   >   K   | E d {    	 t                7 wrz   r   )r   s    r/   message_seqz=TestRunCell.test_eventual_deadline_iopub.<locals>.message_seq  s#     g   s   r8   r1   r   Tr   r+  r  r  r  r   r  r  )r   r   r	   rO   r   r   r   r   r  r[  r\  rw  r  r  r  r[   )r   r)   r   r   r  s        r/   test_eventual_deadline_iopubz(TestRunCell.test_eventual_deadline_iopub	  s    	
 $/tL4L4L/Mcr/R#S ,0$o(BTBT7U%VW-
!!) +/']]<( 	0!!)Q/	0 &&!+++ ((EJ ((EJ	
	0 	0s   CCr1  c                 l    |j                  |d       |j                  dk(  sJ |j                  g k(  sJ y r  r  r  s       r/   test_execute_input_messagez&TestRunCell.test_execute_input_message/  s<     	i+&&!+++  B&&&rC   c                     |j                  |d       |j                  dk(  sJ | j                  |j                  ddddddddg       y )	Nr   r+  r  r  r  r   r  r  )r  r  r  r[   r  s       r/   test_stream_messagesz TestRunCell.test_stream_messages9  sX     	i+&&!+++ ((EJ ((EJ	
rC   clear_outputc                 l    |j                  |d       |j                  dk(  sJ |j                  g k(  sJ y )Nr   r+  r  r  s       r/   test_clear_output_messagez%TestRunCell.test_clear_output_messageR  r  rC   waitTc                     |j                  |d       |j                  dk(  sJ | j                  |j                         |j                  ddddgk(  sJ y )Nr   r+  r  r  r  r   )r  r  
assertTrueclear_before_next_outputr[   r  s       r/   test_clear_output_wait_messagez*TestRunCell.test_clear_output_wait_messagea  sY     	i+&&!+++99:  XxY^%_$````rC   c                     |j                  |d       |j                  dk(  sJ |j                  rJ |j                  ddddgk(  sJ y )Nr   rZ   r  r  r  r   r  r  r  r[   r  s       r/   +test_clear_output_wait_then_message_messagez7TestRunCell.test_clear_output_wait_then_message_messagev  sV    $ 	i+&&!+++4444  XxY^%_$````rC   update_display_datametafoometabar)r   r   c                     |j                  |d       |j                  dk(  sJ |j                  sJ |j                  ddddgk(  sJ y )Nr   rZ   r  r  r  r   r  r  s       r/   2test_clear_output_wait_then_update_display_messagez>TestRunCell.test_clear_output_wait_then_update_display_message  sV    $ 	i+&&!+++0000  XxY^%_$````rC   r6   *   c                     |j                  |d       |j                  dk(  sJ |j                  dk(  sJ |j                  g k(  sJ y )Nr   r  r  r  r  r6   r[   r  s       r/   test_execution_count_messagez(TestRunCell.test_execution_count_message  sP     	i+&&!+++((B...  B&&&rC   c                     |j                  |dd       |j                  dk(  sJ |j                  dk(  sJ |j                  g k(  sJ y )Nr      )r6   r  r!  r  s       r/   0test_execution_count_message_ignored_on_overridez<TestRunCell.test_execution_count_message_ignored_on_override  sU     	iB?&&!+++((B...  B&&&rC   )r6   r  r   c                     |j                  |d       |j                  dk(  sJ |j                  dk(  sJ |j                  ddddgk(  sJ y )Nr   r  r  r  r  r  r   r!  r  s       r/   (test_execution_count_with_stream_messagez4TestRunCell.test_execution_count_with_stream_message  s[     	i+&&!+++((B...  XxY^%_$````rC   commfoobarr  )comm_idr   c                     |j                  |d       |j                  dk(  sJ | j                  |j                  dddii       |j                  rJ |j
                  g k(  sJ y )Nr   r  r)  r  r  )r  r  rr  widget_statewidget_buffersr[   r  s       r/   test_widget_comm_messagez$TestRunCell.test_widget_comm_message  sj     	i+&&!+++..E5>0JK****  B&&&rC   s   123r   )r  buffer_paths)r<   r=   buffersr9   c                     |j                  |d       |j                  dk(  sJ |j                  dddiik(  sJ |j                  ddddd	gd
iik(  sJ |j                  g k(  sJ y )Nr   r  r)  r  r  r   MTIzbase64r   r   encodingr   r  r  r,  r-  r[   r  s       r/   &test_widget_comm_buffer_message_singlez2TestRunCell.test_widget_comm_buffer_message_single  s     	i+&&!+++$$E5>(BBBB&&y6xRXQY"Z[+
 
 	
 
   B&&&rC   foo2bar2path2c                     |j                  |d       |j                  dk(  sJ |j                  ddddik(  sJ |j                  dddd	gd
dddgd
dik(  sJ |j                  g k(  sJ y )Nr   r+  r)  r  r:  )r  r9  r3  r4  r   r5  r;  )r2  )r;  r7  r  s       r/    test_widget_comm_buffer_messagesz,TestRunCell.test_widget_comm_buffer_messages  s    * 	i+&&!+++$$5&3Q(RRRR&&$*6(S%+G9U+
 
 	
 
   B&&&rC   c                     |j                  |d       |j                  dk(  sJ |j                  rJ |j                  rJ |j                  g k(  sJ y r  r7  r  s       r/   test_unknown_comm_messagez%TestRunCell.test_unknown_comm_message   sZ     	i+&&!+++((((****  B&&&rC   execute_result)r   r   r6   c                     |j                  |d       |j                  dk(  sJ |j                  dk(  sJ |j                  dddiddidd	gk(  sJ |j                  rJ y )
Nr   r  r  r@  r  r  r  r  rm  r   r   r6   r  r  r6   r[   _display_id_mapr  s       r/   test_execute_result_messagez'TestRunCell.test_execute_result_message5  s     	i+&&!+++((B...  /&	2#%	%
 
 	
 
 +++++rC   
display_id)	transientr   r   r6   c                     |j                  |d       |j                  dk(  sJ |j                  dk(  sJ |j                  dddiddidd	gk(  sJ d
|j                  v sJ y )Nr   r  r  r@  r  r  r  r  rB  r)  rC  r  s       r/   (test_execute_result_with_display_messagez4TestRunCell.test_execute_result_with_display_messageQ  s     	i+&&!+++((B...  /&	2#%	%
 
 	
 
 833333rC   display_datac                     |j                  |d       |j                  dk(  sJ |j                  dddiddidgk(  sJ |j                  rJ y )	Nr   r  rJ  r  r  r  r  rm  r   r   r  r  r[   rD  r  s       r/   $test_display_data_without_id_messagez0TestRunCell.test_display_data_without_id_messagem  sp     	i+&&!+++  -&	2%
 
 	
 
 +++++rC   )rG  r   r   c                     |j                  |d       |j                  dk(  sJ |j                  dddiddidgk(  sJ d	|j                  v sJ y )
Nr   r  rJ  r  r  r  r  rL  r)  rM  r  s       r/   test_display_data_messagez%TestRunCell.test_display_data_message  sr     	i+&&!+++  -&	2%
 
 	
 
 833333rC   foobar_othermetafoo_othermetabar_other	bar_othermetafoo2metabar2	foobarbazr  bazc                     |j                  |d       |j                  dk(  sJ |j                  dddidddd	dd
diddid	dddidddd	gk(  sJ d|j                  v sJ y )Nr   rZ   rJ  rU  rV  r:  rW  rX  rL  rR  rS  r  rT  r)  rM  r  s       r/   !test_display_data_same_id_messagez-TestRunCell.test_display_data_same_id_message  s    < 	i+&&!+++  -'4 &{;  .,o>,  .'4 &{;%
 
 	
 
" 833333rC   c                     |j                  |d       |j                  dk(  sJ |j                  g k(  sJ |j                  rJ y r  rM  r  s       r/   +test_update_display_data_without_id_messagez7TestRunCell.test_update_display_data_without_id_message  sN     	i+&&!+++  B&&&+++++rC   foobar2c                     |j                  |d       |j                  dk(  sJ |j                  dddidddd	gk(  sJ d
|j                  v sJ y Nr   r+  rJ  rU  rV  r:  rW  rX  rL  r)  rM  r  s       r/   ,test_update_display_data_mismatch_id_messagez8TestRunCell.test_update_display_data_mismatch_id_message  s    * 	i+&&!+++  -'4 &{;%
 
 	
 
 833333rC   c                     |j                  |d       |j                  dk(  sJ |j                  dddidddd	gk(  sJ d
|j                  v sJ y r`  rM  r  s       r/    test_update_display_data_messagez,TestRunCell.test_update_display_data_message  rb  rC   r:   Boom)rn  rp  r   c                 z    |j                  |d       |j                  dk(  sJ |j                  ddddgdgk(  sJ y Nr   r  r:   r  r  re  )rm  rn  rp  r   r  r  s       r/   test_error_messagezTestRunCell.test_error_message%  sU     	i+&&!+++  #euTZS[\%
 
 	
 
rC   r   c                     | j                  t              5  |j                  |d       d d d        |j                  dk(  sJ |j                  ddddgdgk(  sJ y # 1 sw Y   3xY wrg  )assertRaisesr   r  r  r[   r  s       r/   $test_error_and_error_status_messagesz0TestRunCell.test_error_and_error_status_messages5  s{     12 	0!!)Q/	0 &&!+++  #euTZS[\%
 
 	
 
	0 	0s   AA$r3   c                 z    |j                  |d       |j                  dk(  sJ |j                  ddddgdgk(  sJ y rg  r  r  s       r/   test_error_message_onlyz#TestRunCell.test_error_message_onlyM  sW     	i+ &&!+++  #euTZS[\%
 
 	
 
rC   c                 z    d|_         |j                  |d       |j                  dk(  sJ |j                  g k(  sJ y )NTr   r   )rl  r  r  r[   r  s       r/   r  zTestRunCell.test_allow_errorse  sF     !%i+ &&!+++  B&&&rC   NotImplementedError)r5   rn  c                 |    dg|_         |j                  |d       |j                  dk(  sJ |j                  g k(  sJ y )Nro  r   r   )allow_error_namesr  r  r[   r  s       r/   test_allow_error_namesz"TestRunCell.test_allow_error_namesw  sI     '<%<"i+ &&!+++  B&&&rC   c                     dg|j                   d<   |j                  |d       |j                  dk(  sJ |j                  g k(  sJ y )Nzraises-exceptiontagsr   r   )r   r  r  r[   r  s       r/   test_raises_exception_tagz%TestRunCell.test_raises_exception_tag  sQ     '9%9	6"i+ &&!+++  B&&&rC   c                     t        di dg       }|j                  |d       |j                  dk(  sJ |j                  g k(  sJ y )Nr   rawr   r   r   r  r  r[   r  s       r/   test_non_code_cellzTestRunCell.test_non_code_cell  sP     !"PU_ab	i+ &&!+++  B&&&rC   c                     t        di dg       }|j                  |d       |j                  dk(  sJ |j                  g k(  sJ y )Nz     r   r   r   rx  r  s       r/   test_no_sourcezTestRunCell.test_no_source  sV     !
	 	i+ &&!+++  B&&&rC   c                    t        |      \  }}|j                  |d       |d   j                  |d       |d   j                  |d       |d   j                  |d       |d   j                  |dt               |d	   j	                          |d
   j	                          |d   j	                          |d   j	                          y Nr)   r   r   rv   r  r   r   r   rv   r  r;   r   r   r    r!   r0   r  assert_called_once_withEXECUTE_REPLY_OKr  r   r)   r   r   r,   s        r/   test_cell_hookszTestRunCell.test_cell_hooks  s    18D%i+o66IRS6T 88iTU8V !99yUV9W !99q8H 	: 	
 	o002!"446$%779!"446rC   c                    t        |      \  }}| j                  t              5  |j                  |d       d d d        |d   j	                  |d       |d   j	                  |d       |d   j	                  |d       |d   j	                  |dt
               |d	   j	                  |dt
               |d
   j                          |d   j                          |d   j                          y # 1 sw Y   xY wr}  r0   rj  r   r  r  EXECUTE_REPLY_ERRORr  r  s        r/   test_error_cell_hooksz!TestRunCell.test_error_cell_hooks  s    28D%12 	0!!)Q/	0o66IRS6T 88iTU8V !99yUV9W !99q8K 	: 	
 	o66q8K 	7 	
 	!"446$%779!"446	0 	0s   C22C;c                    t        di dg       }t        |      \  }}|j                  |d       |d   j                  |d       |d   j	                          |d	   j	                          |d
   j	                          |d   j	                          |d   j	                          |d   j	                          |d   j	                          y )Nr   rw  r   r~  r   r   r  r   r   r   r   r   r    r!   )r   r0   r  r  r  r  s        r/   test_non_code_cell_hooksz$TestRunCell.test_non_code_cell_hooks  s     !"PU_ab	18D%i+o66IRS6T 224 !335 !335o002!"446$%779!"446rC   c                    t        |d      \  }}|j                  |d       |d   j                  |d       |d   j                  |d       |d   j                  |d       |d   j                  |dt        	       |d
   j	                          |d   j	                          |d   j	                          |d   j	                          y NT)r)   r*   r   r   r  r   r   r   r  r   r   r    r!   r  r  s        r/   test_async_cell_hooksz!TestRunCell.test_async_cell_hooks  s    18QUV%i+o66IRS6T 88iTU8V !99yUV9W !99q8H 	: 	
 	o002!"446$%779!"446rC   c                    t        |d      \  }}| j                  t              5  |j                  |d       d d d        |d   j	                  |d       |d   j	                  |d       |d   j	                  |d       |d   j	                  |dt
        	       |d
   j	                  |dt
        	       |d   j                          |d   j                          |d   j                          y # 1 sw Y   xY wr  r  r  s        r/   test_error_async_cell_hooksz'TestRunCell.test_error_async_cell_hooks  s    28QUV%12 	0!!)Q/	0o66IRS6T 88iTU8V !99yUV9W !99q8K 	: 	
 	o66q8K 	7 	
 	!"446$%779!"446	0 	0s   C33C<foo1bar1c                 l    d|_         |j                  |d       |j                  ddddddddgk(  sJ y )	NTr   r  r  foo1foo2r   r  bar1bar2)coalesce_streamsr  r[   r  s       r/   test_coalesce_streamsz!TestRunCell.test_coalesce_streams4  sM    . %)!i+  $h
K$h
K%
 
 	
 
rC   N).r?   r@   rA   r  r   r  r  r  r  r  r
  r  r  r  r  r  r  r"  r%  r'  r.  r8  r=  r?  rE  rI  rN  rP  r[  r]  ra  rd  rh  rk  rm  r  rr  ru  ry  r{  r  r  r  r  r  r  rB   rC   r/   r  r    s
   A' '  !?3&7 (%8		
''  !8,)62	
''  !8, (%8	
 !!8, (%8	


, 0 0  !8, (%8	
 !!8, (%8	


4 $_0MZ\]''  !8, (%8	
 !!8, (%8	


  !?3 (%8	

 $
N/KXZ[''  !8, (%8	
 '!>2~	
aa  !8, (%8	
 '!>2~	
 !!8, (%8	
"a#"a  !8, (%8	
 '!>2~	
 .!#89%.	$:UENS	
"a#"a '!?3)2.	
'' '!?3)2.	
''  !8,+-xO	
aa !6*#+gu~5NO	
'' !6*x##(%.F8*M		

	'
	' !6*x##(%.F8*M		
 !6*x##)6"2gYKP		
(')(' !6*#	

'
' (!#34&	2#%	

,
," (!#34*H5&	2#%			
44  &!>2%.	$:UENS	
,, &!>2*H5&	2	

4
4 &!>2*H5&	2	
 '!>2*N;,o>,	
 '!>2*H5'4 &{;	
':4;:40 -!#89%.	$:UENS	
,, &!>2*H5'4 &{;	
 .!#89*I6'4 &{;	
(4)(4 &!>2*H5&	2	
 .!#89*H5'4 &{;	
(4)(4 !7+!&%vhO	


 !7+!&%vhO	
 (!?3 '*	
	
	
 !7+!&%vhO	
 (!?3 $'	
	
	
 '!?3 '*	
'' '!?3")4IJ	
'' '!?3 '*	
'' '!?3 '*	
'' '!?3 '*	
''  7 7 !7+!&%vhO	
 (!?3 '*	
77" '!?3 '*	
77 7 7 !7+!&%vhO	
 (!?3 '*	
77"  !8, (&9	
 !!8, (&9	
 !!8, (&9	
 !!8, (&9	
!,
-,
rC   r  )NNFrz   )XrH   concurrent.futuresr  ri   r%  r   r   r   r  r   rl   r4  r   r   queuer   typingr   unittest.mockr   r	   rg   r[  r   r
   jupyter_clientr   r   jupyter_client._versionr   jupyter_client.kernelspecr   nbconvert.filtersr   r   testpathr   	traitletsr   nbclientr   r   nbclient.exceptionsr   baser   compiler   r   rq  r  r   r   r   environr#   r0   r  r  r$   rL   rO   rW   rx   r|   r   r   r   r   r   r   r  parametrizer   r  skipifr  r  r  r"  r6  r9  rC  rG  intr]  r_  r  rB   rC   r/   <module>r     s        	 	 
   '   )     6 0 7 ( ! !   , 2 #2::()ggooh'BJJT 
  RZZ\  03

+ ,	 	*15 
 	*'"?+	 	 	S W^^ 82 37 JZ:B*F, 6	}h78	x89	mX67	mX67	mX67	x89	-x/HI	}h/0	=(34	mX67	"]H$=>	(=(*CD"0#"0?2 BGGtO,OP? Q?4?4?2*<, CQ(1,5IJ K@L7# L7^[
# [
rC   