U
    
W[É  ã                   @   sh   d Z ddlmZmZ ddlZddlmZ ddlmZ ddl	m
Z
 G dd„ deƒZG d	d
„ d
eejƒZdS )z2
Tests for warning suppression features of Trial.
é    )ÚdivisionÚabsolute_importN)ÚnamedAny)Úunittest)Úsuppressionc                   @   sX   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ ZdS )ÚSuppressionMixinzj
    Tests for the warning suppression features of
    L{twisted.trial.unittest.SynchronousTestCase}.
    c                 C   s   |  t ¡ ¡ d S )N)ÚrunÚpyunitZ
TestResult)ÚselfZsuite© r   úE/usr/lib/python3/dist-packages/twisted/trial/test/test_suppression.pyÚrunTests   s    zSuppressionMixin.runTestsc                 C   s   t  ||ƒg¡S )zÞ
        Return a new L{unittest.TestSuite} with a single test method in it.

        @param cls: A L{TestCase} subclass defining a test method.

        @param methodName: The name of the test method from C{cls}.
        )r	   Z	TestSuite)r
   ÚclsZ
methodNamer   r   r   Ú_load   s    zSuppressionMixin._loadc                 C   s   |   dd„ |D ƒ|¡ dS )a&  
        Assert that a certain number of warnings with certain messages were
        emitted in a certain order.

        @param warnings: A list of emitted warnings, as returned by
            C{flushWarnings}.

        @param which: A list of strings giving warning messages that should
            appear in C{warnings}.

        @raise self.failureException: If the warning messages given by C{which}
            do not match the messages in the warning information in C{warnings},
            or if they do not appear in the same order.
        c                 S   s   g | ]}|d  ‘qS )Úmessager   )Ú.0Zwarningr   r   r   Ú
<listcomp>5   s     z4SuppressionMixin._assertWarnings.<locals>.<listcomp>N)ÚassertEqual)r
   ÚwarningsZwhichr   r   r   Ú_assertWarnings%   s    þz SuppressionMixin._assertWarningsc                 C   sD   |   |  | jd¡¡ |  | jjg¡}|  |tjtjtjtjg¡ dS )z“
        Suppressions defined by the test method being run are applied to any
        warnings emitted while running the C{setUp} fixture.
        ÚtestSuppressMethodN)	r   r   ÚTestSetUpSuppressionÚflushWarningsÚ_emitr   r   ÚCLASS_WARNING_MSGÚMODULE_WARNING_MSG©r
   ZwarningsShownr   r   r   Útest_setUpSuppression9   s    ÿÿ ÿþz&SuppressionMixin.test_setUpSuppressionc                 C   sD   |   |  | jd¡¡ |  | jjg¡}|  |tjtjtjtjg¡ dS )z–
        Suppressions defined by the test method being run are applied to any
        warnings emitted while running the C{tearDown} fixture.
        r   N)	r   r   ÚTestTearDownSuppressionr   r   r   r   r   r   r   r   r   r   Útest_tearDownSuppressionH   s    ÿÿ ÿþz)SuppressionMixin.test_tearDownSuppressionc                 C   s<   |   |  | jd¡¡ |  | jjg¡}|  |tjtjg¡ dS )zœ
        A suppression set on a test method prevents warnings emitted by that
        test method which the suppression matches from being emitted.
        r   N)	r   r   ÚTestSuppressionr   r   r   r   r   r   r   r   r   r   Útest_suppressMethodW   s    ÿÿ
þz$SuppressionMixin.test_suppressMethodc                 C   sd   |   |  | jd¡¡ |  | jjg¡}|  |d d tj¡ |  |d d tj¡ |  t	|ƒd¡ dS )zÌ
        A suppression set on a L{SynchronousTestCase} subclass prevents warnings
        emitted by any test methods defined on that class which match the
        suppression from being emitted.
        ZtestSuppressClassr   r   é   é   N)
r   r   r    r   r   r   r   ÚMETHOD_WARNING_MSGr   Úlenr   r   r   r   Útest_suppressClasse   s    ÿÿ
 ÿ
 ÿz#SuppressionMixin.test_suppressClassc                 C   sd   |   |  | jd¡¡ |  | jjg¡}|  |d d tj¡ |  |d d tj	¡ |  t
|ƒd¡ dS )zµ
        A suppression set on a module prevents warnings emitted by any test
        mewthods defined in that module which match the suppression from being
        emitted.
        ZtestSuppressModuler   r   r"   r#   N)r   r   ÚTestSuppression2r   r    r   r   r   r$   r   r%   r   r   r   r   Útest_suppressModulev   s    ÿÿ
 ÿ
 ÿz$SuppressionMixin.test_suppressModulec                 C   sz   |   |  | jd¡¡ |  | jjg¡}|  |d d tj¡ |  |d d tj¡ |  |d d tj	¡ |  t
|ƒd¡ dS )zô
        The suppression set on a test method completely overrides a suppression
        with wider scope; if it does not match a warning emitted by that test
        method, the warning is emitted, even if a wider suppression matches.
        ZtestOverrideSuppressClassr   r   r"   r#   é   N)r   r   r    r   r   r   r   r$   r   r   r%   r   r   r   r   Útest_overrideSuppressClass‡   s&    ÿÿ
 ÿ
 ÿ
 ÿz+SuppressionMixin.test_overrideSuppressClassN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r!   r&   r(   r*   r   r   r   r   r      s   r   c                   @   s0   e Zd ZdZedƒZedƒZedƒZedƒZdS )ÚSynchronousSuppressionTestsz0
    @see: L{twisted.trial.test.test_tests}
    z>twisted.trial.test.suppression.SynchronousTestSetUpSuppressionzAtwisted.trial.test.suppression.SynchronousTestTearDownSuppressionz9twisted.trial.test.suppression.SynchronousTestSuppressionz:twisted.trial.test.suppression.SynchronousTestSuppression2N)	r+   r,   r-   r.   r   r   r   r    r'   r   r   r   r   r/   ›   s   ÿÿÿÿr/   )r.   Z
__future__r   r   r   r	   Ztwisted.python.reflectr   Ztwisted.trialZtwisted.trial.testr   Úobjectr   ZSynchronousTestCaser/   r   r   r   r   Ú<module>   s    