
    b"                     f    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mZ d Zd Z	 G d de          Z
dS )zSource level Python tests.    N)TestCasec               #     K   t           j                            t           j                            t           j                            t
                    ddd                    } t           j                            |           s
J |             t          j        |           D ]_\  }}}|D ]V}|                    d          r?t           j                            t           j                            ||                    V  W`t           j                            t           j                            t           j                            t
                    ddddd                    }t           j                            |          s
J |            t          j	        |          D ]}t           j                            t           j                            ||                    }t           j        
                    |          s_t          j        |          }t           j                            |                              d          r|V  t           j                            t           j                            t           j                            t
                    dddddd                    }t           j                            |          s
J |            t          j        |          D ]_\  }}}|D ]V}|                    d          r?t           j                            t           j                            ||                    V  W`dS )	z%Iterate over all Python source files.z..sambaz.pybinzscripting/bin
buildtoolswafsambaN)ospathabspathjoindirname__file__isdirwalkendswithlistdirislinkreadlink)	library_dirrootdirsfilesfbindirptargetwafsambadirs	            4/usr/lib/python3/dist-packages/samba/tests/source.pyget_python_source_filesr   !   s     '//"',,rwx/H/H$PTV]"^"^__K7==%%22{222W[11 = =dE 	= 	=Azz%   =goobgll4&;&;<<<<<	= W__RW\\"'//(*C*CT4QUW[]bccddF7==  ((&(((Z  GOOBGLL3344w~~a   	Q7??6""++O<< 	GGG'//"',,rwx/H/H$PTVZ\`bnpz"{"{||K7==%%22{222W[11 = =dE 	= 	=Azz%   =goobgll4&;&;<<<<<	== =    c               #   x  K   t                      D ]} 	 t          j        | dd          }nD# t          $ r7}|j        t          j        k    rt          j        d| z             Y d}~V d}~ww xY w	 |                                }|	                                 n# |	                                 w xY w| |fV  dS )z.Iterate over the contents of all python files.rzutf-8)modeencodingzsource file %s broken link?N)
r   ioopenIOErrorerrnoENOENTwarningswarnreadclose)fnamer   etexts       r   get_source_file_contentsr1   <   s      (**  	C':::AA 	 	 	w%,&&;eCDDD		6688DGGIIIIAGGIIIITk s&   ,
A-,A('A((A-1BB0c                   D    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
S )
TestSourcec                 $   g }t          j        dt           j                  }t                      D ]z\  }}|                    d          rd|v r |                    d          r6|                    d          rL|                    |          }|s|                    |df           {|rcddg}|D ]2\  }}|                    |           |                    d	|z              3|                     d
                    |                     dS dS )z<Test that all Python files have a valid copyright statement.z#\s*copyright.*(?=
)zms_schema.pyr   "python/samba/tests/krb5/kcrypto.py)python/samba/tests/krb5/rfc4120_pyasn1.pyzno copyright line found
z:Some files have missing or incorrect copyright statements.     
N)	recompileIr1   r   searchappendfailr   )self	incorrectcopyright_rer.   r0   match	help_textcomments           r   test_copyrightzTestSource.test_copyrightP   sL   	z":BDAA355 	G 	GKE4~~n-- U""~~BCC ~~IJJ  ''--E G  %)D!EFFF 	, "$I #, 6 6w  '''  'W!45555IIdii	**+++++	, 	,r    c                    g }d}t          j        t          j        |          t           j                  }t	                      D ]v\  }}d|v r
|                    d          r |                    d          r6|                    d          rL|                    |          s|                    |           w|rKd|g}|D ]}|                    d|z              |                     d	                    |                     d	S d	S )
z.Test that all .py files have a GPL disclaimer.a{  
# 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   z/python/samba/subunit/run.pyr5   r6   z3Some files have missing or incomplete GPL statementr8   r9   N)
r:   r;   escape	MULTILINEr1   r   r=   r>   r?   r   )r@   rA   gpl_txtgpl_rer.   r0   rD   s          r   test_gplzTestSource.test_gplq   s5   	 BIg..==355 	( 	(KE4U""~~<==  ~~BCC ~~IJJ ==&& (  ''' 	,N "I" 4 4  'U!23333IIdii	**+++++	, 	,r    c                 T    ||vr|g||<   d S ||                              |           d S )N)r>   )r@   dict_r.   line_nos       r   
_push_filezTestSource._push_file   s:    #9E%LLL%L(((((r    c                     d |                                 D             }|                                 |dd                    |          z  z   S )Nc                 \    g | ])\  }}|d d                     d |D                       *S )z: z, c                 2    g | ]}t          |d z             S )   )str).0is     r   
<listcomp>z9TestSource._format_message.<locals>.<listcomp>.<listcomp>   s"    *E*E*E!3q1u::*E*E*Er    )r   )rV   r   liness      r   rX   z.TestSource._format_message.<locals>.<listcomp>   sS     0 0 0Q QQ		*E*Eu*E*E*E F F FG 0 0 0r    z

    %sz
    )itemssortr   )r@   rN   messager   s       r   _format_messagezTestSource._format_message   sQ    0 0!&0 0 0

u)=)=>>>r    c              #      K   t                      D ]6\  }}|                    d          }t          |          D ]\  }}|||fV  7d S )NT)r1   
splitlines	enumerate)r@   r.   r0   rY   rO   lines         r   _iter_source_files_linesz#TestSource._iter_source_files_lines   sp      355 	+ 	+KE4OOD))E!*5!1!1 + +Wd*****+	+ 	+r    c                     i }|                                  D ]!\  }}}d|v r|                     |||           "|r+|                     |                     |d                     dS dS )z-Check that there are no tabs in Python files.	zmTab characters were found in the following source files.
They should either be replaced by "\t" or by spaces:N)rb   rP   r?   r]   )r@   tabsr.   rO   ra   s        r   test_no_tabszTestSource.test_no_tabs   s    $($A$A$C$C 	6 	6 E7Dt||eW555 	gIId**4,ef f g g g g g	g 	gr    c                    i }|                                  D ]G\  }}}|                    d          r|                    d          r|                     |||           H|r+|                     |                     |d                     dS dS )zCheck for unix new lines.r9   z
z;Non-unix newlines were found in the following source files:N)rb   r   rP   r?   r]   )r@   illegal_newlinesr.   rO   ra   s        r   test_unix_newlineszTestSource.test_unix_newlines   s    $($A$A$C$C 	B 	B E7D==&& B$--*?*? B 0%AAA 	kIId**+;+hj j k k k k k	k 	kr    c                    i }|                                  D ]E\  }}}|                    d                              d          r|                     |||           F|r+|                     |                     |d                     dS dS )z<Check that there is not trailing whitespace in Python files.r9    z<Trailing whitespace was found in the following source files.N)rb   rstripr   rP   r?   r]   )r@   trailing_whitespacer.   rO   ra   s        r   test_trailing_whitespacez#TestSource.test_trailing_whitespace   s     $($A$A$C$C 	E 	E E7D{{4  ))#.. E 3UGDDD 	lIId**+>+ik k l l l l l	l 	lr    c                    i }i }|                                  D ]t\  }}}|dk    rt          j        |          j        dz  }|                    d          }|r|s|                     |||           |s|r|                     |||           u|r)|                     |                     |d                     |r+|                     |                     |d                     dS dS )zBCheck that files with shebang lines and only those are executable.rT   I   z#!z0Files with shebang line that are not executable:z/Files without shebang line that are executable:N)rb   r	   statst_mode
startswithrP   r?   r]   )r@   files_with_shebangfiles_without_shebangr.   rO   ra   
executablehas_shebangs           r   test_shebang_lineszTestSource.test_shebang_lines   sE    "$($A$A$C$C 	G 	G E7D!||'%..058J//$//K D: D 2E7CCC G: G 5ugFFF 	`IId**+=+]_ _ ` ` `  	_IId**+@+\^ ^ _ _ _ _ _	_ 	_r    N)__name__
__module____qualname__rF   rL   rP   r]   rb   rf   ri   rn   rx    r    r   r3   r3   N   s        , , ,B+, +, +,Z) ) )? ? ?+ + +	g 	g 	gk k kl l l_ _ _ _ _r    r3   )__doc__r%   r(   r	   r:   r*   samba.testsr   r   r1   r3   r|   r    r   <module>r      s   ( !   				  				 				      
= = =6  $S_ S_ S_ S_ S_ S_ S_ S_ S_ S_r    