ó
&9_[c           @   s¹   d  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 e
 f d „  ƒ  YZ d „  Z d	 e j f d
 „  ƒ  YZ d e f d „  ƒ  YZ d e j f d „  ƒ  YZ d S(   s:   Tests for the TerminalInteractiveShell and related pieces.iÿÿÿÿN(   t   InputTransformer(   t   tools(   t   capture_outputt   mock_input_helperc           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   sZ   Machinery for tests of the main interact loop.

    Used by the mock_input decorator.
    c         C   s"   | |  _  d  |  _ t ƒ  |  _ d  S(   N(   t   testgent   Nonet	   exceptiont   get_ipythont   ip(   t   selfR   (    (    sJ   lib/python2.7/site-packages/IPython/terminal/tests/test_interactivshell.pyt   __init__   s    		c         C   s"   |  j  j |  _ |  j |  j  _ |  S(   N(   R   t   prompt_for_codet   orig_prompt_for_codet
   fake_input(   R	   (    (    sJ   lib/python2.7/site-packages/IPython/terminal/tests/test_interactivshell.pyt	   __enter__   s    c         C   s   |  j  |  j _ d  S(   N(   R   R   R   (   R	   t   etypet   valuet   tb(    (    sJ   lib/python2.7/site-packages/IPython/terminal/tests/test_interactivshell.pyt   __exit__   s    c         C   sX   y t  |  j ƒ SWn@ t k
 r1 t |  j _ d St j ƒ  |  _ t |  j _ d SXd  S(   Nu    (	   t   nextR   t   StopIterationt   FalseR   t   keep_runningt   syst   exc_infoR   (   R	   (    (    sJ   lib/python2.7/site-packages/IPython/terminal/tests/test_interactivshell.pyR   !   s    (   t   __name__t
   __module__t   __doc__R
   R   R   R   (    (    (    sJ   lib/python2.7/site-packages/IPython/terminal/tests/test_interactivshell.pyR      s
   			c            s   ‡  f d †  } | S(   s·   Decorator for tests of the main interact loop.

    Write the test as a generator, yield-ing the input strings, which IPython
    will see as if they were typed in at the prompt.
    c            s   ˆ  |  ƒ } t  | ƒ  } | j j ƒ  Wd  QX| j d  k	 r} | j \ } } } d d  l } | j | d t j ƒ~ | ‚ n  d  S(   Niÿÿÿÿt   file(	   R   R   t   interactR   R   t	   tracebackt   print_tbR   t   stdout(   R	   R   t   mihR   R   R   R   (   t   testfunc(    sJ   lib/python2.7/site-packages/IPython/terminal/tests/test_interactivshell.pyt   test_method2   s    (    (   R"   R#   (    (   R"   sJ   lib/python2.7/site-packages/IPython/terminal/tests/test_interactivshell.pyt
   mock_input,   s    t   InteractiveShellTestCasec           B   s)   e  Z d  „  Z e d „  ƒ Z d „  Z RS(   c         C   s:   g  t  | d d d ƒ D] } | j | j ƒ  | ƒ ^ q S(   s-   Get last n readline history entries as a listi   iÿÿÿÿ(   t   ranget   get_history_itemt   get_current_history_length(   R	   t   rlt   nt   x(    (    sJ   lib/python2.7/site-packages/IPython/terminal/tests/test_interactivshell.pyt   rl_hist_entriesD   s    c         c   sÍ   t  ƒ  } t ƒ  } | j j j | ƒ | j j j | ƒ zg t j d d t ƒ
 d VWd  QXt j d d t ƒ
 d VWd  QXt j d d t ƒ
 d VWd  QXWd  | j j j	 | ƒ | j j j	 | ƒ Xd  S(   Nt   4t   suppressu
   print(2*2)s   SyntaxError: input containsu   print(2345) # syntaxerrort   16u
   print(4*4)(
   R   t   SyntaxErrorTransformert   input_splittert   python_line_transformst   appendt   input_transformer_managert   ttt   AssertPrintsR   t   remove(   R	   R   t   transformer(    (    sJ   lib/python2.7/site-packages/IPython/terminal/tests/test_interactivshell.pyt!   test_inputtransformer_syntaxerrorI   s    		c   	      C   s
  t  ƒ  } | j } | j d g k s* t ‚ | j j s= t ‚ d t f d „  ƒ  Y} | ƒ  } | j | ƒ \ } } |  j | i t	 | ƒ d 6ƒ d | f d „  ƒ  Y} | ƒ  } t
 ƒ   } | j | ƒ \ } } Wd  QX|  j | i t	 | ƒ d 6ƒ | j d k st ‚ d  S(   Ns
   text/plaint   Testc           B   s   e  Z d  „  Z d „  Z RS(   c         S   s   d t  |  ƒ S(   Ns	   <Test %i>(   t   id(   R	   (    (    sJ   lib/python2.7/site-packages/IPython/terminal/tests/test_interactivshell.pyt   __repr__f   s    c         S   s   d S(   Ns   <html>(    (   R	   (    (    sJ   lib/python2.7/site-packages/IPython/terminal/tests/test_interactivshell.pyt   _repr_html_i   s    (   R   R   R<   R=   (    (    (    sJ   lib/python2.7/site-packages/IPython/terminal/tests/test_interactivshell.pyR:   e   s   	t   Test2c           B   s   e  Z d  „  Z RS(   c         S   s   d d l  m } | d ƒ d  S(   Niÿÿÿÿ(   t   displays   <custom>(   t   IPython.displayR?   (   R	   R?   (    (    sJ   lib/python2.7/site-packages/IPython/terminal/tests/test_interactivshell.pyt   _ipython_display_r   s    (   R   R   RA   (    (    (    sJ   lib/python2.7/site-packages/IPython/terminal/tests/test_interactivshell.pyR>   q   s   t    (   R   t   display_formattert   active_typest   AssertionErrort   ipython_display_formattert   enabledt   objectt   formatt   assertEqualt   reprR   R    (	   R	   R   t	   formatterR:   t   objt   datat   _R>   t   captured(    (    sJ   lib/python2.7/site-packages/IPython/terminal/tests/test_interactivshell.pyt   test_plain_text_only_   s    				(   R   R   R,   R$   R9   RQ   (    (    (    sJ   lib/python2.7/site-packages/IPython/terminal/tests/test_interactivshell.pyR%   C   s   	R0   c           B   s   e  Z d  „  Z d „  Z RS(   c         C   sJ   | j  d ƒ } | d k rF t d ƒ } | | _ | d | _ | ‚ n  | S(   Nt   syntaxerrori    s   input contains "syntaxerror"i   (   t   findt   SyntaxErrort   textt   offset(   R	   t   linet   post   e(    (    sJ   lib/python2.7/site-packages/IPython/terminal/tests/test_interactivshell.pyt   push   s    		c         C   s   d  S(   N(    (   R	   (    (    sJ   lib/python2.7/site-packages/IPython/terminal/tests/test_interactivshell.pyt   resetŠ   s    (   R   R   RZ   R[   (    (    (    sJ   lib/python2.7/site-packages/IPython/terminal/tests/test_interactivshell.pyR0   €   s   		t   TerminalMagicsTestCasec           B   s   e  Z d  „  Z RS(   c         C   sS   t  ƒ  } d } | j j d } | j | d d ƒ|  j | j d d ƒ d ƒ d S(   s=   Test that code with a blank line doesn't get split (gh-3246).s-   def pasted_func(a):
    b = a+1

    return bt   TerminalMagicst   namet   pasted_funci6   i7   N(   R   t   magics_managert   registryt   store_or_executeR   RJ   t   user_ns(   R	   R   t   st   tm(    (    sJ   lib/python2.7/site-packages/IPython/terminal/tests/test_interactivshell.pyt   test_paste_magics_blanklineŽ   s
    	(   R   R   Rf   (    (    (    sJ   lib/python2.7/site-packages/IPython/terminal/tests/test_interactivshell.pyR\      s   (   R   R   t   unittestt   IPython.core.inputtransformerR    t   IPython.testingR   R5   t   IPython.utils.captureR   RH   R   R$   t   TestCaseR%   R0   R\   (    (    (    sJ   lib/python2.7/site-packages/IPython/terminal/tests/test_interactivshell.pyt   <module>   s   	=