AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python3/dist-packages/twisted/trial/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /usr/lib/python3/dist-packages/twisted/trial/test/__pycache__/test_util.cpython-310.pyc
o

�b�L�@sdZddlZddlZddlmZddlmZddlmZddl	m
Z
ddlmZddl
mZdd	lmZdd
lmZddlmZmZmZmZGdd
�d
e�ZGdd�de�ZGdd�d�ZGdd�d�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�Z dS)z!
Tests for L{twisted.trial.util}
�N)�StringIO)�implementer)�DelayedCall)�IProcessTransport)�filepath)�Failure)�util)�SynchronousTestCase)�DirtyReactorAggregateError�_Janitor�acquireAttribute�excInfoOrFailureToExcInfoc@�0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�MktempTestszm
    Tests for L{TestCase.mktemp}, a helper function for creating temporary file
    or directory names.
    cCs8|��}tj�|��tj�dd�}|�|gd��dS)z�
        The path name returned by C{mktemp} is directly beneath a directory
        which identifies the test method which created the name.
        N���)ztwisted.trial.test.test_utilr�	test_name)�mktemp�os�path�dirname�split�sep�assertEqual)�self�name�dirs�r�>/usr/lib/python3/dist-packages/twisted/trial/test/test_util.pyr$s
�zMktempTests.test_namecCs|��}|�||���dS)zF
        Repeated calls to C{mktemp} return different values.
        N)r�assertNotEqual)rrrrr�test_unique/szMktempTests.test_uniquecCs<|��}tj�|�}|�tj�|��|�tj�|��dS)zS
        The directory part of the path name returned by C{mktemp} exists.
        N)rrrr�
assertTrue�exists�assertFalse)rrrrrr�test_created6szMktempTests.test_createdcCs(tj�|���}|�|�t����dS)zZ
        The path returned by C{mktemp} is beneath the current working directory.
        N)rr�abspathrr �
startswith�getcwd)rrrrr�
test_location?szMktempTests.test_locationN)�__name__�
__module__�__qualname__�__doc__rrr#r'rrrrrs	rc@�(eZdZdZdd�Zdd�Zdd�ZdS)	�DirtyReactorAggregateErrorTestsz6
    Tests for the L{DirtyReactorAggregateError}.
    cCs tddg�}|�t|�d�dS)z5
        Delayed calls are formatted nicely.
        �Foo�barzhReactor was unclean.
DelayedCalls: (set twisted.internet.base.DelayedCall.debug = True to debug)
Foo
barN�r
r�str�r�errorrrr�test_formatDelayedCallLs
�z6DirtyReactorAggregateErrorTests.test_formatDelayedCallcCs"tgddg�}|�t|�d�dS)z3
        Selectables are formatted nicely.
        zselectable 1zselectable 2z;Reactor was unclean.
Selectables:
selectable 1
selectable 2Nr0r2rrr�test_formatSelectablesZs
�z6DirtyReactorAggregateErrorTests.test_formatSelectablescCs&tddgddg�}|�t|�d�dS)zR
        Both delayed calls and selectables can appear in the same error.
        �bleck�Boozo�Sel1�Sel2z�Reactor was unclean.
DelayedCalls: (set twisted.internet.base.DelayedCall.debug = True to debug)
bleck
Boozo
Selectables:
Sel1
Sel2Nr0r2rrr�%test_formatDelayedCallsAndSelectableshs
�zEDirtyReactorAggregateErrorTests.test_formatDelayedCallsAndSelectablesN)r(r)r*r+r4r5r:rrrrr-Gs
r-c@s4eZdZdZddd�Zddd�Zdd�Zd	d
�ZdS)�StubReactora~
    A reactor stub which contains enough functionality to be used with the
    L{_Janitor}.

    @ivar iterations: A list of the arguments passed to L{iterate}.
    @ivar removeAllCalled: Number of times that L{removeAll} was called.
    @ivar selectables: The value that will be returned from L{removeAll}.
    @ivar delayedCalls: The value to return from L{getDelayedCalls}.
    NcCs$||_g|_d|_|s
g}||_dS)z�
        @param delayedCalls: See L{StubReactor.delayedCalls}.
        @param selectables: See L{StubReactor.selectables}.
        rN)�delayedCalls�
