
    J/Ph}                         d dl mZ d dlmZ d dlmZ d dlmZ d dlZd dl	Z	d dl
m
Z
 d dl Z 	 d dlmZ d Zn# e$ r d dlmZ d	 ZY nw xY w G d
 de          ZdS )    )TestCase)utils)convert)readsN)copy)Emptyc                 ,    t          | t                    S N)
isinstancestrss    V/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numba/testing/notebook.pyisstrr      s    !S!!!    c                 ,    t          | t                    S r
   )r   
basestringr   s    r   r   r      s    !Z(((r   c                   V    e Zd ZdZg dZg dZdZd Zd Zd Z	d Z
d	 Zd
 Zd Zd ZdS )NotebookTestaV  Validate a notebook. All code cells are executed in order. The output is either checked
    for errors (if no reference output is present), or is compared against expected output.


    Useful references:
    http://nbformat.readthedocs.org/en/latest/format_description.html
    http://jupyter-client.readthedocs.org/en/latest/messaging.html
)execute_requestexecute_inputstatuspyin)execution_count	tracebackprompt_numbersource   c                    t          |          5 }t          t          |                                          | j                  }d d d            n# 1 swxY w Y   t          j                    \  }}t          d |j        D                       D ]0\  }}| 	                    | 
                    |          |||           1d S )Nc                 (    g | ]}|j         d k    |S )code)	cell_type).0cs     r   
<listcomp>z/NotebookTest._test_notebook.<locals>.<listcomp>-   s$    LLLQakV6K6Kq6K6K6Kr   )openr   r   readNBFORMAT_VERSIONr   start_new_kernel	enumeratecells_test_notebook_cellsanitize_cell)	selfnotebooktestfnb_kernelir$   s	            r   _test_notebookzNotebookTest._test_notebook(   s   (^^ 	Aqqvvxx$*?@@B	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A*,,	6LL"(LLLMM 	M 	MDAq$$T%7%7%:%:AvtLLLL	M 	Ms   5AAAc                     t          |d          r|j        }n|j        }|j        }|                    |           g }d }d}	d}
d}                     |          r	 |                    dd          }n# t          $ r Y :w xY w|d          j        vr|d         dk    r-d	|d
         d         z   dz   |d
         d         z   }d}	|
dk    r|}
t          |          }|t          |j
                  k     r|j
        |         pg }                     ||          }|                    |                                |          |dk    r                     |	d|
|fz             d S  fd} ||          } ||j
                  }d S )Nr   T    )blocktimeoutmsg_typeerrorz  contentenamez
  evalueFcheck_errorz*Executing cell %d resulted in an error:
%sc                 n                         t                              |                               S r
   )dump_canonicallistscrub_outputs)xr.   s    r   <lambda>z2NotebookTest._test_notebook_cell.<locals>.<lambda>S   s+    d11$t7I7I!7L7L2M2MNN r   )hasattrr   inputiopub_channelexecuteshould_continueget_msgr   IGNORE_TYPESlenoutputstransform_messageappend
assertTrue)r.   cellr5   r4   r0   r!   iopubrQ   msgno_errorfirst_error	error_msgexpectedoscrubscrubbeds   `               r   r,   z NotebookTest._test_notebook_cell0   s   4"" 	;DD:D$t	""3'' 	"mm$m::   :d&777z?g-- $s9~g'> > G#i.YaJb bI$H"b((&'LLs4<000DT\!_J**399q!!! ""3'' 	"  M!!OOH&SU`bkTl&lmmmmm
 ONNNEuW~~HuT\**HHHs   A5 5
BBc                 0    t          j        |dd          S )N   T)indent	sort_keys)jsondumps)r.   objs     r   rD   zNotebookTest.dump_canonicalZ   s    z#a48888r   c              #   Z  K   |D ]}t          |          }dD ]\  fd}d|v r ||d                   |d<   d|v rdt          |d         t                    r5|d                                         D ]\  }} ||          |d         |<   w ||d                   |d<   |V  dS )z=
        remove all scrubs from output data and text
         c                 l    t          |           rt          j        |           S fd| D             S )Nc                 <    g | ]}t          j        |          S rg   )resub)r#   liner]   rk   s     r   r%   zCNotebookTest.scrub_outputs.<locals>._scrubLines.<locals>.<listcomp>i   s'    KKKTuc4 8 8KKKr   )r   rj   rk   )linesr]   rk   s    r   _scrubLinesz/NotebookTest.scrub_outputs.<locals>._scrubLinese   sC    U|| L!veS%888KKKKKUKKKKr   textdataN)r   r   dictitems)	r.   rQ   outputoutrn   mimerp   r]   rk   s	          @@r   rF   zNotebookTest.scrub_outputs]   s       	 	Fv,,C  ? ?
sL L L L L L S=="-+c&k":":CKS==!#f+t44 ?*-f+*;*;*=*= B BJD$0;D0A0ACK--B '2k#f+&>&>FIIII'	 	r   c                 F    | j         D ]}|                    |d           |S )zE
        remove keys from STRIP_KEYS to ensure comparability
        N)
STRIP_KEYSpop)r.   dkeys      r   
strip_keyszNotebookTest.strip_keysv   s1     ? 	 	CEE#tr   c                 D    |j         D ]}|                     |           |S )z0
        remove non-reproducible things
        )rQ   r{   )r.   rU   rs   s      r   r-   zNotebookTest.sanitize_cell~   s/     l 	$ 	$FOOF####r   c                 &   ddddi}d|d         i}|                     |d                    |                     |          }|                                D ]$\  }}||v r||         |v r|||                  ||<   %d|v rd|vr|d         |d<   |d= |S )	zF
        transform a message into something like the notebook
        output_typeexecute_resultr>   )pyoutpyerrr=   r?   rp   ro   )updater{   rr   )r.   rW   r[   	SWAP_KEYSrs   rz   swapss          r   rR   zNotebookTest.transform_message   s    
 )  
	 C
O
 	c)n%%%((#//++ 	1 	1JCf}}!5!5#F3K0sVh 6 6#F^F6Nvr   c                 H    |dS |d         dk    o|d         d         dk     S )zQ
        determine whether the current message is the last for this cell
        NTr=   r   r?   execution_stateidlerg   )r.   rW   s     r   rM   zNotebookTest.should_continue   s>     ;4
Ox/ @	N#45?A 	Ar   N)__name__
__module____qualname____doc__rO   rw   r(   r6   r,   rD   rF   r{   r-   rR   rM   rg   r   r   r   r      s          JIILLLLJM M M%+ %+ %+T9 9 9  2      6A A A A Ar   r   )unittestr   ipykernel.testsr   nbformat.converterr   nbformat.readerr   rj   rc   r   queuer   r   ImportErrorQueuer   rg   r   r   <module>r      s3         ! ! ! ! ! ! & & & & & & ! ! ! ! ! ! 				        )" " " " ) ) )) ) ) ) )	)PA PA PA PA PA8 PA PA PA PA PAs   	6 AA