o
    ¯b  ã                   @   sV   d Z ddlZddlmZ ddlmZ ddlmZ G dd„ dƒZG dd	„ d	eej	ƒZ
dS )
z2
Tests for warning suppression features of Trial.
é    N)Ú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ÚpyunitÚ
TestResult)ÚselfÚ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   Ú	TestSuite)r	   ÚclsÚ
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   )Ú.0Úwarningr   r   r   Ú
<listcomp>2   s    z4SuppressionMixin._assertWarnings.<locals>.<listcomp>N)ÚassertEqual)r	   ÚwarningsÚwhichr   r   r   Ú_assertWarnings#   s   z SuppressionMixin._assertWarningsc                 C   óD   |   |  | 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	   ÚwarningsShownr   r   r   Útest_setUpSuppression4   ó   üþz&SuppressionMixin.test_setUpSuppressionc                 C   r   )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_tearDownSuppressionE   r$   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_suppressMethodV   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.
        ÚtestSuppressClassr   r   é   é   N)
r   r   r'   r   r   r   r   ÚMETHOD_WARNING_MSGr    Úlenr!   r   r   r   Útest_suppressClassb   ó
   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.
        ÚtestSuppressModuler   r   r*   r+   N)r   r   ÚTestSuppression2r   r'   r   r   r   r,   r   r-   r!   r   r   r   Útest_suppressModulen   r/   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.
        ÚtestOverrideSuppressClassr   r   r*   r+   é   N)r   r   r'   r   r   r   r   r,   r   r    r-   r!   r   r   r   Útest_overrideSuppressClassz   s   z+SuppressionMixin.test_overrideSuppressClassN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r#   r&   r(   r.   r2   r5   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)	r6   r7   r8   r9   r   r   r%   r'   r1   r   r   r   r   r:   ˆ   s    ÿÿÿÿr:   )r9   r   r   Útwisted.python.reflectr   Útwisted.trialÚtwisted.trial.testr   r   ÚSynchronousTestCaser:   r   r   r   r   Ú<module>   s   x