a
    )&iD3                     @   sz  d dl Z d dlZd dlZd dlmZmZ d dlmZ d dlZd dl	Z	de j
v rZe j
d Zne je je jedZg dZh dZh dZh d	Zd
d Ze ZedddefddZdd Zdd Zi Zdd ZedjZi Zdd Z edjZ!i Z"dd Z#G dd deZ$G dd deZ%G dd deZ&G d d! d!e&Z'G d"d# d#e&Z(e$)  e%)  e')  e()  dS )$    N)TestCasecheck_help_consistency)	TestSuiteZ
SRCDIR_ABSz../../..)Z	bootstrapZtestdataZctdbZ
dfs_serverZpidlZauthZ	packagingpythonZincludeZnsswitchZlibcliZcoverityzrelease-scriptsZ	testprogsbinZsource3zdocs-xmlZ
buildtoolsZfile_serverZ	dynconfigZsource4ZtestsZlibdsZselftestlibZscriptZtrafficZ	testsuiteZlibgpoZwintestZlibrpc>-   zsource3/selftest/tests.pyselftest/tap2subunitz@python/samba/tests/krb5/ms_kile_client_principal_lookup_tests.pyzscript/autobuild.pyz,python/samba/tests/krb5/rfc4120_constants.pyzbin/python/samba/subunit/run.pyz$python/samba/tests/krb5/spn_tests.pyzscript/show_test_timez)python/samba/tests/dcerpc/raw_protocol.pyzsource4/selftest/tests.pyz)python/samba/tests/krb5/test_idmap_nss.pyz(python/samba/tests/krb5/kpasswd_tests.pyz'python/samba/tests/krb5/simple_tests.pyz#source4/scripting/bin/gen_output.pyz%python/samba/tests/krb5/salt_tests.pyz"python/samba/tests/krb5/kcrypto.pyz.python/samba/tests/krb5/test_min_domain_uid.pyz.python/samba/tests/krb5/compatability_tests.pyzctdb/utils/etcd/ctdb_etcd_lockzbuildtools/bin/wafzpython/samba/subunit/run.pyz(source4/scripting/bin/samba_downgrade_dbz&python/samba/tests/krb5/test_ccache.pyzlib/ldb/tests/python/index.pyzscript/bisect-test.pyz'python/samba/tests/krb5/as_req_tests.pyz'python/samba/tests/krb5/xrealm_tests.pyz#python/samba/tests/krb5/test_smb.pyz&python/samba/tests/krb5/alias_tests.pyz$python/samba/tests/krb5/kdc_tests.pyz4python/samba/tests/krb5/as_canonicalization_tests.pyz#python/samba/tests/krb5/test_rpc.pyz(python/samba/tests/krb5/kdc_base_test.pyzbin/gen_output.pyz(python/samba/tests/krb5/kdc_tgs_tests.pyzselftest/filter-subunitzselftest/tests.pyzselftest/format-subunitz source4/scripting/bin/subunitrunzbin/samba_downgrade_dbz$python/samba/tests/krb5/test_ldap.pyzlib/ldb/tests/python/api.pyz$python/samba/tests/krb5/s4u_tests.pyz%python/samba/tests/krb5/rodc_tests.pyz%python/samba/tests/krb5/fast_tests.py>   zwintest/test-s3.pyr   zwintest/test-s4-howto.py>   zbin/python/samba/testszbin/abzbin/python/samba/tests/krb5zsource3/script/testszsource4/dsdb/tests/pythonzbin/python/samba/tests/dcerpczpython/examplesc               	   C   s\   t  } tjddtddgtjd}|jdkrV|jdD ]}| t	j
t|d q6| jS )	zUGenerate a function that quickly answers the question:
    'is this a git file?'
    Zgitz-Czls-filesz-z)stdoutr       utf-8)set
subprocessrunBASEDIRPIPE
returncoder	   splitaddospathjoindecode__contains__)Zgit_file_cachepfn r   3/usr/lib/python3/dist-packages/samba/tests/usage.py_init_git_file_finder   s    
r   c                 C   s|  |stt dj}|D ]Z}tj| |}tj|ddD ]6\}}	}
|
D ]$}|drZqH|drfqHtj||}zt|}W n t	y   Y qHY n0 |j
tj@ sqH|dkst|sqH|d ur||sqH|d urFzt|d}W nB ty& } z(td||f  W Y d }~qHW Y d }~n
d }~0 0 |d	}|  ||sFqH|d
|}||v rf|d
7 }qP|||< qHq8q| S )Nz\W+F)followlinks~z.instr   rbzcould not open %s: %s(   _)recompilesubr   r   r   walkendswithstatFileNotFoundErrorst_modeS_IXUSRis_git_fileopenOSErrorprintreadcloseitems)dcacheshebang_filterfilename_filtersubdirsZsafenameZsubdirZsdrootdirsfilesr   Zffnsfelinenamer   r   r   script_iterator   sJ    





"



