o
    Óó·iƒ  ã                   @  s˜   d dl m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
 d dlmZmZ d dlmZ d dlmZmZ G d	d
„ d
eƒZG dd„ deƒZdS )é    )ÚannotationsN)ÚskipIf)Úimplementer)ÚFailure)Ú	IReporterÚ	ITestCase)Úpyunitcases)ÚPyUnitResultAdapterÚSynchronousTestCasec                   @  s    e Zd Zddd„Zddd„ZdS )	ÚPyUnitTestTestsÚreturnÚNonec                 C  s   t  d¡| _t| jƒ| _d S )NZ	test_pass)r   Z
PyUnitTestÚoriginalr   Útest©Úself© r   újC:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-packages\twisted/trial/test/test_pyunitcompat.pyÚ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   )Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r      s    
r   c                   @  s„   e Zd ZdZG dd„ deƒZddd„Zddd	„Zdd
d„Zddd„Z	ddd„Z
ddd„Zddd„Zddd„Zddd„Zd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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.
        Fr   r   c                 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_foo0   s   z$PyUnitResultTests.ErrorTest.test_fooNr   )r   r   r   Ú__doc__r   r    r   r   r   r   Ú	ErrorTest'   s    r"   r   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                   @  s8   e Zd ZdZddd„Zddd	„Zdd
d„Zd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}.
            r   r   c                 S  s   g | _ g | _d S )N)ÚerrorsÚfailuresr   r   r   r   Ú__init__F   s   
zaPyUnitResultTests.test_dontUseAdapterWhenReporterProvidesIReporter.<locals>.StubReporter.__init__r   Úobjectc                 S  ó   dS ©z-
                Do nothing.
                Nr   ©r   r   r   r   r   Ú	startTestJ   ó    zbPyUnitResultTests.test_dontUseAdapterWhenReporterProvidesIReporter.<locals>.StubReporter.startTestc                 S  r'   r(   r   r)   r   r   r   ÚstopTestO   r+   zaPyUnitResultTests.test_dontUseAdapterWhenReporterProvidesIReporter.<locals>.StubReporter.stopTestÚerrorr   c                 S  s   | j  |¡ dS )z3
                Record the error.
                N)r#   Úappend)r   r   r-   r   r   r   ÚaddErrorT   s   zaPyUnitResultTests.test_dontUseAdapterWhenReporterProvidesIReporter.<locals>.StubReporter.addErrorNr   )r   r&   r   r   )r   r&   r-   r   r   r   )r   r   r   r!   r%   r*   r,   r/   r   r   r   r   ÚStubReporter=   s    


r0   r    r   N)r   r   r"   ÚrunZassertIsInstancer#   r   )r   r0   r   Úresultr   r   r   Ú0test_dontUseAdapterWhenReporterProvidesIReporter7   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d„ZdS )z3PyUnitResultTests.test_success.<locals>.SuccessTestFr   r   c                 S  ó
   d| _ d S ©NTr   ©Úsr   r   r   r    c   ó   
z<PyUnitResultTests.test_success.<locals>.SuccessTest.test_fooNr   ©r   r   r   r   r    r   r   r   r   ÚSuccessTest`   ó    r;   r    r   )	r
   ÚpyunitÚ
TestResultr1   r   r   ÚassertEqualÚtestsRunÚwasSuccessful)r   r;   r   r2   r   r   r   Útest_success_   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>.FailureTestFr   r   c                 S  s   d| _ |  d¡ d S )NTzboom!)r   Zfailr7   r   r   r   r    r   s   z<PyUnitResultTests.test_failure.<locals>.FailureTest.test_fooNr   r:   r   r   r   r   ÚFailureTesto   r<   rC   r    r   )r
   r=   r>   r1   r   r   r?   r@   Úlenr$   ÚassertFalserA   )r   rC   r   r2   r   r   r   Útest_failuren   s   
zPyUnitResultTests.test_failurec                 C  sZ   |   d¡}t ¡ }| |¡ |  |j¡ |  d|j¡ |  dt|j	ƒ¡ |  
| ¡ ¡ d S )Nr    r   )r"   r=   r>   r1   r   r   r?   r@   rD   r#   rE   rA   )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d„Zd	dd„ZdS )
z4PyUnitResultTests.test_setUpError.<locals>.ErrorTestFr   r   c                 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_fooNr   )r   r   r   r   r   r    r   r   r   r   r"   Š   s    
r"   r    r   )r
   r=   r>   r1   rE   r   r?   r@   rD   r#   rA   )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 ¡ }| |¡ |jdusJ ‚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d„ZdS )z3PyUnitResultTests.test_traceback.<locals>.ErrorTestNr   r   c                 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_foor   )r   r   r   rN   r    r   r   r   r   r"   ²   r<   r"   r    NrK   é   Ú
r   r   éÿÿÿÿ)r
   r=   r>   r1   rN   rO   rP   Ú	format_tbr#   Ú
splitlinesr?   ÚstriprD   )r   r"   r   r2   Zexpected_stackZobserved_stackr   r   r   Útest_traceback­   s   

 ÿz PyUnitResultTests.test_tracebackc                 C  sˆ   zdd  W n t y   t ¡ }tƒ }Y nw | ¡  t ¡ }t|ƒ}| | |¡ d 	t
j|Ž ¡}|  |jd d  d¡| d¡¡ 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   z$ZeroDivisionError: division by zero
N)rL   rM   rN   r   ZcleanFailurer=   r>   r	   r/   rO   rP   rQ   r?   r#   Úendswith)r   rN   rR   rS   r2   Ztbackr   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d„ƒZdS )	z2PyUnitResultTests.test_trialSkip.<locals>.SkipTestTúLet's skip!r   r   c                 S  rH   rI   r   r   r   r   r   Ú	test_skipê   ó   z<PyUnitResultTests.test_trialSkip.<locals>.SkipTest.test_skipNr   )r   r   r   r   r`   r   r   r   r   ÚSkipTesté   ó    rb   r`   r_   N©r
   r=   r>   r1   r?   Úskipped©r   rb   r   r2   r   r   r   Útest_trialSkipã   ó
   
z PyUnitResultTests.test_trialSkipc                 C  r^   )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d„ƒZdS )z3PyUnitResultTests.test_pyunitSkip.<locals>.SkipTestÚskippyr   r   c                 S  rH   rI   r   r   r   r   r   r`   ú   ra   z=PyUnitResultTests.test_pyunitSkip.<locals>.SkipTest.test_skipNr   )r   r   r   r=   Úskipr`   r   r   r   r   rb   ù   rc   rb   r`   ri   Nrd   rf   r   r   r   Útest_pyunitSkipó   rh   z!PyUnitResultTests.test_pyunitSkipNr   )r   r   r   r!   r
   r"   r3   rB   rF   rG   rJ   rT   r[   r]   rg   rk   r   r   r   r   r      s    

(






!
r   )Ú
__future__r   rM   rP   Zunittestr=   r   Zzope.interfacer   Ztwisted.python.failurer   Ztwisted.trial.itrialr   r   Ztwisted.trial.testr   Ztwisted.trial.unittestr	   r
   r   r   r   r   r   r   Ú<module>   s   