
    hb                     b    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ej                        Z
y)    N)Mock)unittest)choosereactorc                   6    e Zd Zd Zd Zd Zd Zd Zd Zd Z	y)	ChooseReactorTestsc                     t        t        j                        r"| j                  t        j                  |       yfd}t	        t        j                  |       y)zh
        Patch ``name`` so that Twisted will grab a fake reactor instead of
        a real one.
        c                  :    t        t        j                          y N)delattrtwistedinternet)names   g/var/www/Befach/backend/env/lib/python3.12/site-packages/autobahn/twisted/test/test_tx_choosereactor.py_cleanupz2ChooseReactorTests.patch_reactor.<locals>._cleanup.   s    (($/    N)hasattrr   r   patchsetattr)selfr   new_reactorr   s    `  r   patch_reactorz ChooseReactorTests.patch_reactor&   sB    
 7##T*JJw''{;0G$$dK8r   c                     t        t        j                        t        t        j                        }|d= fd}| j                  |       |t        _        y)zg
        Patch ``sys.modules`` so that Twisted believes there is no
        installed reactor.
        ztwisted.internet.reactorc                       t         _        y r
   )sysmodules)old_moduless   r   r   z2ChooseReactorTests.patch_modules.<locals>._cleanup<   s
    %CKr   N)dictr   r   
addCleanup)r   new_modulesr   r   s      @r   patch_modulesz ChooseReactorTests.patch_modules2   sD    
 3;;'3;;'23	& 	!!r   c                     t               }| j                  d|       | j                  t        dd       | j	                          t        j                          |j                  j                          y)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_mocks     r   test_unknownzChooseReactorTests.test_unknownB   sW    
 v?L9

3
I. 	--/446r   c                     t               }| j                  d|       | j                  t        dd       | j	                          t        j                          |j                  j                          y)zb
        ``install_optimal_reactor`` will install KQueueReactor on
        Darwin (OS X).
        	kqreactorr#   darwinNr%   r)   s     r   test_maczChooseReactorTests.test_macQ   sW    
 v;5

3
H- 	--/446r   c                 6   t         j                  dk7  rt        j                  d      t	               }| j                  d|       | j                  t         dd       | j                          t        j                          |j                  j                          y)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)   s     r   test_winzChooseReactorTests.test_win`   su     <<7"##$@AAv=,7

3
G, 	--/446r   c                     t               }| j                  d|       | j                  t        dd       | j	                          t        j                          |j                  j                          y)zP
        ``install_optimal_reactor`` will install KQueueReactor on BSD.
        r-   r#   	freebsd11Nr%   r)   s     r   test_bsdzChooseReactorTests.test_bsdq   sW     v;5

3
K0 	--/446r   c                     t               }| j                  d|       | j                  t        dd       | j	                          t        j                          |j                  j                          y)zQ
        ``install_optimal_reactor`` will install EPollReactor on Linux.
        epollreactorr#   linuxNr%   r)   s     r   
test_linuxzChooseReactorTests.test_linux   sW     v><8

3
G, 	--/446r   N)
__name__
__module____qualname__r   r    r+   r/   r4   r7   r;    r   r   r   r   $   s%    
9" 777"77r   r   )r   unittest.mockr   twisted.internetr   twisted.trialr   autobahn.twistedr   TestCaser   r?   r   r   <module>rE      s*   6    " *g7** g7r   