a
    7Ub0                     @   sP   d 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	 G d	d
 d
eZ
dS )Tests for HTMLExporter    N   )ExportersTestsBase   HTMLExporter)Config)v4c                   @   sr   e Zd ZdZeZdgZdd Zdd Zdd Z	d	d
 Z
dd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )TestHTMLExporterr   htmlc                 C   s
   t   dS )z4
        Can a HTMLExporter be constructed?
        Nr   )self r   Blib/python3.9/site-packages/nbconvert/exporters/tests/test_html.pytest_constructor   s    z!TestHTMLExporter.test_constructorc                 C   s(   t  |  \}}t|dks$J dS )z6
        Can a HTMLExporter export something?
        r   Nr   from_filename_get_notebooklenr   output	resourcesr   r   r   test_export   s    zTestHTMLExporter.test_exportc                 C   s,   t dd|  \}}t|dks(J dS )zI
        Can a HTMLExporter export using the 'classic' template?
        classictemplate_namer   Nr   r   r   r   r   test_export_classic$   s    z$TestHTMLExporter.test_export_classicc                 C   s,   t dd|  \}}t|dks(J dS )zE
        Can a HTMLExporter export using the 'lab' template?
        labr   r   Nr   r   r   r   r   test_export_notebook,   s    z%TestHTMLExporter.test_export_notebookc                 C   s^   t dd| jdd\}}d}d}g d}dg}t|||ksFJ t|||ksZJ d	S )
M
        Does HTMLExporter properly format input and output prompts?
        r   r   prompt_numbers.ipynbZnb_nameIn&nbsp;\[(.*)\]:Out\[(.*)\]:)210&nbsp;r%   0r$   N)r   r   r   refindall)r   r   r   in_regex	out_regexZinsZoutsr   r   r   test_prompt_number3   s    

z#TestHTMLExporter.test_prompt_numberc                 C   s`   t ddddi}t|dd}|| jdd\}}d}d	}t||rLJ t||r\J d
S )r   ZTemplateExporterT)Zexclude_input_promptZexclude_output_promptr   )Zconfigr   r   r    r!   r"   N)r   r   r   r   r'   r(   )r   Zno_prompt_confZexporterr   r   r)   r*   r   r   r   r+   B   s    
c                 C   sV   t dd| jdd\}}td}||}|d}d|v sFJ d|v sRJ d	S )
zp
        Does HTMLExporter with the 'classic' template treat pngs with width/height metadata correctly?
        r   r   zpngmetadata.ipynbr    <img src="[^"]*?"([^>]*?)>r   widthZheightN)r   r   r   r'   compilesearchgroup)r   r   r   check_for_pngresultZattr_stringr   r   r   test_png_metadataV   s    




z"TestHTMLExporter.test_png_metadatac                 C   sJ   t jt jt jdddidgdgd}tdd|\}}| d	| d S )
NZdisplay_datazapplication/javascriptzjavascript_output();)Zoutput_typedata)Zoutputs)cellsr   r   Zjavascript_output)r	   new_notebooknew_code_cellZ
new_outputr   from_notebook_nodeZassertIn)r   nbr   r   r   r   r   test_javascript_outputb   s    z'TestHTMLExporter.test_javascript_outputc                 C   s   t dd| jdd\}}td}||}| |d 	d | |d 	d	 td
}|
|}|d |d ksJ dd|d v sJ dd S )Nr   r   zattachment.ipynbr    r,   r   z%<img src="data:image/png;base64,iVBORr   zalt="image.png"z<img src="(?P<url>[^"]*?)"z0attachments only need to be unique within a cellz	image/svgzsecond image should use svg)r   Z	from_filer   r'   r.   r/   
assertTruer0   strip
startswithr(   )r   r   r   r1   r2   Zcheck_for_dataZresultsr   r   r   test_attachmentsr   s    





z!TestHTMLExporter.test_attachmentsc                 C   sT   t  }|jt d d	dd}d|i}td|d|\}}| d|v  d S )
NZ	some_textpythonc                 S   s   | d S )Nz ADDED_TEXTr   )sourceZlanguagemetadatar   r   r   custom_highlight_code   s    zQTestHTMLExporter.test_custom_filter_highlight_code.<locals>.custom_highlight_codeZhighlight_coder   )r   filtersZ
ADDED_TEXT)r?   N)r	   r6   r5   appendr7   r   r8   r;   )r   r9   rB   rC   r   r   r   r   r   !test_custom_filter_highlight_code   s    
z2TestHTMLExporter.test_custom_filter_highlight_codec                 C   s,   t dd|  \}}t|dks(J dS )zG
        Can a HTMLExporter export using the 'basic' template?
        Zbasicr   r   Nr   r   r   r   r   test_basic_name   s    z TestHTMLExporter.test_basic_nameN)__name__
__module____qualname____doc__r   Zexporter_classZshould_include_rawr   r   r   r   r+   r3   r:   r>   rE   rF   r   r   r   r   r
      s   r
   )rJ   r'   baser   r   r   Ztraitlets.configr   Znbformatr	   r
   r   r   r   r   <module>   s   