iterations�removeAllCalled�selectables)rr<r?rrr�__init__�s
zStubReactor.__init__cC�|j�|�dS)z/
        Increment C{self.iterations}.
        N)r=�append)r�timeoutrrr�iterate��zStubReactor.iteratecCs|jS)z.
        Return C{self.delayedCalls}.
        )r<�rrrr�getDelayedCalls�szStubReactor.getDelayedCallscCs|jd7_|jS)zS
        Increment C{self.removeAllCalled} and return C{self.selectables}.
        �)r>r?rFrrr�	removeAll�szStubReactor.removeAll�N)r(r)r*r+r@rDrGrIrrrrr;zs


r;c@� eZdZdZdd�Zdd�ZdS)�StubErrorReporterz�
    A subset of L{twisted.trial.itrial.IReporter} which records L{addError}
    calls.

    @ivar errors: List of two-tuples of (test, error) which were passed to
        L{addError}.
    cC�
g|_dSrJ)�errorsrFrrrr@��
zStubErrorReporter.__init__cCs|j�||f�dS)z6
        Record parameters in C{self.errors}.
        N)rNrB)r�testr3rrr�addError�szStubErrorReporter.addErrorN)r(r)r*r+r@rQrrrrrL�srLc@sheZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�JanitorTestsz 
    Tests for L{_Janitor}!
    cCs4tg�}tdd|d�}|��|�|jddg�dS)a
        During pending-call cleanup, the reactor will be spun twice with an
        instant timeout. This is not a requirement, it is only a test for
        current behavior. Hopefully Trial will eventually not do this kind of
        reactor stuff.
        N��reactorr)r;r�
