<s> from functools import partial <EOL> from tornado import testing <EOL> import tornado . websocket <EOL> import tornado . web <EOL> import tornado . ioloop <EOL> import websocket <EOL> class EchoWebSocketHandler ( tornado . websocket . WebSocketHandler ) : <EOL> def on_message ( self , message ) : <EOL> self . write_message ( message ) <EOL> class WebSocketTest ( testing . AsyncHTTPTestCase ) : <EOL> """<STR_LIT>""" <EOL> def get_app ( self ) : <EOL> app = tornado . web . Application ( [ ( '<STR_LIT:/>' , EchoWebSocketHandler ) ] ) <EOL> return app <EOL> def test_echo ( self ) : <EOL> _self = self <EOL> class WSClient ( websocket . WebSocket ) : <EOL> def on_open ( self ) : <EOL> self . write_message ( '<STR_LIT:hello>' ) <EOL> def on_message ( self , data ) : <EOL> _self . assertEquals ( data , '<STR_LIT:hello>' ) <EOL> _self . io_loop . add_callback ( _self . stop ) <EOL> self . io_loop . add_callback ( partial ( WSClient , self . get_url ( '<STR_LIT:/>' ) , <EOL> self . io_loop ) ) <EOL> self . wait ( ) </s>
