o
    i2                     @   s   d dl Z d dlZd dlm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mZmZmZ d dlmZ dd	 ZG d
d dZeddZG dd de
ZdS )    N)join)url_path_join)NotebookTestBaseassert_http_error)write)new_notebooknew_markdown_cellnew_code_cell
new_output)encodebytesc                 C   s   t | du r	dS dS )zCheck is a command exists.NFT)shutilwhich)cmd r   k/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/notebook/nbconvert/tests/test_nbconvert_handlers.py
cmd_exists   s   r   c                   @   s<   e Zd ZdZdd ZdddZddd	Zd
d Zdd ZdS )NbconvertAPIz Wrapper for nbconvert API calls.c                 C   s
   || _ d S )N)request)selfr   r   r   r   __init__   s   
zNbconvertAPI.__init__Nc                 C   s$   | j |td|||d}|  |S )N	nbconvert)dataparams)r   r   raise_for_status)r   verbpathbodyr   responser   r   r   _req   s   zNbconvertAPI._reqFc                 C   s   | j dt|||d|idS )NGETdownload)r   )r   r   )r   formatr   namer    r   r   r   	from_file%   s   zNbconvertAPI.from_filec                 C   s   t |}| d||S )NPOST)jsondumpsr   )r   r!   nbmodelr   r   r   r   	from_post)   s   
zNbconvertAPI.from_postc                 C   s   |  ddS )Nr    )r   r   r   r   r   list_formats-   s   zNbconvertAPI.list_formats)NN)F)	__name__
__module____qualname____doc__r   r   r#   r(   r+   r   r   r   r   r      s    

r   sG   PNG

   IHDR     x00   wS   IDATc  \.~d    IENDB`asciic                   @   s   e Zd Zdd Zejjed dddd Zejjed dddd	 Z	ejjed ddd
d Z
ejjed dddd Zejjed dddd Zejjed dddd ZdS )APITestc                    s   | j }tjt|dst|d t  | j fdd}t }|j	t
d tdd}|j	tddd	 |j	td
dtidd |j	| tt|ddddd}t||dd W d    n1 siw   Y  t| j| _d S )Nfooc                      s   t j dd d S )NT)ignore_errors)r   rmtreer   subdirr   r   cleanup_dirA   s   z"APITest.setUp.<locals>.cleanup_diru   Created by test ³
print(2*6))sourcestream12)output_typetextexecute_resultz	image/png   )r<   r   execution_counttestnb.ipynbwzutf-8)encoding   )version)notebook_dirosr   isdirpjoinmkdir
addCleanupr   cellsappendr   r	   outputsr
   png_green_pixelopenr   r   r   nbconvert_api)r   nbdirr7   nbcc1fr   r5   r   setUp6   s,   



zAPITest.setUppandocz(Pandoc wasn't found. Skipping this test.)reasonc                 C   s   | j ddd}| |jd | d|jd  | d|j | d|j | j d	dd}| d
|jd  | d|j d S )Nhtmlr2   rA      	text/htmlContent-TypeCreated by testprintpythontext/x-pythonr8   )rQ   r#   assertEqualstatus_codeassertInheadersr=   r   rr   r   r   test_from_fileV   s   zAPITest.test_from_filec                 C   s>   t d | jddd W d    d S 1 sw   Y  d S )Ni  rY   r2   zthisdoesntexist.ipynb)r   rQ   r#   r*   r   r   r   test_from_file_404e   s   
"zAPITest.test_from_file_404c                 C   s:   | j jddddd}|jd }| d| | d| d S )	Nr_   r2   rA   Tr    Content-Disposition
attachmentz	testnb.py)rQ   r#   rd   rc   )r   rf   content_dispositionr   r   r   test_from_file_downloadm   s   
zAPITest.test_from_file_downloadc                 C   s<   | j jddddd}| d|jd  | d|jd	  d S )
Nlatexr2   rA   Tri   application/zipr\   .ziprj   )rQ   r#   rc   rd   re   r   r   r   test_from_file_zipw   s   zAPITest.test_from_file_zipc                 C   s   |  dd }| jjd|d}| |jd | d|jd  | d|j | d	|j | jjd
|d}| d|jd  | d|j d S )Nr   api/contents/foo/testnb.ipynbrY   r!   r'   rZ   r[   r\   r]   r^   r_   r`   r8   )	r   r%   rQ   r(   ra   rb   rc   rd   r=   r   r'   rf   r   r   r   test_from_post   s   zAPITest.test_from_postc                 C   sH   |  dd }| jjd|d}| d|jd  | d|jd  d S )	Nr   rr   rn   rs   ro   r\   rp   rj   )r   r%   rQ   r(   rc   rd   rt   r   r   r   test_from_post_zip   s   zAPITest.test_from_post_zipN)r,   r-   r.   rV   pytestmarkskipifr   rg   rh   rm   rq   ru   rv   r   r   r   r   r1   5   s@     




r1   )r%   rG   os.pathr   rI   r   rw   notebook.utilsr   notebook.tests.launchnotebookr   r   nbformatr   nbformat.v4r   r   r	   r
   base64r   r   r   decoderO   r1   r   r   r   r   <module>   s     