ó
Ð4¹[c           @   s³   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 g Z e j j e	 ƒ Z
 d a d „  Z d „  Z d Z d e f d „  ƒ  YZ e  j d d „ ƒ Z d S(	   iÿÿÿÿNt   MockCommandt   assert_callsc         C   s#   |  t  j t  j d t  j d <d  S(   Nt   PATH(   t   ost   pathsept   environ(   t   dir(    (    s0   lib/python2.7/site-packages/testpath/commands.pyt   prepend_to_path   s    c         C   sC   t  j d j t  j ƒ } | j |  ƒ t  j j | ƒ t  j d <d  S(   NR   (   R   R   t   splitR   t   removet   join(   R   t	   path_dirs(    (    s0   lib/python2.7/site-packages/testpath/commands.pyt   remove_from_path   s    sý   #!{python}
import os, sys
import json

with open({recording_file!r}, 'a') as f:
    json.dump({{'env': dict(os.environ),
               'argv': sys.argv,
               'cwd': os.getcwd()}},
              f)
    f.write('\x1e') # ASCII record separator
c           B   sM   e  Z d  Z d d „ Z d „  Z e d „  ƒ Z d „  Z d „  Z	 d „  Z
 RS(   sK  Context manager to mock a system command.
    
    The mock command will be written to a directory at the front of $PATH,
    taking precedence over any existing command with the same name.
    
    By specifying content as a string, you can determine what running the
    command will do. The default content records each time the command is
    called and exits: you can access these records with mockcmd.get_calls().
    
    On Windows, the specified content will be run by the Python interpreter in
    use. On Unix, it should start with a shebang (``#!/path/to/interpreter``).
    c         C   st   | |  _  | |  _ t d  k r- t j ƒ  a n  t j d t d | d d ƒ \ } |  _ t j	 | ƒ t j ƒ  |  _
 d  S(   NR   t   prefixt   suffixs   .json(   t   namet   contentt   recording_dirt   Nonet   tempfilet   mkdtempt   mkstempt   recording_fileR   t   closet   command_dir(   t   selfR   R   t   fd(    (    s0   lib/python2.7/site-packages/testpath/commands.pyt   __init__2   s    		c         C   sg   t  j d k r d n d } t j j t d | ƒ } t j j |  j |  j d ƒ } t j	 | | ƒ d  S(   Ni   i    t   64t   32s
   cli-%s.exes   .exeI       (
   t   syst   maxsizeR   t   pathR
   t   pkgdirR   R   t   shutilt   copy(   R   t   bitnesst   srct   dst(    (    s0   lib/python2.7/site-packages/testpath/commands.pyt	   _copy_exe>   s    c         C   s;   t  j j |  j |  j ƒ } t  j d k r7 | d 7} n  | S(   Nt   nts
   -script.py(   R   R    R
   R   R   (   R   t   p(    (    s0   lib/python2.7/site-packages/testpath/commands.pyt	   _cmd_pathD   s    c         C   sÒ   t  j j |  j ƒ r4 t d |  j |  j f ƒ ‚ n  |  j d  k rg t j	 d t
 j d |  j ƒ |  _ n  t |  j d ƒ  } | j |  j ƒ Wd  QXt  j d k r® |  j ƒ  n t  j |  j d ƒ t |  j ƒ |  S(   Ns   Command %r already exists at %st   pythonR   t   wR(   ií  (   R   R    t   isfileR*   t   EnvironmentErrorR   R   R   t   _record_runt   formatR   t
   executableR   t   opent   writeR'   t   chmodR   R   (   R   t   f(    (    s0   lib/python2.7/site-packages/testpath/commands.pyt	   __enter__L   s    c         C   s'   t  |  j ƒ t j |  j d t ƒd  S(   Nt   ignore_errors(   R   R   R"   t   rmtreet   True(   R   t   etypet   evaluet   tb(    (    s0   lib/python2.7/site-packages/testpath/commands.pyt   __exit__a   s    c         C   s}   t  d k r g  St j j |  j ƒ s) g  St |  j d ƒ   } | j ƒ  j d ƒ d  } Wd QXg  | D] } t	 j
 | ƒ ^ qd S(   sI  Get a list of calls made to this mocked command.
        
        This relies on the default script content, so it will return an
        empty list if you specified a different content parameter.
        
        For each time the command was run, the list will contain a dictionary
        with keys argv, env and cwd.
        t   rs   iÿÿÿÿN(   R   R   R   R    R-   R   R2   t   readR   t   jsont   loads(   R   R5   t   chunkst   c(    (    s0   lib/python2.7/site-packages/testpath/commands.pyt	   get_callse   s    	N(   t   __name__t
   __module__t   __doc__R   R   R'   t   propertyR*   R6   R=   RD   (    (    (    s0   lib/python2.7/site-packages/testpath/commands.pyR    %   s   			c         #   sÉ   t  |  ƒ  } d VWd QX| j ƒ  } | g  k sB t d |  ƒ ‚ ˆ  d k	 rÅ t ‡  f d †  | Dƒ ƒ sÅ d |  ˆ  f d g } x' | D] } | j d | d d ƒ q‡ Wt d	 j | ƒ ƒ ‚ qÅ n  d S(
   s›  Assert that a block of code runs the given command.
    
    If args is passed, also check that it was called at least once with the
    given arguments (not including the command name).
    
    Use as a context manager, e.g.::
    
        with assert_calls('git'):
            some_function_wrapping_git()
            
        with assert_calls('git', ['add', myfile]):
            some_other_function()
    Ns   Command %r was not calledc         3   s#   |  ] } ˆ  | d  d k Vq d S(   t   argvi   N(    (   t   .0RC   (   t   args(    s0   lib/python2.7/site-packages/testpath/commands.pys	   <genexpr>   s    s2   Command %r was not called with specified args (%r)s$   It was called with these arguments: s     %rRI   i   s   
(   R    RD   t   AssertionErrorR   t   anyt   appendR
   (   t   cmdRK   t   mct   callst   msgRC   (    (   RK   s0   lib/python2.7/site-packages/testpath/commands.pyR   z   s    
	(   t
   contextlibR@   R   R"   R   R   t   __all__R    t   dirnamet   __file__R!   R   R   R   R   R/   t   objectR    t   contextmanagerR   (    (    (    s0   lib/python2.7/site-packages/testpath/commands.pyt   <module>   s   		U