a
    7Ub#                     @   s   d 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
 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 ejeZG dd deZdS )zTests for Latex exporter    N)TemporaryDirectory   )ExportersTestsBase   LatexExporter   )onlyif_cmds_exist)Config)write)v4)
DictLoaderc                   @   s   e Zd ZdZeZdgZdd Zeddd Z	eddd	 Z
edd
d Zeddd Zeddd Zeddd Zedddd Zdd Zdd ZdS )TestLatexExporterz$Contains test functions for latex.pylatexc                 C   s
   t   dS )z5
        Can a LatexExporter be constructed?
        Nr   )self r   Clib/python3.9/site-packages/nbconvert/exporters/tests/test_latex.pytest_constructor   s    z"TestLatexExporter.test_constructorZpandocc                 C   s(   t  |  \}}t|dks$J dS )z7
        Can a LatexExporter export something?
        r   Nr   from_filename_get_notebooklenr   output	resourcesr   r   r   test_export&   s    zTestLatexExporter.test_exportc                 C   s,   t dd|  \}}t|dks(J dS )zE
        Can a LatexExporter export using 'report' template?
        Zreport)template_filer   Nr   r   r   r   r   test_export_book/   s    z"TestLatexExporter.test_export_bookc           
   	   C   s   t d}|ddd }d|gd }d}tjtj|dgd	}t t}tj	||}t
|d
}t||d W d   n1 s0    Y  t |\}}	t|dksJ W d   n1 s0    Y  dS )zB
        Torture test that long cells do not cause issues
        au            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec
          dignissim, ipsum non facilisis tempus, dui felis tincidunt metus,
          nec pulvinar neque odio eget risus. Nulla nisi lectus, cursus
          suscipit interdum at, ultrices sit amet orci. Mauris facilisis
          imperdiet elit, vitae scelerisque ipsum dignissim non. Integer
          consequat malesuada neque sit amet pulvinar. Curabitur pretium
          ut turpis eget aliquet. Maecenas sagittis lacus sed lectus
          volutpat, eu adipiscing purus pulvinar. Maecenas consequat
          luctus urna, eget cursus quam mollis a. Aliquam vitae ornare
          erat, non hendrerit urna. Sed eu diam nec massa egestas pharetra
          at nec tellus. Fusce feugiat lacus quis urna sollicitudin volutpat.
          Quisque at sapien non nibh feugiat tempus ac ultricies purus.
           
 z

 i  zlorem_ipsum_long.ipynb)source)cellsw   Nr   )textwrapdedentreplacejoinr   new_notebookZnew_markdown_cellr   ospathopenr   r   r   r   )
r   Zlorem_ipsum_textZlarge_lorem_ipsum_textZnotebook_namenbZtdZnbfilefr   r   r   r   r   test_very_long_cells8   s    

*z&TestLatexExporter.test_very_long_cellsc                 C   sZ   t  | jdd\}}d}d}g d}dg}t|||ksBJ t|||ksVJ dS )zW
        Does LatexExporter properly format input and output prompts in color?
        prompt_numbers.ipynbZnb_namez&\\prompt\{In\}\{incolor\}\{(\d+|\s*)\}z(\\prompt\{Out\}\{outcolor\}\{(\d+|\s*)\}210r   r   0r4   N)r   r   r   refindall)r   r   r   in_regex	out_regexinsoutsr   r   r   test_prompt_number_color]   s    
z*TestLatexExporter.test_prompt_number_colorc           	      C   s|   t ddi}G dd dt}||gd| jdd\}}d}d	}g d
}dg}t|||ksdJ t|||ksxJ dS )z
        Does LatexExporter properly format input and output prompts in color?

        Uses an in memory latex template to load style_ipython as the cell style.
        my_templatez
            ((* extends 'style_ipython.tex.j2' *))

            ((* block docclass *))
            \documentclass[11pt]{article}
            ((* endblock docclass *))
            c                   @   s   e Zd ZdZdS )zFTestLatexExporter.test_prompt_number_color_ipython.<locals>.MyExporterr=   N__name__
__module____qualname__r   r   r   r   r   
MyExporter~   s   rB   Zextra_loadersr0   r1   z"In \[\{\\color\{incolor\}(.*)\}\]:z#Out\[\{\\color\{outcolor\}(.*)\}\]:r2   r4   N)r   r   r   r   r6   r7   )	r   my_loader_tplxrB   r   r   r8   r9   r:   r;   r   r   r    test_prompt_number_color_ipythonn   s    	
z2TestLatexExporter.test_prompt_number_color_ipythonc                 C   sR   ddddi}t |}t|d}|| jdd\}}d|v sBJ d|v sNJ d S )	NZTemplateExporterT)Zexclude_input_promptZexclude_output_prompt)Zconfigr0   r1   shapeZevs)r
   r   r   r   )r   Z	no_promptZc_no_promptexporterr   r   r   r   r   test_no_prompt_yes_input   s    

z*TestLatexExporter.test_no_prompt_yes_inputZinkscapec                 C   s4   t jtdd}t |\}}t|dks0J dS )zZ
        Can a LatexExporter export when it recieves raw binary strings form svg?
        filesz	svg.ipynbr   N)r*   r+   r(   current_dirr   r   r   )r   filenamer   r   r   r   r   test_svg   s    zTestLatexExporter.test_svgc                 C   sB   t ddi}G dd dt}||gd}t }||\}}d S )Nr=   z{%- extends 'index' -%}c                   @   s   e Zd ZdZdS )zBTestLatexExporter.test_in_memory_template_tplx.<locals>.MyExporterr=   Nr>   r   r   r   r   rB      s   rB   rC   )r   r   r   r)   from_notebook_node)r   rD   rB   rG   r-   outr   r   r   r   test_in_memory_template_tplx   s
    z.TestLatexExporter.test_in_memory_template_tplxc                 C   sR   t  }|jt d d	dd}d|i}t|d|\}}| d|v  d S )
NZ	some_textpythonFc                 S   s   | d S )Nz ADDED_TEXTr   )r!   ZlanguagemetadataZstrip_verbatimr   r   r   custom_highlight_code   s    zRTestLatexExporter.test_custom_filter_highlight_code.<locals>.custom_highlight_codeZhighlight_code)filtersZ
ADDED_TEXT)rP   NF)r   r)   r"   appendZnew_code_cellr   rM   Z
assertTrue)r   r-   rR   rS   r   r   r   r   r   !test_custom_filter_highlight_code   s    
z3TestLatexExporter.test_custom_filter_highlight_codeN)r?   r@   rA   __doc__r   Zexporter_classZshould_include_rawr   r	   r   r   r/   r<   rE   rH   rL   rO   rU   r   r   r   r   r      s(   


$



r   )rV   os.pathr*   Ztempfiler   r%   r6   baser   r   r   Ztests.utilsr	   Ztraitlets.configr
   Znbformatr   r   Zjinja2r   r+   dirname__file__rJ   r   r   r   r   r   <module>   s   