
=\•jH  ã               @   s  d  Z  d d l Z d d l Z d d l Z d d l Z d g e j d d … <y d d l Z Wn e k
 rv d Z	 Yn Xe j
 d d k r¬ e j
 d d k  r¬ d d l Z n d d l Z e j j d d	 ƒ d
 k Z d Z Gd d „  d e j ƒ Z e d k re j ƒ  d S)aH  
websocket - WebSocket client library for Python

Copyright (C) 2010 Hiroki Ohtani(liris)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

é    NÚ Fé   é   é   ÚTEST_WITH_INTERNETÚ0Ú1Tc               @   s˜   e  Z d  Z Gd d „  d e ƒ Z d d „  Z d d „  Z e j e	 d ƒ d d	 „  ƒ Z
 e j e	 d ƒ d
 d „  ƒ Z e j e	 d ƒ d d „  ƒ Z d S)ÚWebSocketAppTestc               @   s   e  Z d  Z d Z d S)zWebSocketAppTest.NotSetYetzI A marker class for signalling that a value hasn't been set yet.
        N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r   r   úD/tmp/pip-build-jxowagp5/websocket-client/websocket/tests/test_app.pyÚ	NotSetYet/   s   r   c             C   s>   t  j t ƒ t j ƒ  t _ t j ƒ  t _ t j ƒ  t _ d  S)N)ÚwsZenableTraceÚ	TRACEABLEr	   r   Úkeep_running_openÚkeep_running_closeÚget_mask_key_id)Úselfr   r   r   ÚsetUp3   s    zWebSocketAppTest.setUpc             C   s1   t  j ƒ  t  _ t  j ƒ  t  _ t  j ƒ  t  _ d  S)N)r	   r   r   r   r   )r   r   r   r   ÚtearDown:   s    zWebSocketAppTest.tearDownz%Internet-requiring tests are disabledc             C   sA   d d „  } d d „  } t  j d d | d | ƒ} | j ƒ  d S)	z| A WebSocketApp should keep running as long as its self.keep_running
        is not False (in the boolean context).
        c             _   s   |  j  t _ |  j ƒ  d S)zn Set the keep_running flag for later inspection and immediately
            close the connection.
            N)Úkeep_runningr	   r   Úclose)r   ÚargsÚkwargsr   r   r   Úon_openE   s    z1WebSocketAppTest.testKeepRunning.<locals>.on_openc             _   s   |  j  t _ d S)z< Set the keep_running flag for the test to use.
            N)r   r	   r   )r   r   r   r   r   r   Úon_closeM   s    z2WebSocketAppTest.testKeepRunning.<locals>.on_closezws://echo.websocket.org/r   r   N)r   ÚWebSocketAppÚrun_forever)r   r   r   Úappr   r   r   ÚtestKeepRunning?   s    z WebSocketAppTest.testKeepRunningc             C   sA   d d „  } d d „  } t  j d d | d | ƒ} | j ƒ  d S)	zi A WebSocketApp should forward the received mask_key function down
        to the actual socket.
        c               S   s   d  S)Nr   r   r   r   r   Úmy_mask_key_funce   s    z:WebSocketAppTest.testSockMaskKey.<locals>.my_mask_key_funcc             _   s    t  |  j ƒ t _ |  j ƒ  d S)zm Set the value so the test can use it later on and immediately
            close the connection.
            N)ÚidÚget_mask_keyr	   r   r   )r   r   r   r   r   r   r   h   s    z1WebSocketAppTest.testSockMaskKey.<locals>.on_openzws://echo.websocket.org/r   r%   N)r   r   r    )r   r#   r   r!   r   r   r   ÚtestSockMaskKey_   s    z WebSocketAppTest.testSockMaskKeyc          
   C   s~   d d „  } d d „  } t  j d d | d | ƒ} | j d d	 d
 d ƒ |  j t  j | j d d	 d
 d d d t j i ƒd S)z. A WebSocketApp should ping regularly
        c             S   s   t  d ƒ |  j ƒ  d  S)NzGot a ping!)Úprintr   )r!   Úmsgr   r   r   Úon_ping{   s    
z2WebSocketAppTest.testPingInterval.<locals>.on_pingc             S   s   t  d ƒ |  j ƒ  d  S)NzGot a pong! No need to respond)r'   r   )r!   r(   r   r   r   Úon_pong   s    
z2WebSocketAppTest.testPingInterval.<locals>.on_pongzwss://api-pub.bitfinex.com/ws/1r)   r*   Zping_intervalr   Zping_timeoutr   é   ZssloptÚ	cert_reqsN)r   r   r    ZassertRaisesZWebSocketExceptionÚsslÚ	CERT_NONE)r   r)   r*   r!   r   r   r   ÚtestPingIntervalv   s
    z!WebSocketAppTest.testPingIntervalN)r
   r   r   Úobjectr   r   r   ÚunittestZ
skipUnlessr   r"   r&   r/   r   r   r   r   r	   -   s    r	   Ú__main__)r   ÚosÚos.pathZ	websocketr   ÚsysÚpathr-   ÚImportErrorZHAVE_SSLÚversion_infoZ	unittest2r1   ÚenvironÚgetr   r   ZTestCaser	   r
   Úmainr   r   r   r   Ú<module>   s"   &[