_cleanPendingrr=�rrT�janrrr�test_cleanPendingSpinsReactor�sz*JanitorTests.test_cleanPendingSpinsReactorcCsVdd�}g}td|di|jdd��}t|g�}tdd|d�}|��|�||g�dS)	zW
        During pending-call cleanup, the janitor cancels pending timed calls.
        cS�dS)N�Lulzrrrrr�func��z8JanitorTests.test_cleanPendingCancelsCalls.<locals>.func�,rcS�dSrJr��xrrr�<lambda>��z<JanitorTests.test_cleanPendingCancelsCalls.<locals>.<lambda>NrS)rrBr;rrUr)rr[�	cancelled�delayedCallrTrWrrr�test_cleanPendingCancelsCalls�s
z*JanitorTests.test_cleanPendingCancelsCallsc	Cs`tddd�didd�dd�dd�d�}t|�}t|g�}tdd|d	�}|��}|�||g�dS)
aK
        The Janitor produces string representations of delayed calls from the
        delayed call cleanup method. It gets the string representations
        *before* cancelling the calls; this is important because cancelling the
        call removes critical debugging information from the string
        representation.
        r]cSr^rJrrrrrra�rbzIJanitorTests.test_cleanPendingReturnsDelayedCallStrings.<locals>.<lambda>rcSr^rJrr_rrrra�rbcSrY�Nrrrrrrra�rb��secondsNrS)rr1r;rrUr)rrd�delayedCallStringrTrW�stringsrrr�*test_cleanPendingReturnsDelayedCallStrings�s�
z7JanitorTests.test_cleanPendingReturnsDelayedCallStringscCs0tg�}tdd|d�}|��|�|jd�dS)zM
        The Janitor will remove selectables during reactor cleanup.
        NrSrH)r;r�
_cleanReactorrr>rVrrr�#test_cleanReactorRemovesSelectables�sz0JanitorTests.test_cleanReactorRemovesSelectablescCsRtt�Gdd�d��}|�}tg|g�}tdd|d�}|��|�|jdg�dS)zI
        The Janitor will kill processes during reactor cleanup.
        c@rK)zJJanitorTests.test_cleanReactorKillsProcesses.<locals>.StubProcessTransportz�
            A stub L{IProcessTransport} provider which records signals.
            @ivar signals: The signals passed to L{signalProcess}.
            cSrMrJ)�signalsrFrrrr@�rOzSJanitorTests.test_cleanReactorKillsProcesses.<locals>.StubProcessTransport.__init__cSrA)zF
                Append C{signal} to C{self.signals}.
                N)rnrB)r�signalrrr�
signalProcessrEzXJanitorTests.test_cleanReactorKillsProcesses.<locals>.StubProcessTransport.signalProcessN)r(r)r*r+r@rprrrr�StubProcessTransport�srqNrS�KILL)rrr;rrlrrn)rrq�ptrTrWrrr�test_cleanReactorKillsProcesses�sz,JanitorTests.test_cleanReactorKillsProcessescCs@Gdd�d�}tg|�g�}tdd|d�}|�|��dg�dS)z�
        The Janitor returns string representations of the selectables that it
        cleaned up from the reactor cleanup method.
        c@seZdZdZdefdd�ZdS)zJJanitorTests.test_cleanReactorReturnsSelectableStrings.<locals>.Selectablezl
            A stub Selectable which only has an interesting string
            representation.
            �returncSrY)N�
(SELECTABLE!)rrFrrr�__repr__r\zSJanitorTests.test_cleanReactorReturnsSelectableStrings.<locals>.Selectable.__repr__N)r(r)r*r+r1rwrrrr�
SelectablesrxNrSrv)r;rrrl)rrxrTrWrrr�)test_cleanReactorReturnsSelectableStrings
s	z6JanitorTests.test_cleanReactorReturnsSelectableStringscCsBtg�}t�}t�}t|||d�}|�|���|�|jg�dS)z�
        The post-case cleanup method will return True and not call C{addError}
        on the result if there are no pending calls.
        rSN)r;�objectrLrr �postCaseCleanuprrN�rrTrP�reporterrWrrr�test_postCaseCleanupNoErrors sz)JanitorTests.test_postCaseCleanupNoErrorsc	Cs�tddd�didd�dd�dd�d�}t|�}t|gg�}t�}t�}t|||d�}|�|���|�t	|j
�d	�|�|j
d
d	jj|g�dS)z�
        The post-case cleanup method will return False and call C{addError} on
        the result with a L{DirtyReactorAggregateError} Failure if there are
        pending calls.
        r]cSr^rJrrrrrra3rbz=JanitorTests.test_postCaseCleanupWithErrors.<locals>.<lambda>rcSr^rJrr_rrrra3rbcSrYrfrrrrrra3rbrgrSrHrN)
rr1r;rzrLrr"r{r�lenrN�valuer<�rrdrirTrPr}rWrrr�test_postCaseCleanupWithErrors,s� z+JanitorTests.test_postCaseCleanupWithErrorscCs<tg�}t�}t�}t|||d�}|��|�|jg�dS)z�
        The post-class cleanup method will not call C{addError} on the result
        if there are no pending calls or selectables.
        rSN)r;rzrLr�postClassCleanuprrNr|rrr�test_postClassCleanupNoErrors>sz*JanitorTests.test_postClassCleanupNoErrorsc	Cs�tddd�didd�dd�dd�d�}t|�}t|gg�}t�}t�}t|||d�}|��|�t|j	�d	�|�|j	d
d	j
j|g�dS)z�
        The post-class cleanup method call C{addError} on the result with a
        L{DirtyReactorAggregateError} Failure if there are pending calls.
        r]cSr^rJrrrrrraPrbzIJanitorTests.test_postClassCleanupWithPendingCallErrors.<locals>.<lambda>rcSr^rJrr_rrrraPrbcSrYrfrrrrrraPrbrgrSrHrN)rr1r;rzrLrr�rrrNr�r<r�rrr�*test_postClassCleanupWithPendingCallErrorsJs� z7JanitorTests.test_postClassCleanupWithPendingCallErrorscCshd}tg|g�}t�}t�}t|||d�}|��|�t|j�d�|�|jddjj	t
|�g�dS)z�
        The post-class cleanup method call C{addError} on the result with a
        L{DirtyReactorAggregateError} Failure if there are selectables.
        zSELECTABLE HERErSrHrN)r;rzrLrr�rrrNr�r?�repr)r�
selectablerTrPr}rWrrr�)test_postClassCleanupWithSelectableErrors[s$z6JanitorTests.test_postClassCleanupWithSelectableErrorsN)r(r)r*r+rXrerkrmrtryr~r�r�r�r�rrrrrR�s	rRc@r,)	�RemoveSafelyTestsz*
    Tests for L{util._removeSafely}.
    cCs8|���d�}t�|�t�|�}|�tjtj	|�dS)z�
        If a path doesn't contain a node named C{"_trial_marker"}, that path is
        not removed by L{util._removeSafely} and a L{util._NoTrialMarker}
        exception is raised instead.
        �utf-8N)
r�encoder�mkdirr�FilePath�assertRaisesr�_NoTrialMarker�
_removeSafely)r�	directory�dirPathrrr�test_removeSafelyNoTrialMarkeros

z0RemoveSafelyTests.test_removeSafelyNoTrialMarkercCspdd�}t�}|�td|�|���d�}t�|�t�|�}|�	d��
�||_t�
|�|�d|���dS)z�
        If an L{OSError} is raised while removing a path in
        L{util._removeSafely}, an attempt is made to move the path to a new
        name.
        cSst��)��
            Raise an C{OSError} to emulate the branch of L{util._removeSafely}
            in which path removal fails.
            ��OSErrorrrrr�dummyRemove�szORemoveSafelyTests.test_removeSafelyRemoveFailsMoveSucceeds.<locals>.dummyRemove�stdoutr��
_trial_marker�could not remove FilePathN)r�patch�sysrr�rr�rr��child�touch�removerr��assertIn�getvalue)rr��outr�r�rrr�(test_removeSafelyRemoveFailsMoveSucceedszs


z:RemoveSafelyTests.test_removeSafelyRemoveFailsMoveSucceedscCs�dd�}dd�}t�}|�td|�|���d�}t�|�t�|�}|�	d��
�||_||_|�
ttj|�}|�t|�d�|�d	|���d
S)z�
        If an L{OSError} is raised while removing a path in
        L{util._removeSafely}, an attempt is made to move the path to a new
        name. If that attempt fails, the L{OSError} is re-raised.
        cS�td��)r�zpath removal failedr�rrrrr���zLRemoveSafelyTests.test_removeSafelyRemoveFailsMoveFails.<locals>.dummyRemovecSr�)z�
            Raise an C{OSError} to emulate the branch of L{util._removeSafely}
            in which path movement fails.
            �path movement failedr�)rrrr�dummyMoveTo�r�zLRemoveSafelyTests.test_removeSafelyRemoveFailsMoveFails.<locals>.dummyMoveTor�r�r�r�r�N)rr�r�rr�rr�rr�r�r�r��moveTor�r�rr�rr1r�r�)rr�r�r�r�r�r3rrr�%test_removeSafelyRemoveFailsMoveFails�s

z7RemoveSafelyTests.test_removeSafelyRemoveFailsMoveFailsN)r(r)r*r+r�r�r�rrrrr�js
r�c@rK)�ExcInfoTestsz1
    Tests for L{excInfoOrFailureToExcInfo}.
    cCs$ttd�df}|�|t|�u�dS)z�
        L{excInfoOrFailureToExcInfo} returns exactly what it is passed, if it is
        passed a tuple like the one returned by L{sys.exc_info}.
        �fooN)�
ValueErrorr r
)r�inforrr�test_excInfo�szExcInfoTests.test_excInfocCsFzddWntyt�}Ynw|�|j|j|jft|��dS)z�
        When called with a L{Failure} instance, L{excInfoOrFailureToExcInfo}
        returns a tuple like the one returned by L{sys.exc_info}, with the
        elements taken from the type, value, and traceback of the failure.
        rHrN)�
BaseExceptionrr�typer��tbr
)r�frrr�test_failure�s
� zExcInfoTests.test_failureN)r(r)r*r+r�r�rrrrr��sr�c@r)�AcquireAttributeTestsz(
    Tests for L{acquireAttribute}.
    cCs*t�|_}|�|t|t�gd�u�dS)z�
        The value returned by L{acquireAttribute} is the value of the requested
        attribute on the first object in the list passed in which has that
        attribute.
        r�N�rzr�r r�rr�rrr�test_foundOnEarlierObject�sz/AcquireAttributeTests.test_foundOnEarlierObjectcCs*t�|_}|�|tt�|gd�u�dS)z�
        The same as L{test_foundOnEarlierObject}, but for the case where the 2nd
        element in the object list has the attribute and the first does not.
        r�Nr�r�rrr�test_foundOnLaterObject�sz-AcquireAttributeTests.test_foundOnLaterObjectcCs|�ttt�gd�dS)z�
        If none of the objects passed in the list to L{acquireAttribute} have
        the requested attribute, L{AttributeError} is raised.
        r�N)r��AttributeErrorrrzrFrrr�test_notFoundException�sz,AcquireAttributeTests.test_notFoundExceptioncCs$t�}|�|tt�gd|�u�dS)z�
        If none of the objects passed in the list to L{acquireAttribute} have
        the requested attribute and a default value is given, the default value
        is returned.
        r�N)rzr r)r�defaultrrr�test_notFoundDefault�sz*AcquireAttributeTests.test_notFoundDefaultN)r(r)r*r+r�r�r�r�rrrrr��s	r�c@sXeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�ZdS)�ListToPhraseTestsz�
    Input is transformed into a string representation of the list,
    with each item separated by delimiter (defaulting to a comma) and the final
    two being separated by a final delimiter.
    cCs$g}d}t�|d�}|�||�dS)zB
        If things is empty, an empty string is returned.
        ��andN�r�
_listToPhraser�r�sample�expected�resultrrr�
test_emptyszListToPhraseTests.test_emptycCs&dg}d}t�|d�}|�||�dS)z;
        With a single item, the item is returned.
        �Oner�Nr�r�rrr�test_oneWordszListToPhraseTests.test_oneWordcCs(ddg}d}t�|d�}|�||�dS)zA
        Two words are separated by the final delimiter.
        r��TwozOne and Twor�Nr�r�rrr�
test_twoWords�zListToPhraseTests.test_twoWordscC�(gd�}d}t�|d�}|�||�dS)zY
        With more than two words, the first two are separated by the delimiter.
        )r�r��ThreezOne, Two, and Threer�Nr�r�rrr�test_threeWords"r�z!ListToPhraseTests.test_threeWordscCs,gd�}d}tj|ddd�}|�||�dS)zW
        If a delimiter is specified, it is used instead of the default comma.
        )r�r�r��FourzOne; Two; Three; or Four�orz; )�	delimiterNr�r�rrr�test_fourWords+sz ListToPhraseTests.test_fourWordscCr�)zS
        If something in things is not a string, it is converted into one.
        )rH��threez1, 2, and threer�Nr�r�rrr�test_notString4r�z ListToPhraseTests.test_notStringcCs*d}|�ttj|d�}|�t|�d�dS)z?
        If things is a string, a TypeError is raised.
        zOne, two, threer�� Things must be a list or a tupleN�r��	TypeErrorrr�rr1�rr�r3rrr�test_stringTypeError=sz&ListToPhraseTests.test_stringTypeErrorcCs2tgd��}|�ttj|d�}|�t|�d�dS)zB
        If things is an iterator, a TypeError is raised.
        )rHr��r�r�N)�iterr�r�rr�rr1r�rrr�test_iteratorTypeErrorEsz(ListToPhraseTests.test_iteratorTypeErrorcCs.dd�}|�ttj|d�}|�t|�d�dS)zB
        If things is a generator, a TypeError is raised.
        css�td�EdHdS)Nr�)�rangerrrrr�Rs�z9ListToPhraseTests.test_generatorTypeError.<locals>.sampler�r�Nr�r�rrr�test_generatorTypeErrorMsz)ListToPhraseTests.test_generatorTypeErrorN)
r(r)r*r+r�r�r�r�r�r�r�r�r�rrrrr�s						r�)!r+rr��ior�zope.interfacer�twisted.internet.baser�twisted.internet.interfacesr�twisted.pythonr�twisted.python.failurer�
twisted.trialr�twisted.trial.unittestr	�twisted.trial.utilr
rrr
rr-r;rLrRr�r�r�r�rrrr�<module>s,)3+3U'

Anon7 - 2022
AnonSec Team