o
    ¼>hƒ  ã                   @  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 )NÚ	test_pass)r   Ú
PyUnitTestÚoriginalr   Útest©Úself© r   ú„/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/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.   r1   r   r   r   r   ÚStubReporter=   s    


r2   r"   r   N)r   r   r$   ÚrunÚassertIsInstancer%   r   )r   r2   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Ú
TestResultr3   r   r!   ÚassertEqualÚtestsRunÚwasSuccessful)r   r>   r   r5   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                   @  r7   )z3PyUnitResultTests.test_failure.<locals>.FailureTestFr   r   c                 S  s   d| _ |  d¡ d S )NTzboom!)r!   Úfailr:   r   r   r   r"   r   s   z<PyUnitResultTests.test_failure.<locals>.FailureTest.test_fooNr   r=   r   r   r   r   ÚFailureTesto   r?   rG   r"   r   )r
   r@   rA   r3   r   r!   rB   rC   Úlenr&   ÚassertFalserD   )r   rG   r   r5   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@   rA   r3   r   r!   rB   rC   rH   r%   rI   rD   )r   r   r5   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  r8   r9   r    r:   r   r   r   r"      r<   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@   rA   r3   rI   r!   rB   rC   rH   r%   rD   )r   r$   r   r5   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@   rA   r	   r1   rB   r%   ÚjoinÚ	tracebackÚformat_exception)r   rR   ÚfÚpyresultr5   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 rM   )rP   rQ   rR   r   r   r   r   r"   µ   s   
þz<PyUnitResultTests.test_traceback.<locals>.ErrorTest.test_foor   )r   r   r   rR   r"   r   r   r   r   r$   ²   r?   r$   r"   NrO   é   Ú
r   r   éÿÿÿÿ)r
   r@   rA   r3   rR   rS   rT   Ú	format_tbr%   Ú
splitlinesrB   ÚstriprH   )r   r$   r   r5   Úexpected_stackÚ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   rO   z$ZeroDivisionError: division by zero
N)rP   rQ   rR   r   ÚcleanFailurer@   rA   r	   r1   rS   rT   rU   rB   r%   Úendswith)r   rR   rV   rW   r5   Ú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  rL   rM   r   r   r   r   r   Ú	test_skipê   ó   z<PyUnitResultTests.test_trialSkip.<locals>.SkipTest.test_skipNr   )r   r   r   r   rh   r   r   r   r   ÚSkipTesté   ó    rj   rh   rg   N©r
   r@   rA   r3   rB   Úskipped©r   rj   r   r5   r   r   r   Útest_trialSkipã   ó
   
z PyUnitResultTests.test_trialSkipc                 C  rf   )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  rL   rM   r   r   r   r   r   rh   ú   ri   z=PyUnitResultTests.test_pyunitSkip.<locals>.SkipTest.test_skipNr   )r   r   r   r@   Úskiprh   r   r   r   r   rj   ù   rk   rj   rh   rq   Nrl   rn   r   r   r   Útest_pyunitSkipó   rp   z!PyUnitResultTests.test_pyunitSkipNr   )r   r   r   r#   r
   r$   r6   rE   rJ   rK   rN   rX   ra   re   ro   rs   r   r   r   r   r      s    

(




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