ó
@K7]c           @` så   d  Z  d d l m Z m Z m Z d d l Z d d l m Z m Z d d l	 Z	 d d l
 m Z m Z m Z m Z m Z d d „ Z d „  Z d d „ Z d	 d
 „ Z d d „ Z d d „ Z d d „ Z d d „ Z d d „ Z d S(   s)   
Module to handle generating test files.
i    (   t   absolute_importt   divisiont   print_functionN(   t   joint   exists(   t	   copy_intot   ensure_listt   globt   on_wint   rm_rfc      
   C` sÄ   | s |  j  j } n  t } t j j | ƒ s= t j | ƒ n  x€ t |  j d g  ƒ ƒ D]f } t	 } t
 t |  j | ƒ ƒ } x? | D]7 } t | | j |  j | ƒ |  j  j d t d t	 ƒq WqV W| S(   s  
    Create the test files for pkg in the directory given.  The resulting
    test files are configuration (i.e. platform, architecture, Python and
    numpy version, ...) independent.
    Return False, if the package has no tests (for any configuration), and
    True if it has.
    s
   test/filest   lockingt   clobber(   t   configt   test_dirt   Falset   ost   patht   isdirt   makedirsR   t	   get_valuet   TrueR   R   R   t   replacet   timeout(   t   mR   t	   has_filest   patternt   filest   f(    (    s6   lib/python2.7/site-packages/conda_build/create_test.pyt   create_files   s    *c         C` sÆ   | r d n d } d | } | } |  j  r¼ d } xˆ |  j j d g  ƒ D]n } |  j ƒ  | j d ƒ k rG | j d i  ƒ j d d ƒ } t j j | ƒ d	 j ƒ  | k rµ | } Pqµ qG qG Wn  | | f S(
   Ns   .bats   .sht   run_tests   no-filet   outputst   namet   testt   scripti   (   t	   is_outputt   metat   getR   R   R   t   splitextt   lower(   R   t
   win_statust   extt   dst_namet   src_namet   outt   out_test_script(    (    s6   lib/python2.7/site-packages/conda_build/create_test.pyt   _get_output_script_name%   s    
	"c         C` sÈ  | s |  j  j } n  t g } |  j r6 t t g } n  g  } x…| D]}} t |  | ƒ \ } } t | | ƒ } t t |  j	 | ƒ ƒ r° t
 t |  j	 | ƒ | |  j  j d t ƒn  t j	 j | ƒ d k ržt |  j d g  ƒ ƒ } | ržt t | ƒ d ƒ › }	 |	 j d ƒ | s!|	 j d ƒ n  |	 j d ƒ x> | D]6 }
 |	 j |
 ƒ |	 j d ƒ | r5|	 j d ƒ q5q5W| r…|	 j d	 ƒ n |	 j d
 ƒ Wd  QXqžn  t j	 j | ƒ rC | j | ƒ qC qC W| S(   NR
   t   test_tmps   test/commandst   as   

s	   set -ex

s   
s    IF %ERRORLEVEL% NEQ 0 exit /B 1
s
   exit /B 0
s   exit 0
(   R   R   R   t   noarchR   R   R-   R   R   R   R   R   R   t   basenameR   R   t   opent   writet   isfilet   append(   R   R   R'   t   shell_filest   statusR*   R)   t	   dest_filet   commandsR   t   cmd(    (    s6   lib/python2.7/site-packages/conda_build/create_test.pyt   create_shell_files7   s<    		+s   # c         C` s  d | } |  j  r‘ d } xu |  j j d g  ƒ D][ } |  j ƒ  | j d ƒ k r/ | j d i  ƒ j d d ƒ } | j | ƒ rŠ | } PqŠ q/ q/ Wn  t | d | ƒ } | rÒt j j |  j | ƒ } t j j | ƒ rÒt	 | d ƒ ç }	 |	 j
 d	 | |  j ƒ  f ƒ |	 j
 d
 |  j ƒ  ƒ yt t	 | ƒ b }
 |	 j
 d j | ƒ ƒ |	 j
 d j | | ƒ ƒ |	 j
 |
 j ƒ  ƒ |	 j
 d j | | ƒ ƒ Wd  QXWn t k
 r®|	 j
 d ƒ n X|	 j
 d |  j ƒ  ƒ Wd  QXqÒn  | t | ƒ ot j j | ƒ ot j j | ƒ d k f S(   NR   t    R   R   R    R!   s   no-filet   ws,   %s tests for %s (this is a generated file);
s*   print('===== testing package: %s =====');
s   print('running {0}');
s   {0} --- {1} (begin) ---
s   {0} --- {1} (end) ---
s>   # tests were not packaged with this module, and cannot be run
s   
print('===== %s OK =====');
(   R"   R#   R$   R   t   endswithR   R   R   R4   R2   R3   t   distt   formatt   readt   AttributeErrort   boolR1   (   R   R   R(   t   comment_charR   R+   R,   t   out_filet	   test_filet   fot   fi(    (    s6   lib/python2.7/site-packages/conda_build/create_test.pyt   _create_test_files]   s4    
	##c         C` s»  | s |  j  j } n  t |  | d ƒ \ } } |  j ƒ  } | j d ƒ } | j d ƒ } | j d ƒ } | pu | pu | } | ré g  }	 x¿ t |  j d g  ƒ ƒ D]E }
 t |
 d ƒ r d |
 k r |
 d d k r |	 j |
 d	 ƒ q q Wn] t |  j d g  ƒ ƒ }	 g  |	 D]8 } t | d ƒ s:d | k r| d d k r| ^ q}	 |	 r§t	 | d
 ƒ G } x= |	 D]5 } | j
 d | ƒ | j
 d | ƒ | j
 d ƒ qeWWd  QXn  | s³|	 r·| St S(   Ns   .pys   r-s   lua-s   perl-s   test/importst   keyst   langt   pythont   importsR/   s   print("import: %r")
s
   import %s
s   
(   R   R   RI   R   t
   startswithR   R   t   hasattrt   extendR2   R3   R   (   R   R   t   tft	   tf_existst   pkg_namet   likely_r_pkgt   likely_lua_pkgt   likely_perl_pkgt   likely_non_python_pkgRM   t   import_itemt   itemRG   R   (    (    s6   lib/python2.7/site-packages/conda_build/create_test.pyt   create_py_files~   s0    (c         C` s4  | s |  j  j } n  t |  | d ƒ \ } } d  } |  j ƒ  j d ƒ rc t |  j d g  ƒ ƒ } n\ xY t |  j d g  ƒ ƒ D]? } t | d ƒ r| d | k r| | d d k r| | d } Pq| q| W| r t	 | d ƒ G } x= | D]5 } | j
 d	 | ƒ | j
 d
 | ƒ | j
 d ƒ qÞ WWd  QXn  | s,| r0| St S(   Ns   .rs   r-s   test/importsRJ   RK   t   rRM   R/   s   print("library(%r)")
s   library(%s)
s   
(   R   R   RI   t   NoneR   RN   R   R   RO   R2   R3   R   (   R   R   RQ   RR   RM   RX   RG   R   (    (    s6   lib/python2.7/site-packages/conda_build/create_test.pyt   create_r_files    s$    
c      	   C` s£  | s |  j  j } n  t |  | d ƒ \ } } d  } |  j ƒ  j d ƒ rc t |  j d g  ƒ ƒ } n\ xY t |  j d g  ƒ ƒ D]? } t | d ƒ r| d | k r| | d d k r| | d } Pq| q| W| sË | rt	 | d ƒ ° } t
 d	 |  j ƒ  j d
 ƒ d | ƒ| r†x} | D]r } t
 d | d | ƒt
 d | d | ƒd | k rt
 d d d d d d d d j | ƒ d | ƒqqWn  Wd  QXn  | s›| rŸ| St S(   Ns   .pls   perl-s   test/importsRJ   RK   t   perlRM   R/   s   my $expected_version = "%s";t   0t   files   print("import: %s\n");s   use %s;
t    s   if (defined {0}->VERSION) {{
s#   	my $given_version = {0}->VERSION;
s   	$given_version =~ s/0+$//;
s4   	die('Expected version ' . $expected_version . ' buts5    found ' . $given_version) unless ($expected_version s   eq $given_version);
s0   	print('	using version ' . {0}->VERSION . '
');
s   
}}(   R   R   RI   R\   R   RN   R   R   RO   R2   t   printt   versiont   rstripR@   R   (   R   R   RQ   RR   RM   RX   RG   R   (    (    s6   lib/python2.7/site-packages/conda_build/create_test.pyt   create_pl_filesº   s0    
*c      	   C` s-  | s |  j  j } n  t |  | d ƒ \ } } d  } |  j ƒ  j d ƒ rc t |  j d g  ƒ ƒ } n\ xY t |  j d g  ƒ ƒ D]? } t | d ƒ r| d | k r| | d d k r| | d } Pq| q| W| rt	 | d ƒ @ } x6 | D]. } t
 d	 | d
 | ƒt
 d | d
 | ƒqÞ WWd  QXn  | s%| r)| St S(   Ns   .luas   lua-s   test/importsRJ   RK   t   luaRM   s   a+s   print("require \"%s\"\n");R`   s   require "%s"
(   R   R   RI   R\   R   RN   R   R   RO   R2   Rb   R   (   R   R   RQ   RR   RM   RX   RG   R   (    (    s6   lib/python2.7/site-packages/conda_build/create_test.pyt   create_lua_filesÜ   s"    
!c   
      C` sý   | r t  | ƒ t j | ƒ |  j j d i  ƒ j d g  ƒ } | r t t j j | d ƒ d ƒ  } t j	 | | ƒ Wd  QXq n |  j
 j } t |  | ƒ } t |  | ƒ } t |  | ƒ } t |  | ƒ } t |  | ƒ } t |  | ƒ }	 | | | | | |	 f S(   NR    t   requiress   test_time_dependencies.jsonR=   (   R	   R   R   R#   R$   R2   R   R   t   jsont   dumpR   R   R   Re   RZ   R]   Rg   R;   (
   R   R   t	   test_depsR   R   t   pl_filest   py_filest   r_filest	   lua_filesR6   (    (    s6   lib/python2.7/site-packages/conda_build/create_test.pyt   create_all_test_filesñ   s    
!!(   t   __doc__t
   __future__R    R   R   R   t   os.pathR   R   Ri   t   conda_build.utilsR   R   R   R   R	   R\   R   R-   R;   RI   RZ   R]   Re   Rg   Rp   (    (    (    s6   lib/python2.7/site-packages/conda_build/create_test.pyt   <module>   s   (	&!""