r@   c                 C   s*   |  dd } | o(d| vo(d| vo(d| v S )Nzbin/   /testZldb)	partition)r   r   r   r   elf_file_name   s    rE   c                 C   s   | d d dkS )N   s   ELFr   )xr   r   r   elf_shebang   s    rH   c                   C   s   t ttttdgdS )Nr   )r5   r6   r7   )r@   r   	elf_cacherH   rE   r   r   r   r   elf_iterator   s
    rJ   s   #!.+perlc                   C   s   t tttS N)r@   r   perl_script_cacheperl_shebangr   r   r   r   perl_script_iterator   s    rN   s
   #!.+pythonc                   C   s   t tttS rK   )r@   r   python_script_cachepython_shebangr   r   r   r   python_script_iterator   s    rQ   c                   @   s   e Zd ZdZedd ZdS )PerlScriptUsageTestszgPerl scripts run without arguments should print a usage string,
        not fail with a traceback.
    c                 C   s   t  D ]\}}t|| qd S rK   )rN   r/   )clsr?   filenamer   r   r   
initialise   s    zPerlScriptUsageTests.initialiseN__name__
__module____qualname____doc__classmethodrU   r   r   r   r   rR      s   rR   c                   @   s   e Zd ZdZedd ZdS )PythonScriptUsageTestsziPython scripts run without arguments should print a usage string,
        not fail with a traceback.
    c                 C   sv   t  D ]j\}}|tdd}|tv r6td|  qtj|t	v rTtd|  q|fdd}t
| d| | qd S )N rB   zskipping %s (EXCLUDE_USAGE)skipping %s (EXCLUDE_DIRS)c              
   S   s   t | z,tjd|gtjtjd}|jdd\}}W nd tyf } z| d|  W Y d }~n<d }~0  tjy } z| d|  W Y d }~n
d }~0 0 |d}|d}| 	d| | 
d	| |  d
||f  d S )Npython3stderrr	      Ztimeout	Error: %sSubprocess error: %sr   Z	Tracebackusagezstdout:
%s
stderr:
%s)r/   r   Popenr   communicater.   failSubprocessErrorr   ZassertNotInassertInlower)selfrT   r   outerrr=   r   r   r   _f  s"    
"$


z-PythonScriptUsageTests.initialise.<locals>._ftest_%s)rQ   replacer   lstripEXCLUDE_USAGEr/   r   r   dirnameEXCLUDE_DIRSsetattrrS   r?   rT   r   rp   r   r   r   rU      s    z!PythonScriptUsageTests.initialiseNrV   r   r   r   r   r\      s   r\   c                   @   sD   e Zd ZdZdZdZdZdZdZdZ	dZ
dZdd Zedd ZdS )	HelpTestSuper`Python scripts run with -h or --help should print a help string,
    and exit with success.
    TFNc                 C   s   t dd S )Nz+Subclass this and add an iterator function!)NotImplementedError)rm   r   r   r   iterator'  s    zHelpTestSuper.iteratorc                 C   sx   |   D ]j\}}|tdd}|tv r8td|  qtj|t	v rVtd|  q|fdd}t
| d| | qd S )Nr]   rB   zskipping %s (EXCLUDE_HELP)r^   c           
      S   sv  t | dD ]b}||g}| jr.|d| j z(tj|tjtjd}|jdd\}}W nd ty } z| d|  W Y d }~n<d }~0  tj	y } z| d|  W Y d }~n
d }~0 0 |
d}|
d}| jrd	||f }|d d
  }| jrt|| j| j}	|	d ur| |	 | jrF| |jdd|||j||f  | jr\| d|d | jr| d|d qd S )N)z--helpz-hr   r`   rb   rc   rd   re   r   z%s
%si  z1%s %s
returncode should not be %d
err:
%s
out:
%srf   zlacks "Usage:"

zexpected multi-line output)r/   interpreterinsertr   rg   r   rh   r.   ri   rj   r   check_merged_out_and_errrl   check_consistencyr   options_startoptions_endcheck_return_codeZassertEqualr   check_contains_usagerk   check_multiline)
rm   rT   hcmdr   rn   ro   r=   Zoutlerrorsr   r   r   rp   ;  sJ    
"$




z$HelpTestSuper.initialise.<locals>._frq   )r|   rr   r   rs   EXCLUDE_HELPr/   r   r   ru   rv   rw   rx   r   r   r   rU   +  s    4zHelpTestSuper.initialise)rW   rX   rY   rZ   r   r   r   r   r   r~   r   r   r|   r[   rU   r   r   r   r   ry     s   ry   c                   @   s   e Zd ZdZeZdZdS )PythonScriptHelpTestsrz   r_   N)rW   rX   rY   rZ   rQ   r|   r~   r   r   r   r   r   r  s   r   c                   @   s   e Zd ZdZeZdZdZdS )ElfHelpTestsz^ELF binaries run with -h or --help should print a help string,
    and exit with success.
    FTN)rW   rX   rY   rZ   rJ   r|   r   r   r   r   r   r   r   z  s   r   )*r   sysr   Zsamba.testsr   r   Zunittestr   r#   r(   environr   r   abspathr   ru   __file__Z	TEST_DIRSrt   r   rv   r   r,   r@   rE   rH   rI   rJ   r$   matchrM   rL   rN   rP   rO   rQ   rR   r\   ry   r   r   rU   r   r   r   r   <module>   sR   
#0
/+Y	