o
    b                     @   s   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 d dl	m
Z
mZ d dlmZmZ G dd deZG d	d
 d
eZdS )    N)skipIf)implementer)Failure)	IReporter	ITestCase)PyUnitResultAdapterSynchronousTestCasec                   @   s.   e Zd ZG dd dejZdd Zdd ZdS )PyUnitTestTestsc                   @   s   e Zd Zdd ZdS )zPyUnitTestTests.PyUnitTestc                 C   s   d S N selfr   r   F/usr/lib/python3/dist-packages/twisted/trial/test/test_pyunitcompat.py	test_pass   s   z$PyUnitTestTests.PyUnitTest.test_passN)__name__
__module____qualname__r   r   r   r   r   
PyUnitTest   s    r   c                 C   s   |  d| _t| j| _d S )Nr   )r   originalr   testr   r   r   r   setUp   s   zPyUnitTestTests.setUpc                 C   s   |  t| j| jd dS )zW
        Tests must be callable in order to be used with Python's unittest.py.
        z is not callable.N)
assertTruecallabler   r   r   r   r   test_callable   s   zPyUnitTestTests.test_callableN)r   r   r   pyunitTestCaser   r   r   r   r   r   r   r	      s    r	   c                   @   sp   e Zd ZdZG dd de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d ZdS )PyUnitResultTestsz
    Tests to show that PyUnitResultAdapter wraps TestResult objects from the
    standard library 'unittest' module in such a way as to make them usable and
    useful from Trial.
    c                   @   s   e Zd ZdZdZdd ZdS )zPyUnitResultTests.ErrorTestz
        A test case which has a L{test_foo} which will raise an error.

        @ivar ran: boolean indicating whether L{test_foo} has been run.
        Fc                 C   s   d| _ dd  dS )zR
            Set C{self.ran} to True and raise a C{ZeroDivisionError}
            T   r   Nranr   r   r   r   test_foo3   s   z$PyUnitResultTests.ErrorTest.test_fooN)r   r   r   __doc__r   r    r   r   r   r   	ErrorTest*   s    r"   c                 C   sF   t tG dd d}| d}| }|| | |jd t dS )z
        The L{PyUnitResultAdapter} is only used when the result passed to
        C{run} does *not* provide L{IReporter}.
        c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )zXPyUnitResultTests.test_dontUseAdapterWhenReporterProvidesIReporter.<locals>.StubReporterz
            A reporter which records data about calls made to it.

            @ivar errors: Errors passed to L{addError}.
            @ivar failures: Failures passed to L{addFailure}.
            c                 S   s   g | _ g | _d S r
   )errorsfailuresr   r   r   r   __init__I   s   
zaPyUnitResultTests.test_dontUseAdapterWhenReporterProvidesIReporter.<locals>.StubReporter.__init__c                 S      dS z-
                Do nothing.
                Nr   r   r   r   r   r   	startTestM       zbPyUnitResultTests.test_dontUseAdapterWhenReporterProvidesIReporter.<locals>.StubReporter.startTestc                 S   r&   r'   r   r(   r   r   r   stopTestR   r*   zaPyUnitResultTests.test_dontUseAdapterWhenReporterProvidesIReporter.<locals>.StubReporter.stopTestc                 S   s   | j | dS )z3
                Record the error.
                N)r#   append)r   r   errorr   r   r   addErrorW   s   zaPyUnitResultTests.test_dontUseAdapterWhenReporterProvidesIReporter.<locals>.StubReporter.addErrorN)r   r   r   r!   r%   r)   r+   r.   r   r   r   r   StubReporter@   s    r/   r    r   N)r   r   r"   runassertIsInstancer#   r   )r   r/   r   resultr   r   r   0test_dontUseAdapterWhenReporterProvidesIReporter:   s   

zBPyUnitResultTests.test_dontUseAdapterWhenReporterProvidesIReporterc                 C   sV   G dd dt }|d}t }|| | |j | d|j | |  d S )Nc                   @      e Zd ZdZdd ZdS )z3PyUnitResultTests.test_success.<locals>.SuccessTestFc                 S   
   d| _ d S NTr   sr   r   r   r    f      
z<PyUnitResultTests.test_success.<locals>.SuccessTest.test_fooNr   r   r   r   r    r   r   r   r   SuccessTestc       r;   r    r   )	r   r   
TestResultr0   r   r   assertEqualtestsRunwasSuccessful)r   r;   r   r2   r   r   r   test_successb   s   
zPyUnitResultTests.test_successc                 C   sh   G dd dt }|d}t }|| | |j | d|j | dt|j	 | 
|  d S )Nc                   @   r4   )z3PyUnitResultTests.test_failure.<locals>.FailureTestFc                 S   s   d| _ | d d S )NTzboom!)r   failr7   r   r   r   r    u   s   z<PyUnitResultTests.test_failure.<locals>.FailureTest.test_fooNr:   r   r   r   r   FailureTestr   r<   rC   r    r   )r   r   r=   r0   r   r   r>   r?   lenr$   assertFalser@   )r   rC   r   r2   r   r   r   test_failureq   s   
zPyUnitResultTests.test_failurec                 C   sZ   |  d}t }|| | |j | d|j | dt|j	 | 
|  d S )Nr    r   )r"   r   r=   r0   r   r   r>   r?   rD   r#   rE   r@   )r   r   r2   r   r   r   
test_error   s   

