ó
&9_[c           @   s  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l j Z	 d d l
 j j Z d d l m Z d d l m Z m Z d d l m Z e r¾ d d l m Z n d d l m Z d „  Z d e f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   s    Tests for autoreload extension.
iÿÿÿÿN(   t   AutoreloadMagics(   t   EventManagert   pre_run_cell(   t   PY3(   t   StringIOc          O   s   d  S(   N(   t   None(   t   at   kw(    (    sG   lib/python2.7/site-packages/IPython/extensions/tests/test_autoreload.pyt   <lambda>&   s    t	   FakeShellc           B   sB   e  Z d  „  Z e Z Z d „  Z d „  Z d „  Z d d „ Z
 RS(   c         C   sP   i  |  _  t |  d t h ƒ |  _ t d |  ƒ |  _ |  j j d |  j j ƒ d  S(   NR   t   shell(   t   nsR   R   t   eventsR    t   auto_magicst   register(   t   self(    (    sG   lib/python2.7/site-packages/IPython/extensions/tests/test_autoreload.pyt   __init__*   s    	c         B   s,   |  j  j d ƒ | |  j U|  j j ƒ  d  S(   NR   (   R   t   triggerR   R   t   post_execute_hook(   R   t   code(    (    sG   lib/python2.7/site-packages/IPython/extensions/tests/test_autoreload.pyt   run_code2   s    c         C   s   |  j  j | ƒ d  S(   N(   R   t   update(   R   t   items(    (    sG   lib/python2.7/site-packages/IPython/extensions/tests/test_autoreload.pyt   push7   s    c         C   s   |  j  j | ƒ d  S(   N(   R   t
   autoreload(   R   t	   parameter(    (    sG   lib/python2.7/site-packages/IPython/extensions/tests/test_autoreload.pyt   magic_autoreload:   s    c         C   s'   |  j  j | d | ƒ|  j  j ƒ  d  S(   Nt   stream(   R   t   aimportR   (   R   R   R   (    (    sG   lib/python2.7/site-packages/IPython/extensions/tests/test_autoreload.pyt   magic_aimport=   s    N(   t   __name__t
   __module__R   t   noopt   register_magicst   set_hookR   R   R   R   R   (    (    (    sG   lib/python2.7/site-packages/IPython/extensions/tests/test_autoreload.pyR	   (   s   	
			t   Fixturec           B   sM   e  Z d  Z d Z d Z d Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z RS(   s&   Fixture for creating test module filest#   abcdefghijklmopqrstuvwxyz0123456789c         C   sG   t  j ƒ  |  _ t t j ƒ |  _ t j j d |  j ƒ t ƒ  |  _	 d  S(   Ni    (
   t   tempfilet   mkdtempt   test_dirt   listt   syst   patht   old_sys_patht   insertR	   R
   (   R   (    (    sG   lib/python2.7/site-packages/IPython/extensions/tests/test_autoreload.pyt   setUpI   s    c         C   s;   t  j |  j ƒ |  j t _ d  |  _ d  |  _ d  |  _ d  S(   N(   t   shutilt   rmtreeR'   R+   R)   R*   R   R
   (   R   (    (    sG   lib/python2.7/site-packages/IPython/extensions/tests/test_autoreload.pyt   tearDownO   s
    		c         C   sd   d d j  t j |  j d ƒ ƒ } | t j k r> t j | =n  t j j  |  j | d ƒ } | | f S(   Nt   tmpmod_t    i   s   .py(	   t   joint   randomt   samplet   filename_charsR)   t   modulest   osR*   R'   (   R   t   module_namet	   file_name(    (    sG   lib/python2.7/site-packages/IPython/extensions/tests/test_autoreload.pyt
   get_moduleW   s
    "c         C   s?   t  j d ƒ t | d ƒ } z | j | ƒ Wd | j ƒ  Xd S(   s+  
        Write a file, and force a timestamp difference of at least one second

        Notes
        -----
        Python's .pyc files record the timestamp of their compilation
        with a time resolution of one second.

        Therefore, we need to force a timestamp difference between .py
        and .pyc, without having the .py file be timestamped in the
        future, and without changing the timestamp of the .pyc file
        (because that is stored in the file).  The only reliable way
        to achieve this seems to be to sleep.
        gÍÌÌÌÌÌð?t   wN(   t   timet   sleept   opent   writet   close(   R   t   filenamet   contentt   f(    (    sG   lib/python2.7/site-packages/IPython/extensions/tests/test_autoreload.pyt
   write_file^   s
    c         C   sJ   |  j  ƒ  \ } } t | d ƒ } z | j | ƒ Wd  | j ƒ  X| | f S(   NR<   (   R;   R?   R@   RA   (   R   R   t   mod_namet   mod_fnRD   (    (    sG   lib/python2.7/site-packages/IPython/extensions/tests/test_autoreload.pyt
   new_modulex   s    N(   R   R   t   __doc__R   R'   R+   R6   R-   R0   R;   RE   RH   (    (    (    sG   lib/python2.7/site-packages/IPython/extensions/tests/test_autoreload.pyR#   B   s   				t   TestAutoreloadc           B   s&   e  Z e d  „ Z d „  Z d „  Z RS(   c            s9  |  j  d ƒ \ } } | r |  j j d ƒ |  j j | ƒ t ƒ  } |  j j d d | ƒt j d | | j ƒ  ƒ t j t	 ƒ  |  j j d ƒ Wd QXn\ |  j j d ƒ |  j j
 d	 | ƒ t ƒ  } |  j j d d | ƒt j d
 | j ƒ  k ƒ t j | |  j j ƒ t j | ‰  ˆ  j ‰ ˆ  j d ƒ ‰ ˆ  j ƒ  ‰ ‡  ‡ ‡ ‡ f d †  } | ƒ  |  j | d ƒ t j d | d d ƒ |  j j
 d ƒ Wd QXt j d | d d ƒ |  j j
 d ƒ Wd QX| ƒ  |  j | d ƒ ‡  ‡ ‡ ‡ f d †  } |  j j
 d ƒ | ƒ  t j | ƒ |  j j
 d ƒ | ƒ  | r¢|  j j d | ƒ t ƒ  } |  j j d d | ƒt j d | | j ƒ  k ƒ |  j j d ƒ n |  j j d ƒ |  j | d ƒ |  j j
 d ƒ |  j j
 d ƒ | ƒ  | r|  j j | ƒ n |  j j d ƒ |  j j
 d ƒ t j ˆ  j d ƒ d S(   st   
        Functional test for the automatic reloader using either
        '%autoreload 1' or '%autoreload 2'
        s¸  
x = 9

z = 123  # this item will be deleted

def foo(y):
    return y + 3

class Baz(object):
    def __init__(self, x):
        self.x = x
    def bar(self, y):
        return self.x + y
    @property
    def quux(self):
        return 42
    def zzz(self):
        '''This method will be deleted below'''
        return 99

class Bar:    # old-style class: weakref doesn't work for it on Python < 2.7
    def foo(self):
        return 1
t   1R2   R   s   Modules to reload:
%st   tmpmod_as318989e89dsNt   2s	   import %ss%   Modules to reload:
all-except-skippedi	   c             sû   t  j ˆ  j d ƒ t  j ˆ  j d ƒ t  j ˆ d ƒ d ƒ t  j ˆ  j d ƒ d ƒ ˆ  j d ƒ }  t  j ˆ j d ƒ d ƒ t  j |  j d ƒ d ƒ t  j |  j d ƒ t  j |  j ƒ  d ƒ ˆ  j	 ƒ  } t  j ˆ j ƒ  d ƒ t  j | j ƒ  d ƒ d  S(	   Ni	   i{   i    i   i   i
   i*   ic   (
   t   ntt   assert_equalt   xt   zt   foot   Bazt   bart   quuxt   zzzt   Bar(   t   objt   obj2(   t   modt   old_foot   old_objt   old_obj2(    sG   lib/python2.7/site-packages/IPython/extensions/tests/test_autoreload.pyt   check_module_contentsÃ   s    s   
a syntax error
s   [autoreload of %s failed:t   channelt   stderrt   passs  
x = 10

def foo(y):
    return y + 4

class Baz(object):
    def __init__(self, x):
        self.x = x
    def bar(self, y):
        return self.x + y + 1
    @property
    def quux(self):
        return 43

class Bar:    # old-style class
    def foo(self):
        return 2
c             s'  t  j ˆ  j d ƒ t  j t ˆ  d ƒ ƒ t  j ˆ d ƒ d ƒ t  j ˆ  j d ƒ d ƒ ˆ  j d ƒ }  t  j ˆ j d ƒ d ƒ t  j |  j d ƒ d ƒ t  j ˆ j d ƒ t  j |  j d ƒ t  j t ˆ d	 ƒ ƒ t  j t |  d	 ƒ ƒ ˆ  j	 ƒ  } t  j ˆ j ƒ  d
 ƒ t  j | j ƒ  d
 ƒ d  S(   Ni
   RQ   i    i   i	   i   i   i+   RV   i   (
   RN   RO   RP   t   assert_falset   hasattrRR   RS   RT   RU   RW   (   RX   RY   (   RZ   R[   R\   R]   (    sG   lib/python2.7/site-packages/IPython/extensions/tests/test_autoreload.pyR^   û   s    t   -s   Modules to skip:
%ss   -tmpmod_as318989e89dst   0s	   
x = -99
iÿÿÿ(   RH   R
   R   R   R   RN   t	   assert_int   getvaluet   assert_raisest   ImportErrorR   t   assert_trueR   R)   R7   RR   RS   RW   RE   t   ttt   AssertPrintst   AssertNotPrintsR8   t   unlinkRO   RP   (   R   t   use_aimportRF   RG   R   R^   (    (   RZ   R[   R\   R]   sG   lib/python2.7/site-packages/IPython/extensions/tests/test_autoreload.pyt   _check_smoketest†   sp    								c         C   s   |  j  d t ƒ d  S(   NRo   (   Rp   t   True(   R   (    (    sG   lib/python2.7/site-packages/IPython/extensions/tests/test_autoreload.pyt   test_smoketest_aimport=  s    c         C   s   |  j  d t ƒ d  S(   NRo   (   Rp   t   False(   R   (    (    sG   lib/python2.7/site-packages/IPython/extensions/tests/test_autoreload.pyt   test_smoketest_autoreload@  s    (   R   R   Rq   Rp   Rr   Rt   (    (    (    sG   lib/python2.7/site-packages/IPython/extensions/tests/test_autoreload.pyRJ   …   s   ·	(   RI   R8   R)   R%   R.   R4   R=   t
   nose.toolst   toolsRN   t   IPython.testing.toolst   testingRk   t   IPython.extensions.autoreloadR    t   IPython.core.eventsR   R   t   IPython.utils.py3compatR   t   ioR   R    t   objectR	   R#   RJ   (    (    (    sG   lib/python2.7/site-packages/IPython/extensions/tests/test_autoreload.pyt   <module>   s$   	C