ó
§‰]c           @   sÖ   d  Z  d d l 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 d d l m Z e j j e ƒ Z d e f d „  ƒ  YZ d S(   s   Tests for Latex exporteriÿÿÿÿNi   (   t   ExportersTestsBasei   (   t   LatexExporteri   (   t   onlyif_cmds_exist(   t   Config(   t   write(   t   v4(   t   TemporaryDirectory(   t
   DictLoadert   TestLatexExporterc           B   sø   e  Z d  Z e Z d g Z d „  Z e d ƒ d „  ƒ Z e d ƒ d „  ƒ Z	 e d ƒ d „  ƒ Z
 e d ƒ d „  ƒ Z e d ƒ d „  ƒ Z e d ƒ d	 „  ƒ Z e d ƒ d
 „  ƒ Z e d ƒ d „  ƒ Z e d d ƒ d „  ƒ Z d „  Z d „  Z RS(   s$   Contains test functions for latex.pyt   latexc         C   s   t  ƒ  d S(   s5   
        Can a LatexExporter be constructed?
        N(   R   (   t   self(    (    sC   lib/python2.7/site-packages/nbconvert/exporters/tests/test_latex.pyt   test_constructor   s    t   pandocc         C   s:   t  ƒ  j |  j ƒ  ƒ \ } } t | ƒ d k s6 t ‚ d S(   s7   
        Can a LatexExporter export something?
        i    N(   R   t   from_filenamet   _get_notebookt   lent   AssertionError(   R
   t   outputt	   resources(    (    sC   lib/python2.7/site-packages/nbconvert/exporters/tests/test_latex.pyt   test_export&   s    c         C   s@   t  d d ƒ j |  j ƒ  ƒ \ } } t | ƒ d k s< t ‚ d S(   sE   
        Can a LatexExporter export using 'report' template?
        t   template_filet   reporti    N(   R   R   R   R   R   (   R
   R   R   (    (    sC   lib/python2.7/site-packages/nbconvert/exporters/tests/test_latex.pyt   test_export_book/   s    $c         C   s@   t  d d ƒ j |  j ƒ  ƒ \ } } t | ƒ d k s< t ‚ d S(   sF   
        Can a LatexExporter export using 'article' template?
        R   t   articlei    N(   R   R   R   R   R   (   R
   R   R   (    (    sC   lib/python2.7/site-packages/nbconvert/exporters/tests/test_latex.pyt   test_export_basic8   s    $c         C   s@   t  d d ƒ j |  j ƒ  ƒ \ } } t | ƒ d k s< t ‚ d S(   sF   
        Can a LatexExporter export using 'article' template?
        R   R   i    N(   R   R   R   R   R   (   R
   R   R   (    (    sC   lib/python2.7/site-packages/nbconvert/exporters/tests/test_latex.pyt   test_export_articleA   s    $c   
      C   së   t  j d ƒ } | j d d ƒ d } d j | g d ƒ } d } t j d t j d	 | ƒ g ƒ } t ƒ  z } t j	 j | | ƒ } t
 | d
 ƒ  } t | | d ƒ Wd QXt d d ƒ j | ƒ \ } }	 t | ƒ d k sá t ‚ Wd QXd S(   sB   
        Torture test that long cells do not cause issues
        su            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.
           s   
t    s   

t    i¸  s   lorem_ipsum_long.ipynbt   cellst   sourcet   wi   NR   R   i    (   t   textwrapt   dedentt   replacet   joinR   t   new_notebookt   new_markdown_cellR   t   ost   patht   openR   R   R   R   R   (
   R
   t   lorem_ipsum_textt   large_lorem_ipsum_textt   notebook_namet   nbt   tdt   nbfilet   fR   R   (    (    sC   lib/python2.7/site-packages/nbconvert/exporters/tests/test_latex.pyt   test_very_long_cellsI   s    		c         C   sŽ   t  ƒ  j |  j d d ƒ ƒ \ } } d } d } d d d d d g } d g } t j | | ƒ | k sl t ‚ t j | | ƒ | k sŠ t ‚ d	 S(
   sW   
        Does LatexExporter properly format input and output prompts in color?
        t   nb_names   prompt_numbers.ipynbs&   \\prompt\{In\}\{incolor\}\{(\d+|\s*)\}s(   \\prompt\{Out\}\{outcolor\}\{(\d+|\s*)\}t   2t   10R   t   0N(   R   R   R   t   ret   findallR   (   R
   R   R   t   in_regext	   out_regext   inst   outs(    (    sC   lib/python2.7/site-packages/nbconvert/exporters/tests/test_latex.pyt   test_prompt_number_colorn   s    		c   	      C   sÀ   t  i d d 6ƒ } d t f d „  ƒ  Y} | d | g ƒ j |  j d d ƒ ƒ \ } } d } d	 } d
 d d d d g } d g } t j | | ƒ | k sž t ‚ t j | | ƒ | k s¼ t ‚ d S(   s²   
        Does LatexExporter properly format input and output prompts in color?
        
        Uses an in memory latex template to load style_ipython as the cell style.
        s²   
            ((* extends 'style_ipython.tplx' *))

            ((* block docclass *))
            \documentclass[11pt]{article}
            ((* endblock docclass *))
            t   my_templatet
   MyExporterc           B   s   e  Z d  Z RS(   R;   (   t   __name__t
   __module__R   (    (    (    sC   lib/python2.7/site-packages/nbconvert/exporters/tests/test_latex.pyR<      s   t   extra_loadersR0   s   prompt_numbers.ipynbs"   In \[\{\\color\{incolor\}(.*)\}\]:s#   Out\[\{\\color\{outcolor\}(.*)\}\]:R1   R2   R   R3   N(   R   R   R   R   R4   R5   R   (	   R
   t   my_loader_tplxR<   R   R   R6   R7   R8   R9   (    (    sC   lib/python2.7/site-packages/nbconvert/exporters/tests/test_latex.pyt    test_prompt_number_color_ipython   s    	c         C   s   i i t  d 6t  d 6d 6} t | ƒ } t d | ƒ } | j |  j d d ƒ ƒ \ } } d | k si t ‚ d | k s{ t ‚ d  S(	   Nt   exclude_input_promptt   exclude_output_promptt   TemplateExportert   configR0   s   prompt_numbers.ipynbt   shapet   evs(   t   TrueR   R   R   R   R   (   R
   t	   no_promptt   c_no_promptt   exporterR   R   (    (    sC   lib/python2.7/site-packages/nbconvert/exporters/tests/test_latex.pyt   test_no_prompt_yes_inputž   s    t   inkscapec         C   sL   t  j j t d d ƒ } t ƒ  j | ƒ \ } } t | ƒ d k sH t ‚ d S(   sZ   
        Can a LatexExporter export when it recieves raw binary strings form svg?
        t   filess	   svg.ipynbi    N(   R%   R&   R"   t   current_dirR   R   R   R   (   R
   t   filenameR   R   (    (    sC   lib/python2.7/site-packages/nbconvert/exporters/tests/test_latex.pyt   test_svg®   s    c         C   s`   t  i d d 6ƒ } d t f d „  ƒ  Y} | d | g ƒ } t j ƒ  } | j | ƒ \ } } d  S(   Ns   {%- extends 'article.tplx' -%}R;   R<   c           B   s   e  Z d  Z RS(   R;   (   R=   R>   R   (    (    (    sC   lib/python2.7/site-packages/nbconvert/exporters/tests/test_latex.pyR<   ½   s   R?   (   R   R   R   R#   t   from_notebook_node(   R
   R@   R<   RK   R+   t   outR   (    (    sC   lib/python2.7/site-packages/nbconvert/exporters/tests/test_latex.pyt   test_in_memory_template_tplx·   s
    c         C   sy   t  j ƒ  } | j j t  j d ƒ ƒ d d  t d „ } i | d 6} t d | ƒ j | ƒ \ } } |  j	 d | k ƒ d  S(   Nt	   some_textt   pythonc         S   s   |  d S(   Ns    ADDED_TEXT(    (   R   t   languaget   metadatat   strip_verbatim(    (    sC   lib/python2.7/site-packages/nbconvert/exporters/tests/test_latex.pyt   custom_highlight_codeÉ   s    t   highlight_codet   filterst
   ADDED_TEXT(
   R   R#   R   t   appendt   new_code_cellt   Nonet   FalseR   RR   t
   assertTrue(   R
   R+   RZ   R\   R   R   (    (    sC   lib/python2.7/site-packages/nbconvert/exporters/tests/test_latex.pyt!   test_custom_filter_highlight_codeÄ   s    
(   R=   R>   t   __doc__R   t   exporter_classt   should_include_rawR   R   R   R   R   R   R/   R:   RA   RL   RQ   RT   Rc   (    (    (    sC   lib/python2.7/site-packages/nbconvert/exporters/tests/test_latex.pyR      s   					%		(   Rd   t   os.pathR%   R   R4   t   baseR    R	   R   t   tests.utilsR   t   traitlets.configR   t   nbformatR   R   t   testpath.tempdirR   t   jinja2R   R&   t   dirnamet   __file__RO   R   (    (    (    sC   lib/python2.7/site-packages/nbconvert/exporters/tests/test_latex.pyt   <module>   s   