ó
E®Uc           @   sr   d  Z  d d l Z d d l Z d d l Z d d l Z d d l m Z d „  Z d „  Z d e f d „  ƒ  YZ	 d S(   s   Source level Python tests.iÿÿÿÿN(   t   TestCasec    	   	   c   sW  t  j j t  j j t  j j t ƒ d d d ƒ ƒ }  t  j j |  ƒ sQ t |  ƒ ‚ xc t  j |  ƒ D]R \ } } } x@ | D]8 } | j	 d ƒ rw t  j j t  j j | | ƒ ƒ Vqw qw Wqa Wt  j j t  j j t  j j t ƒ d d d d d ƒ ƒ } t  j j | ƒ st | ƒ ‚ x‚ t  j
 | ƒ D]q } t  j j t  j j | | ƒ ƒ } t  j j | ƒ s]qn  t  j | ƒ } t  j j | ƒ j	 d ƒ r| VqqWt  j j t  j j t  j j t ƒ d d d d d d ƒ ƒ } t  j j | ƒ sít | ƒ ‚ xc t  j | ƒ D]R \ } } } x@ | D]8 } | j	 d ƒ rt  j j t  j j | | ƒ ƒ VqqWqýWd S(	   s%   Iterate over all Python source files.s   ..t   sambas   .pyt   bins   scripting/bint
   buildtoolst   wafsambaN(   t   ost   patht   abspatht   joint   dirnamet   __file__t   isdirt   AssertionErrort   walkt   endswitht   listdirt   islinkt   readlink(	   t   library_dirt   roott   dirst   filest   ft   bindirt   pt   targett   wafsambadir(    (    s6   /usr/lib/python2.7/dist-packages/samba/tests/source.pyt   get_python_source_files    s*    3+9!<c          c   s–   x t  ƒ  D]„ }  y t |  d ƒ } Wn? t k
 rd } | j t j k r^ t j d |  ƒ q
 qe ‚  n Xz | j ƒ  } Wd | j ƒ  X|  | f Vq
 Wd S(   s.   Iterate over the contents of all python files.t   rbs   source file %s broken link?N(	   R   t   opent   IOErrort   errnot   ENOENTt   warningst   warnt   readt   close(   t   fnameR   t   et   text(    (    s6   /usr/lib/python2.7/dist-packages/samba/tests/source.pyt   get_source_file_contents;   s    t
   TestSourcec           B   sY   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   c         C   së   g  } t  j d t  j ƒ } xi t ƒ  D]^ \ } } | j d ƒ rF q% n  d | k rX q% n  | j | ƒ } | s% | j | d f ƒ q% q% W| rç d d g } x2 | D]* \ } } | j | ƒ | j d | ƒ q  W|  j d	 j | ƒ ƒ n  d
 S(   s<   Test that all Python files have a valid copyright statement.s   #\s*copyright.*(?=
)s   ms_schema.pyR   s   no copyright line found
s:   Some files have missing or incorrect copyright statements.t    t    i   s   
Ns       (	   t   ret   compilet   IR(   R   t   searcht   appendt   failR   (   t   selft	   incorrectt   copyright_reR%   R'   t   matcht	   help_textt   comment(    (    s6   /usr/lib/python2.7/dist-packages/samba/tests/source.pyt   test_copyrightO   s"    	c         C   sÛ   g  } d } t  j t  j | ƒ t  j ƒ } x] t ƒ  D]R \ } } d | k rR q4 n  | j d ƒ rg q4 n  | j | ƒ s4 | j | ƒ q4 q4 W| r× d | g } x | D] } | j d	 | ƒ q£ W|  j d j	 | ƒ ƒ n  d S(
   s.   Test that all .py files have a GPL disclaimer.s{  
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
R   s   /python/samba/subunit/run.pys3   Some files have missing or incomplete GPL statementR+   i   s   
Ns       (
   R,   R-   t   escapet	   MULTILINER(   R   R/   R0   R1   R   (   R2   R3   t   gpl_txtt   gpl_reR%   R'   R6   (    (    s6   /usr/lib/python2.7/dist-packages/samba/tests/source.pyt   test_gplj   s     	c         C   s1   | | k r | g | | <n | | j  | ƒ d  S(   N(   R0   (   R2   t   dict_R%   t   line_no(    (    s6   /usr/lib/python2.7/dist-packages/samba/tests/source.pyt
   _push_file‘   s    c      
   C   st   g  | j  ƒ  D]B \ } } d | d j g  | D] } t | d ƒ ^ q, ƒ f ^ q } | j ƒ  | d d j | ƒ S(   Ns   %s: %ss   , i   s   

    %ss   
    (   t   itemsR   t   strt   sort(   R2   R>   t   messageR   t   linest   iR   (    (    s6   /usr/lib/python2.7/dist-packages/samba/tests/source.pyt   _format_message—   s    R
c         c   sh   xa t  ƒ  D]V \ } } | j t ƒ } t | ƒ d } x( t | ƒ D] \ } } | | | f VqB Wq
 Wd  S(   Ni   (   R(   t
   splitlinest   Truet   lent	   enumerate(   R2   R%   R'   RE   t   last_line_noR?   t   line(    (    s6   /usr/lib/python2.7/dist-packages/samba/tests/source.pyt   _iter_source_files_lines   s
    c         C   sn   i  } x? |  j  ƒ  D]1 \ } } } d | k r |  j | | | ƒ q q W| rj |  j |  j | d ƒ ƒ n  d S(   s-   Check that there are no tabs in Python files.s   	sm   Tab characters were found in the following source files.
They should either be replaced by "\t" or by spaces:N(   RN   R@   R1   RG   (   R2   t   tabsR%   R?   RM   (    (    s6   /usr/lib/python2.7/dist-packages/samba/tests/source.pyt   test_no_tabs¤   s    c         C   s   i  } xR |  j  ƒ  D]D \ } } } | j d ƒ sA | j d ƒ r |  j | | | ƒ q q W| r} |  j |  j | d ƒ ƒ n  d S(   s   Check for unix new lines.s   
s   
s;   Non-unix newlines were found in the following source files:N(   RN   R   R@   R1   RG   (   R2   t   illegal_newlinesR%   R?   RM   (    (    s6   /usr/lib/python2.7/dist-packages/samba/tests/source.pyt   test_unix_newlines¯   s    c         C   sz   i  } xK |  j  ƒ  D]= \ } } } | j d ƒ j d ƒ r |  j | | | ƒ q q W| rv |  j |  j | d ƒ ƒ n  d S(   s<   Check that there is not trailing whitespace in Python files.s   
R+   s<   Trailing whitespace was found in the following source files.N(   RN   t   rstripR   R@   R1   RG   (   R2   t   trailing_whitespaceR%   R?   RM   (    (    s6   /usr/lib/python2.7/dist-packages/samba/tests/source.pyt   test_trailing_whitespace¹   s    c         C   sñ   i  } i  } xš |  j  ƒ  D]Œ \ } } } | d k r: q n  t j | ƒ j d @} | j d ƒ } | r‚ | r‚ |  j | | | ƒ n  | r | r |  j | | | ƒ q q W| rË |  j |  j | d ƒ ƒ n  | rí |  j |  j | d ƒ ƒ n  d S(   sB   Check that files with shebang lines and only those are executable.i   iI   s   #!s0   Files with shebang line that are not executable:s/   Files without shebang line that are executable:N(   RN   R   t   statt   st_modet
   startswithR@   R1   RG   (   R2   t   files_with_shebangt   files_without_shebangR%   R?   RM   t
   executablet   has_shebang(    (    s6   /usr/lib/python2.7/dist-packages/samba/tests/source.pyt   test_shebang_linesÃ   s"    (   t   __name__t
   __module__R8   R=   R@   RG   RN   RP   RR   RU   R]   (    (    (    s6   /usr/lib/python2.7/dist-packages/samba/tests/source.pyR)   M   s   		'					
	
(
   t   __doc__R   R   R,   R!   t   samba.testsR    R   R(   R)   (    (    (    s6   /usr/lib/python2.7/dist-packages/samba/tests/source.pyt   <module>   s   		