zPyUnitResultTests.test_errorc                 C   sh   G dd dt }|d}t }|| | |j | d|j | dt|j	 | |
  d S )Nc                   @   s    e Zd ZdZdd Zdd ZdS )z4PyUnitResultTests.test_setUpError.<locals>.ErrorTestFc                 S      dd  d S Nr   r   r   r   r   r   r   r      s   z:PyUnitResultTests.test_setUpError.<locals>.ErrorTest.setUpc                 S   r5   r6   r   r7   r   r   r   r       r9   z=PyUnitResultTests.test_setUpError.<locals>.ErrorTest.test_fooN)r   r   r   r   r   r    r   r   r   r   r"      s    r"   r    r   )r   r   r=   r0   rE   r   r>   r?   rD   r#   r@   )r   r"   r   r2   r   r   r   test_setUpError   s   	
z!PyUnitResultTests.test_setUpErrorc                 C   sp   zdd  W n t y   t }t }Y nw t }t|}|| | | |j	d d d
tj|  dS )z
        Errors added through the L{PyUnitResultAdapter} have the same traceback
        information as if there were no adapter at all.
        r   r    N)ZeroDivisionErrorsysexc_infor   r   r=   r   r.   r>   r#   join	tracebackformat_exceptionr   rN   fpyresultr2   r   r   r   test_tracebackFromFailure   s   
z+PyUnitResultTests.test_tracebackFromFailurec                 C   s   G dd dt }|d}t }|| dt|jd }d|jd d 	 d	d
 }| 
| |t| d	   d	S )zG
        As test_tracebackFromFailure, but covering more code.
        c                   @   s   e Zd ZdZdd ZdS )z3PyUnitResultTests.test_traceback.<locals>.ErrorTestNc                 S   s*   zdd  W d S  t y   t | _ w rI   )rL   rM   rN   r   r   r   r   r       s   
z<PyUnitResultTests.test_traceback.<locals>.ErrorTest.test_foo)r   r   r   rN   r    r   r   r   r   r"      r<   r"   r    rK      
r   r   N)r   r   r=   r0   rO   rP   	format_tbrN   r#   
splitlinesr>   striprD   )r   r"   r   r2   expected_stackobserved_stackr   r   r   test_traceback   s   

	 z PyUnitResultTests.test_tracebackc                 C   sx   zdd  W n t y   t }t }Y nw |  t }t|}|| | | 	|j
d d dtj|  dS )z
        Errors added through the L{PyUnitResultAdapter} have the same
        traceback information as if there were no adapter at all, even
        if the Failure that held the information has been cleaned.
        r   r   rK   N)rL   rM   rN   r   cleanFailurer   r=   r   r.   r>   r#   rO   rP   rQ   rR   r   r   r   test_tracebackFromCleanFailure   s   
z0PyUnitResultTests.test_tracebackFromCleanFailurec                 C   B   G dd dt }|d}t }|| | |j|dfg dS )zw
        Skips using trial's skipping functionality are reported as skips in
        the L{pyunit.TestResult}.
        c                   @   s   e Zd Zedddd ZdS )z2PyUnitResultTests.test_trialSkip.<locals>.SkipTestTLet's skip!c                 S   rH   rI   r   r   r   r   r   	test_skip      z<PyUnitResultTests.test_trialSkip.<locals>.SkipTest.test_skipN)r   r   r   r   rc   r   r   r   r   SkipTest       re   rc   rb   Nr   r   r=   r0   r>   skippedr   re   r   r2   r   r   r   test_trialSkip   
   
z PyUnitResultTests.test_trialSkipc                 C   ra   )zx
        Skips using pyunit's skipping functionality are reported as skips in
        the L{pyunit.TestResult}.
        c                   @   s   e Zd Zeddd ZdS )z3PyUnitResultTests.test_pyunitSkip.<locals>.SkipTestskippyc                 S   rH   rI   r   r   r   r   r   rc      rd   z=PyUnitResultTests.test_pyunitSkip.<locals>.SkipTest.test_skipN)r   r   r   r   skiprc   r   r   r   r   re      rf   re   rc   rl   Nrg   ri   r   r   r   test_pyunitSkip   rk   z!PyUnitResultTests.test_pyunitSkipN)r   r   r   r!   r   r"   r3   rA   rF   rG   rJ   rU   r^   r`   rj   rn   r   r   r   r   r   !   s    (
!r   )rM   rP   unittestr   r   zope.interfacer   twisted.python.failurer   twisted.trial.itrialr   r   twisted.trial.unittestr   r   r	   r   r   r   r   r   <module>   s   