
    <fh                         d dl Z d dlZd dlZd dlmZmZ d dlmZ d dlm	Z	 d dl
mZmZ 	  G d dej                        Zedk(  r ej                           yy)	    N)Mockpatch)recv)SSLWantReadError)WebSocketTimeoutException"WebSocketConnectionClosedExceptionc                   .    e Zd ZdZd Zd Zd Zd Zd Zy)SocketBugsTestz(Test bugs found in socket handling logicc                    t               }t               |j                  _        d|j                  _        t        d      5 }t               }||_        g |j                  _        | j                  t              5 }t        |d       ddd       | j                  dt        j                               ddd       y# 1 sw Y   7xY w# 1 sw Y   yxY w)a  
        BUG #5 FIX VERIFICATION: Test SSLWantReadError timeout now raises correct exception

        Bug was in _socket.py:100-101 - SSLWantReadError except block returned None implicitly
        Fixed: Now properly handles timeout with WebSocketTimeoutException
              ?selectors.DefaultSelectord   N%Connection timed out waiting for datar   r   r   side_effect
gettimeoutreturn_valuer   selectassertRaisesr   assertInstr	exceptionself	mock_sockmock_selector_classmock_selectorcms        S/var/www/zara/venv/lib/python3.12/site-packages/websocket/tests/test_socket_bugs.py6test_bug_implicit_none_return_from_ssl_want_read_fixedzESocketBugsTest.test_bug_implicit_none_return_from_ssl_want_read_fixed$        F	%5%7	",/	)./ 		V3F FM/<,02M  -""#<= %Y$% MMA3r||CTU		V 		V
% %		V 		V$    8C8B;-C;C	 CCc                    t               }t        t        j                  d      }||j                  _        d|j                  _        t        d      5 }t               }||_        g |j                  _        | j                  t              5 }t	        |d       ddd       | j                  dt        j                               ddd       y# 1 sw Y   7xY w# 1 sw Y   yxY w)a  
        BUG #5 FIX VERIFICATION: Test that socket.error with EAGAIN now handles timeout correctly

        Bug was in _socket.py:102-105 - socket.error except block returned None implicitly
        Fixed: Now properly handles timeout with WebSocketTimeoutException
        z Resource temporarily unavailabler   r   r   Nr   )r   OSErrorerrnoEAGAINr   r   r   r   r   r   r   r   r   r   r   )r   r   eagain_errorr   r   r   s         r   5test_bug_implicit_none_return_from_socket_error_fixedzDSocketBugsTest.test_bug_implicit_none_return_from_socket_error_fixed:   s     F	 u||-OP &2	",/	)./ 		V3F FM/<,02M  -""#<= %Y$% MMA3r||CTU		V 		V
% %		V 		Vs$   8C
C-CC	CC"c                    t               }t               |j                  _        d|j                  _        t        d      5 }t               }||_        g |j                  _        | j                  t              5 }t        |d       ddd       | j                  dt        j                               ddd       y# 1 sw Y   7xY w# 1 sw Y   yxY w)z
        BUG #6 FIX VERIFICATION: Test that selector timeout now raises correct exception type

        Bug was in _socket.py:115 returning None for timeout, treated as connection error
        Fixed: Now raises WebSocketTimeoutException directly
        r   r   r   Nr   r   r   s        r   3test_bug_wrong_exception_for_selector_timeout_fixedzBSocketBugsTest.test_bug_wrong_exception_for_selector_timeout_fixedU   r!   r"   c                    t               }d|j                  _        t        j                  d      |j
                  _        | j                  t              5 }t        |d       ddd       ddl	}|j                  dk\  r&| j                  dt        j                               y| j                  dt        j                               y# 1 sw Y   hxY w)zJ
        Test that socket.timeout exceptions are properly handled
        r   zOperation timed outr   Nr   )   
   zConnection timed out)r   r   r   sockettimeoutr   r   r   r   sysversion_infor   r   r   )r   r   r   r0   s       r   &test_socket_timeout_exception_handlingz5SocketBugsTest.test_socket_timeout_exception_handlingp   s     F	,/	) &,^^4I%J	" 89 	!RC 	! 	w&MM0#bll2CDMM/R\\1BC	! 	!s   C		Cc                    t               }t               dg|j                  _        d|j                  _        t        d      5 }t               }||_        dg|j                  _        t        |d      }| j                  |d       |j                  j                          |j                  j                          ddd       y# 1 sw Y   yxY w)zCTest the correct behavior when SSLWantReadError is properly handleds   data after retryr   r   Tr   N)r   r   r   r   r   r   r   r   assertEqualregisterassert_called)r   r   r   r   results        r   )test_correct_ssl_want_read_retry_behaviorz8SocketBugsTest.test_correct_ssl_want_read_retry_behavior   s    F	 '7&8:M%N	",/	)./ 	13F FM/<,15M  - )S)FV%89 ""002  ..0	1 	1 	1s   A6CC
N)	__name__
__module____qualname____doc__r    r(   r*   r2   r8        r   r
   r
   !   s"    2V,V6V6D21r>   r
   __main__)r%   r.   unittestunittest.mockr   r   websocket._socketr   websocket._ssl_compatr   websocket._exceptionsr   r   TestCaser
   r9   mainr=   r>   r   <module>rG      sP       % " 2
&{1X&& {1| zHMMO r>   