HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/samba/subunit/__pycache__/run.cpython-310.pyc
o

�/ad`�@s&dZddlZddlZddlZddlZGdd�dej�Zddd�Zddd	�Zd
d�Z	ej
Z
ejZe
e
dd�durRzddlZe��Z
ejZd
ZWn
eyQdZYnwd
ZdZdZdZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�Zedkr�edejejd�dSdS)znRun a unittest testcase reporting results as Subunit.

  $ python -m samba.subunit.run mylib.tests.test_suite
�NcsfeZdZdZdd�Zddd�Zdd�Z�fd	d
�Z�fdd�Zd
d�Z	dd�Z
dd�Zdd�Z�Z
S)�TestProtocolClienta�A TestResult which generates a subunit stream for a test run.

    # Get a TestSuite or TestCase to run
    suite = make_suite()
    # Create a stream (any object with a 'write' method). This should accept
    # bytes not strings: subunit is a byte orientated protocol.
    stream = open('tests.log', 'wb')
    # Create a subunit result object which will output to the stream
    result = subunit.TestProtocolClient(stream)
    # Optionally, to get timing data for performance analysis, wrap the
    # serialiser with a timing decorator
    result = subunit.test_results.AutoTimingTestResultDecorator(result)
    # Run the test suite reporting to the subunit result object
    suite.run(result)
    # Close the stream.
    stream.close()
    cCstj�|�||_g|_dS�N)�unittest�
TestResult�__init__�_stream�	successes)�self�stream�r�3/usr/lib/python3/dist-packages/samba/subunit/run.pyr4s
zTestProtocolClient.__init__NcCsp|j�d||���|r0|j�d�|D]}|j�|�|�d�s)|j�d�q|j�d�|j�d�dS)z�Report an outcome of test test.

        :param outcome: A string describing the outcome - used as the
            event name in the subunit stream.
        :param errors: A list of strings describing the errors.
        z%s: z [
�
�]N)r�write�id�endswith)r	�outcome�test�errors�errorrrr�_addOutcome9s
�zTestProtocolClient._addOutcomecCs|j�|�dS)zReport a success in a test.N)r�append�r	rrrr�
addSuccessJszTestProtocolClient.addSuccesscs6tt|��|�|j�d|��d�|j��dS)z%Mark a test as starting its test run.ztest: r
N)�superr�	startTestrrr�flushr��	__class__rrrNszTestProtocolClient.startTestcstt|��|�|�|�dS)z,Mark a test as having finished its test run.N)rr�stopTest�writeOutcomerrrrrTszTestProtocolClient.stopTestc	Cs�|�||j�\}|_|�||j�\}|_|�||j�\}|_|�||j�\}|_|�||j�\}|_|�||j�\}|_|rAd}n|rFd}n|rKd}n|rPd}n|rUd}n|rZd}nd}|rl|j||||||d�|j	�
�dS)	z)Output the overall outcome for test test.r�failure�skip�	uxsuccess�xfail�
successfulN)r)�
_filterErrorsr�failures�expectedFailures�skipped�_filterSuccessesr�unexpectedSuccessesrrr)	r	r�err�failr$r"�successr#rrrrr Ys,zTestProtocolClient.writeOutcomecCs@g}g}|D]}|d|ur|�|d�q|�|�q||fS)a^Filter a list of errors by test test.

        :param test: The test to filter by.
        :param errors: A list of <test, error> pairs to filter.

        :return: A pair whose first element is a list of strings containing
            errors that apply to test test, and whose second element is a list
            of the remaining elements.
        r��r)r	rr�filtered�
unfilteredrrrrr&vs
z TestProtocolClient._filterErrorscCs2d}g}|D]}||urd}q|�|�q||fS)abFilter a list of successes by test test.

        :param test: The test to filter by.
        :param successes: A list of tests to filter.

        :return: A tuple whose first element is a boolean stating whether test
            test was found in the list of successes, and whose second element is
            a list of the remaining elements.
        FTr0)r	rrr1r2r.rrrr*�s
z#TestProtocolClient._filterSuccessesc
Cs>|�tjj�}|j�d|j|j|j|j	|j
|j|jf�dS)z^Inform the client of the time.

        ":param datetime: A datetime.datetime object.
        z*time: %04d-%02d-%02d %02d:%02d:%02d.%06dZ
N)
�
astimezone�datetime�timezone�utcrr�year�month�day�hour�minute�second�microsecond)r	�
a_datetime�timerrrr?�s
�zTestProtocolClient.timer)�__name__�
__module__�__qualname__�__doc__rrrrrr r&r*r?�
__classcell__rrrrr!s
rFcCs�zt|�}Wnty|��|fgYSwt|�tjfvs!|r1g}|D]	}|�t|��q%|Sd}t|�}|D]}|��}t	|dd�durL|�
�||fgS)N�
sort_tests)�iter�	TypeErrorr�typer�	TestSuite�extend�_flatten_tests�
iterate_tests�getattrrE)�
suite_or_case�unpack_outer�tests�resultr�suite_idrrrrK�s(��
rKcCs(t||d�}|��t�dd�|D��S)z;Sort suite_or_case while preserving non-vanilla TestSuites.)rOcSsg|]\}}|�qSrr)�.0�sort_keyrrrr�
<listcomp>�sz sorted_tests.<locals>.<listcomp>)rK�sortrrI)rNrOrPrrr�sorted_tests�srWccsL�zt|�}Wn
ty|VYdSw|D]}t|�D]}|VqqdS)z>Iterate through all of the test cases in 'test_suite_or_case'.N)rFrGrL)�test_suite_or_case�suiter�subtestrrrrL�s����rL�discoverTz7  -c, --catch      Catch control-C and display results
z=  -b, --buffer     Buffer stdout and stderr during test runs
a/Usage: %(progName)s [options] [tests]

Options:
  -h, --help       Show this message
  -v, --verbose    Verbose output
  -q, --quiet      Minimal output
  -l, --list       List tests rather than executing them.
  --load-list      Specifies a file containing test ids, only tests matching
                   those ids are executed.
%(catchbreak)s%(buffer)s
Examples:
  %(progName)s test_module               - run tests from test_module
  %(progName)s module.TestClass          - run tests from module.TestClass
  %(progName)s module.Class.test_method  - run specified test method

All options must come before [tests].  [tests] can be a list of any number of
test modules, classes and test methods.

Alternative Usage: %(progName)s discover [options]

Options:
  -v, --verbose    Verbose output
s%(catchbreak)s%(buffer)s  -s directory     Directory to start discovery ('.' default)
  -p pattern       Pattern to match test files ('test*.py' default)
  -t directory     Top level directory of project (default to
                   start directory)
  -l, --list       List tests rather than executing them.
  --load-list      Specifies a file containing test ids, only tests matching
                   those ids are executed.

For test discovery all test modules must be importable from the top
level directory of the project.
c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zd#d
d�Z	d#dd�Z
dd�Zd#dd�Zd#dd�Z
dd�Zdd�Zedd��Zdd�Zedd ��Zd!d"�ZdS)$�TestResultDecoratoraGeneral pass-through decorator.

    This provides a base that other TestResults can inherit from to
    gain basic forwarding functionality. It also takes care of
    handling the case where the target doesn't support newer methods
    or features by degrading them.
    cCs
||_dS)z5Create a TestResultDecorator forwarding to decorated.N)�	decorated�r	r]rrrr1s
zTestResultDecorator.__init__cC�|j�|�Sr)r]rrrrrr6�zTestResultDecorator.startTestcC�
|j��Sr)r]�startTestRun�r	rrrrb9�
z TestResultDecorator.startTestRuncCr_r)r]rrrrrr<r`zTestResultDecorator.stopTestcCrar)r]�stopTestRunrcrrrre?rdzTestResultDecorator.stopTestRunNcC�|j�||�Sr)r]�addError�r	rr,rrrrgB�zTestResultDecorator.addErrorcCrfr)r]�
addFailurerhrrrrjErizTestResultDecorator.addFailurecCr_r)r]rrrrrrHr`zTestResultDecorator.addSuccesscCrfr)r]�addSkip�r	r�reasonrrrrkKrizTestResultDecorator.addSkipcCrfr)r]�addExpectedFailurerhrrrrnNriz&TestResultDecorator.addExpectedFailurecCr_r)r]�addUnexpectedSuccessrrrrroQr`z(TestResultDecorator.addUnexpectedSuccesscCrar)r]�
wasSuccessfulrcrrrrpTrdz!TestResultDecorator.wasSuccessfulcC�|jjSr�r]�
shouldStoprcrrrrsW�zTestResultDecorator.shouldStopcCrar)r]�stoprcrrrru[rdzTestResultDecorator.stopcCrqr)r]�testsRunrcrrrrv^rtzTestResultDecorator.testsRuncCr_r)r]r?�r	r>rrrr?br`zTestResultDecorator.timer)r@rArBrCrrrbrrergrjrrkrnrorp�propertyrsrurvr?rrrrr\(s(





r\cs�eZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Zd!d
d�Z	d!dd�Z
dd�Zd!dd�Zd!dd�Z
dd�Zdd�Zedd��Zdd�Zdd �Z�ZS)"�HookedTestResultDecoratorz/A TestResult which calls a hook on every event.cstt|�|_|j�|�dSr)rryrr^rrrrisz"HookedTestResultDecorator.__init__cC�|��|j�|�Sr)�
_before_eventrrrrrrrm�z#HookedTestResultDecorator.startTestcC�|��|j��Sr)r{rrbrcrrrrbq�
z&HookedTestResultDecorator.startTestRuncCrzr)r{rrrrrrrur|z"HookedTestResultDecorator.stopTestcCr}r)r{rrercrrrreyr~z%HookedTestResultDecorator.stopTestRunNcC�|��|j�||�Sr)r{rrgrhrrrrg}�z"HookedTestResultDecorator.addErrorcCrr)r{rrjrhrrrrj�r�z$HookedTestResultDecorator.addFailurecCrzr)r{rrrrrrr�r|z$HookedTestResultDecorator.addSuccesscCrr)r{rrkrlrrrrk�r�z!HookedTestResultDecorator.addSkipcCrr)r{rrnrhrrrrn�r�z,HookedTestResultDecorator.addExpectedFailurecCrzr)r{rrorrrrro�r|z.HookedTestResultDecorator.addUnexpectedSuccesscCr}r)r{rrprcrrrrp�r~z'HookedTestResultDecorator.wasSuccessfulcCs|��|jjSr)r{rrsrcrrrrs�sz$HookedTestResultDecorator.shouldStopcCr}r)r{rrurcrrrru�r~zHookedTestResultDecorator.stopcCrzr)r{rr?rwrrrr?�r|zHookedTestResultDecorator.timer)r@rArBrCrrrbrrergrjrrkrnrorprxrsrur?rDrrrrryfs$




rycs<eZdZdZ�fdd�Zdd�Zedd��Zdd	�Z�Z	S)
�AutoTimingTestResultDecoratoraDecorate a TestResult to add time events to a test run.

    By default this will cause a time event before every test event,
    but if explicit time data is being provided by the test run, then
    this decorator will turn itself off to prevent causing confusion.
    csd|_tt|��|�dSr)�_timerr�rr^rrrr�sz&AutoTimingTestResultDecorator.__init__cCs8|j}|dur	dStj��jtjjd�}|j�|�dS)N)�tzinfo)r�r4�utcnow�replacer5r6r]r?)r	r?rrrr{�s
z+AutoTimingTestResultDecorator._before_eventcCrqrrrrcrrrrs�rtz(AutoTimingTestResultDecorator.shouldStopcCs||_|j�|�S)a\Provide a timestamp for the current test activity.

        :param a_datetime: If None, automatically add timestamps before every
            event (this is the default behaviour if time() is not called at
            all).  If not None, pass the provided time onto the decorated
            result object and disable automatic timestamps.
        )r�r]r?rwrrrr?�sz"AutoTimingTestResultDecorator.time)
r@rArBrCrr{rxrsr?rDrrrrr��s
r�c@seZdZddd�Zdd�ZdS)�SubunitTestRunnerNcCs|ptj|_dS)zhCreate a SubunitTestRunner.

        :param verbosity: Ignored.
        :param buffer: Ignored.
        N)�sys�stdoutr
)r	�	verbosity�bufferr
rrrr�szSubunitTestRunner.__init__cCst|j�}t|�}||�|S)z&Run the given test case or test suite.)rr
r�)r	rrQrrr�run�s
zSubunitTestRunner.run)NNN)r@rArBrr�rrrrr��s
r�c
@sleZdZdZeZdZZZeddde	dddddf
dd�Z
dd�Zd	d
�Ze
fdd�Zd
d�Zddd�ZdS)�TestProgramzA command-line program that runs a set of tests; this is primarily
       for making test modules conveniently executable.
    NTr/cCs�|tkrd|_n!t|t�r&t|�|_|�d�dd�D]	}t|j|�|_qn||_|dur0tj}|
dur7tj	}
|dur>t
�}||_||_||_
|	|_||_d|_d|_||_||_|d}|�dtjj�rt|�tjj�}
d|
d}ntj�|d�}||_|�|�|jr�t|jd�}z
|��}W|��n|��wtd	d
�|D��}t� �}t!|j"�D]
}|�#�|vr�|�$|�q�||_"|js�|�%�dSt!|j"�D]}|
�&d|�#��q�dS)N�.r/Frz%srun.pyz%s.run����rbcss�|]
}|���d�VqdS)zutf-8N)�strip�decode)rS�linerrr�	<genexpr>s�z'TestProgram.__init__.<locals>.<genexpr>z%s
)'r@�module�
isinstance�str�
__import__�splitrMr��argvr�r��exit�
catchbreakr�r��defaultTest�	listtests�	load_list�
testRunner�
testLoaderr�os�path�sep�basename�progName�	parseArgs�open�	readlines�close�setrrIrLrr�addTest�runTestsr)r	r�r�r�r�r�r�r�r�r�r��partr��elements�source�lines�test_idsr1rrrrr�s^

�


��zTestProgram.__init__cCsVt|�dkr|d��dkr|�|dd��dSddl}gd�}zu|�|dd�d|�\}}|D]@\}}|dvr=|��|dvrDd|_|d	vrKd|_|d
vrW|jdurWd|_|dvrc|jdurcd|_|d
vrjd|_|dkrq||_	q1t|�dkr�|j
dur�d|_nt|�dkr�||_n|j
f|_|��WdS|j
y�|�t��d�YdSw)Nr/r[�r)�help�verbose�quiet�catchr��listz
load-list=�hHvqfcbl)z-hz-Hz--help)z-qz--quiet)�-v�	--verbose)�-c�--catchT)�-b�--buffer)�-l�--list�--load-list)�len�lower�
_do_discovery�getopt�	usageExitr�r�r�r�r�r��	testNames�createTestsrr��exc_info)r	r�r��	long_opts�options�args�opt�valuerrrr�sD

�
�zTestProgram.parseArgscCs6|jdur|j�|j�|_dS|j�|j|j�|_dSr)r�r��loadTestsFromModuler�r�loadTestsFromNamesrcrrrr�Gs



�zTestProgram.createTestscCs�tstd��d|j|_ddl}|��}|j|_|jdddddd	d
�|jdkr3|jddd
ddd	d
�|jdkrC|jdddddd	d
�|jdddddd�|jdddddd�|jddd dd!d�|jd"d#d$dd	d%d&�|jd'd(dd)d�|�	|�\}}t
|�d*kr�|��td+|�D]
\}}t
|||�q�|jdur�|j|_|jdur�|j|_|j|_|j|_|jr�d,|_|j}	|j}
|j}|�}|�|	|
|�}
t|
�|_dS)-NzYUnable to use discovery, must use python 2.7 or greater, or install the discover package.z%s discoverrr�r�r�FzVerbose output�
store_true)�dest�defaultr��actionr�r�r�z'Catch ctrl-C and display results so farr�r�r�z%Buffer stdout and stderr during testsz-sz--start-directory�startr�z*Directory to start discovery ('.' default))r�r�r�z-pz	--pattern�patternztest*.pyz+Pattern to match tests ('test*.py' default)z-tz--top-level-directory�topz<Top level directory of project (defaults to start directory)r�r�r�z$List tests rather than running them.)r�r�r�r�r�r�z2Specify a filename containing the test ids to use.�)r�r�r�r�)�
have_discover�AssertionErrorr��optparse�OptionParser�prog�
add_optionr�r��
parse_argsr�r��zip�setattrr�r�r�r�r�r�r�r[rWr)r	r��Loaderr��parserr�r��namer��	start_dirr��
top_level_dir�loader�loadedrrrr�Nsj�
�
�����
�


zTestProgram._do_discoverycCsN|jrttdd�durt��|j�|j�|_|jr%t	�|j�
��dSdS)N�installHandler)r�rMrr�r�r�rrQr�r�rprcrrrr��s�zTestProgram.runTestscCs�|rt|�|jddd�}|jdkrt|d<|jdkrt|d<|j|}|�d�}|�dd�|�d	d�td�	|��t
�d�dS)
N�)r�r�r�Fr�r�r
r�z)Run a test suite with a subunit reporter.r�)�printr�r��
CATCHBREAKr��BUFFEROUTPUT�USAGEr��insert�joinr�r�)r	�msg�usage�
usage_text�usage_linesrrrr��s�



zTestProgram.usageExitr)r@rArBrC�
USAGE_AS_MAINr�r�r�r��defaultTestLoaderrr�r��defaultTestLoaderClsr�r�r�rrrrr��s
�:(Br��__main__)r�r�r�)F)rCr4r�r�rrrrKrWrLr��
TestLoaderr�rMr[�DiscoveringTestLoaderr��ImportErrorr�r�r��objectr\ryr�r�r�r@r�r�rrrr�<module>sD

�&>A#N