o
    ¯b,  ã                   @   s  d Z ddlZddlZddlZddlmZ ddlmZ ddl	m
Z
mZ ddlmZ G dd„ dejƒZee
jƒG d	d
„ d
e e
jd¡ƒƒZdd„ Zdd„ ZG dd„ deƒZG dd„ deƒZG dd„ deƒZe eeje
j¡ e eeje
j¡ eeddƒZer…e eee
j¡ dd„ ZdS )z-
Infrastructure for test running and suites.
é    N)Úimplementer)Ú
components)ÚitrialÚreporter)Ú_logObserverc                   @   ó   e Zd ZdZdd„ ZdS )Ú	TestSuitezh
    Extend the standard library's C{TestSuite} with a consistently overrideable
    C{run} method.
    c                 C   s$   | j D ]}|jr |S ||ƒ q|S )z;
        Call C{run} on every member of the suite.
        )Ú_testsÚ
shouldStop)ÚselfÚresultÚtest© r   ú</usr/lib/python3/dist-packages/twisted/trial/_asyncrunner.pyÚrun   s   

ÿzTestSuite.runN©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r      ó    r   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚTestDecoratorz—
    Decorator for test cases.

    @param _originalTest: The wrapped instance of test.
    @type _originalTest: A provider of L{itrial.ITestCase}
    c                 C   s
   |   |¡S ©zQ
        Run the unit test.

        @param result: A TestResult object.
        )r   ©r   r   r   r   r   Ú__call__3   s   
zTestDecorator.__call__c                 C   s   | j  t || j¡¡S r   )Ú_originalTestr   r   Ú_AdaptedReporterÚ	__class__r   r   r   r   r   ;   s   zTestDecorator.runN)r   r   r   r   r   r   r   r   r   r   r   &   s    r   r   c                 C   s
   g | _ dS )zÕ
    Clear all tests from C{suite}.

    This messes with the internals of C{suite}. In particular, it assumes that
    the suite keeps all of its tests in a list in an instance variable called
    C{_tests}.
    N)r	   )Úsuiter   r   r   Ú_clearSuiteD   s   
r   c                 C   sN   zt | ƒ}W n ty   || ƒ Y S w t| ƒ |D ]
}|  t||ƒ¡ q| S )a2  
    Decorate all test cases in C{test} with C{decorator}.

    C{test} can be a test case or a test suite. If it is a test suite, then the
    structure of the suite is preserved.

    L{decorate} tries to preserve the class of the test suites it finds, but
    assumes the presence of the C{_tests} attribute on the suite.

    @param test: The C{TestCase} or C{TestSuite} to decorate.

    @param decorator: A unary callable used to decorate C{TestCase}s.

    @return: A decorated C{TestCase} or a C{TestSuite} containing decorated
        C{TestCase}s.
    )ÚiterÚ	TypeErrorr   ÚaddTestÚdecorate)r   Ú	decoratorÚtestsÚcaser   r   r   r#   O   s   ÿr#   c                   @   s   e Zd ZdZdS )Ú_PyUnitTestCaseAdapterz2
    Adapt from pyunit.TestCase to ITestCase.
    N)r   r   r   r   r   r   r   r   r'   n   s    r'   c                   @   r   )Ú_BrokenIDTestCaseAdapterz£
    Adapter for pyunit-style C{TestCase} subclasses that have undesirable id()
    methods. That is C{unittest.FunctionTestCase} and C{unittest.DocTestCase}.
    c                 C   s    | j  ¡ }|dur|S | j  ¡ S )zH
        Return the fully-qualified Python name of the doctest.
        N)r   ÚshortDescriptionÚid)r   ÚtestIDr   r   r   r*   z   s   

z_BrokenIDTestCaseAdapter.idN)r   r   r   r   r*   r   r   r   r   r(   t   r   r(   c                   @   r   )Ú _ForceGarbageCollectionDecoratorzª
    Forces garbage collection to be run before and after the test. Any errors
    logged during the post-test collection are added to the test result as
    errors.
    c                 C   sR   t  ¡  t | |¡ t ¡  t  ¡  t ¡ D ]}| | |¡ qt ¡  t 	¡  d S )N)
ÚgcÚcollectr   r   r   Ú_addÚ	getErrorsÚaddErrorÚflushErrorsÚ_remove)r   r   Úerrorr   r   r   r   ‹   s   z$_ForceGarbageCollectionDecorator.runNr   r   r   r   r   r,   „   s    r,   ÚDocTestCasec                 c   sF   � zt | ƒ}W n ty   | V  Y dS w |D ]	}t|ƒE dH  qdS )zF
    Iterate through all of the test cases in C{testSuiteOrCase}.
    N)r    r!   Ú_iterateTests)ÚtestSuiteOrCaser   r   r   r   r   r6   £   s   €ÿÿr6   )r   Údoctestr-   ÚunittestÚpyunitÚzope.interfacer   Útwisted.pythonr   Útwisted.trialr   r   Útwisted.trial._synctestr   r   Ú	ITestCaseÚproxyForInterfacer   r   r#   r'   r(   r,   ÚregisterAdapterÚTestCaseÚFunctionTestCaseÚgetattrÚ_docTestCaser6   r   r   r   r   Ú<module>   s8   
ÿÿ
ÿ