U
    
W[                     @   s(  d Z ddlmZmZ ddlZddlZddlmZ ddlm	Z	m
Z
 ddlmZ ed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.
    )divisionabsolute_importN)
components)itrialreporter)_logObserverZunittest)implementerc                   @   s   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 q|| q|S )z;
        Call C{run} on every member of the suite.
        )_testsZ
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	      s   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__5   s    zTestDecorator.__call__c                 C   s   | j t|| jS r   )_originalTestr   r   Z_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   _clearSuiteI   s    r   c                 C   sP   zt | }W n tk
r(   ||  Y S X t|  |D ]}| t|| q6| 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   ZaddTestdecorate)r   Z	decoratorZtestsZcaser   r   r   r    U   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!   u   s   r!   c                   @   s   e Zd ZdZdd ZdS )_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k	r|S | j  S )zH
        Return the fully-qualified Python name of the doctest.
        N)r   ZshortDescriptionid)r   ZtestIDr   r   r   r#      s    
z_BrokenIDTestCaseAdapter.idN)r   r   r   r   r#   r   r   r   r   r"   |   s   r"   c                   @   s   e Zd ZdZdd ZdS ) _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)
gcZcollectr   r   r   Z_addZ	getErrorsZaddErrorZflushErrors_remove)r   r   errorr   r   r   r      s    z$_ForceGarbageCollectionDecorator.runNr   r   r   r   r   r$      s   r$   ZDocTestCasec                 c   sJ   zt | }W n tk
r&   | V  Y n X |D ]}t|D ]
}|V  q8q,dS )zF
    Iterate through all of the test cases in C{testSuiteOrCase}.
    N)r   r   _iterateTests)ZtestSuiteOrCaser   r   Zsubtestr   r   r   r(      s    r(   ) r   Z
__future__r   r   Zdoctestr%   Ztwisted.pythonr   Ztwisted.trialr   r   Ztwisted.trial._synctestr   
__import__ZpyunitZzope.interfacer   r	   Z	ITestCaseZproxyForInterfacer   r   r    r!   r"   r$   ZregisterAdapterZTestCaseZFunctionTestCasegetattrZ_docTestCaser(   r   r   r   r   <module>   sH          