o
    ¼>hb  ã                   @   sJ   d dl Z d dlmZ d dlZd dlmZ d dlmZ G dd„ dej	ƒZ
dS )é    N)ÚMock)Úunittest)Úchoosereactorc                   @   sD   e 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S )ÚChooseReactorTestsc                    s>   t tjˆ ƒr|  tjˆ |¡ dS ‡ fdd„}ttjˆ |ƒ dS )zh
        Patch ``name`` so that Twisted will grab a fake reactor instead of
        a real one.
        c                      s   t tjˆ ƒ d S ©N)ÚdelattrÚtwistedÚinternet© ©Únamer
   ú‹/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/autobahn/twisted/test/test_tx_choosereactor.pyÚ_cleanup.   s   z2ChooseReactorTests.patch_reactor.<locals>._cleanupN)Úhasattrr   r	   ÚpatchÚsetattr)Úselfr   Únew_reactorr   r
   r   r   Úpatch_reactor&   s   z ChooseReactorTests.patch_reactorc                    s:   t tjƒ‰ t tjƒ}|d= ‡ fdd„}|  |¡ |t_dS )zg
        Patch ``sys.modules`` so that Twisted believes there is no
        installed reactor.
        ztwisted.internet.reactorc                      s
   ˆ t _d S r   )ÚsysÚmodulesr
   ©Úold_modulesr
   r   r   <   s   
z2ChooseReactorTests.patch_modules.<locals>._cleanupN)Údictr   r   Ú
addCleanup)r   Únew_modulesr   r
   r   r   Úpatch_modules2   s   



z ChooseReactorTests.patch_modulesc                 C   ó>   t ƒ }|  d|¡ |  tdd¡ |  ¡  t ¡  |j ¡  dS )z‹
        ``install_optimal_reactor`` will use the default reactor if it is
        unable to detect the platform it is running on.
        ÚselectreactorÚplatformÚunknownN©	r   r   r   r   r   r   Úinstall_optimal_reactorÚinstallÚassert_called_once_with©r   Úreactor_mockr
   r
   r   Útest_unknownB   ó   zChooseReactorTests.test_unknownc                 C   r   )zb
        ``install_optimal_reactor`` will install KQueueReactor on
        Darwin (OS X).
        Ú	kqreactorr   ÚdarwinNr!   r%   r
   r
   r   Útest_macQ   r(   zChooseReactorTests.test_macc                 C   sR   t jdkr
t d¡‚tƒ }|  d|¡ |  t dd¡ |  ¡  t 	¡  |j
 ¡  dS )zR
        ``install_optimal_reactor`` will install IOCPReactor on Windows.
        Úwin32zunit test requires WindowsÚiocpreactorr   N)r   r   r   ÚSkipTestr   r   r   r   r   r"   r#   r$   r%   r
   r
   r   Útest_win`   s   

zChooseReactorTests.test_winc                 C   r   )zP
        ``install_optimal_reactor`` will install KQueueReactor on BSD.
        r)   r   Ú	freebsd11Nr!   r%   r
   r
   r   Útest_bsdq   ó   zChooseReactorTests.test_bsdc                 C   r   )zQ
        ``install_optimal_reactor`` will install EPollReactor on Linux.
        Úepollreactorr   ÚlinuxNr!   r%   r
   r
   r   Ú
test_linux   r2   zChooseReactorTests.test_linuxN)
Ú__name__Ú
__module__Ú__qualname__r   r   r'   r+   r/   r1   r5   r
   r
   r
   r   r   $   s    r   )r   Úunittest.mockr   Útwisted.internetr   Útwisted.trialr   Úautobahn.twistedr   ÚTestCaser   r
   r
   r
   r   Ú<module>   s   