<s> '''<STR_LIT>''' <EOL> import logging <EOL> from chai import Chai <EOL> from haigha import connection , __version__ <EOL> from haigha . connection import Connection , ConnectionChannel , ConnectionError , ConnectionClosed <EOL> from haigha . channel import Channel <EOL> from haigha . frames . frame import Frame <EOL> from haigha . frames . method_frame import MethodFrame <EOL> from haigha . frames . heartbeat_frame import HeartbeatFrame <EOL> from haigha . frames . header_frame import HeaderFrame <EOL> from haigha . frames . content_frame import ContentFrame <EOL> from haigha . classes . basic_class import BasicClass <EOL> from haigha . classes . channel_class import ChannelClass <EOL> from haigha . classes . exchange_class import ExchangeClass <EOL> from haigha . classes . queue_class import QueueClass <EOL> from haigha . classes . transaction_class import TransactionClass <EOL> from haigha . classes . protocol_class import ProtocolClass <EOL> from haigha . transports import event_transport <EOL> from haigha . transports import gevent_transport <EOL> from haigha . transports import socket_transport <EOL> class ConnectionTest ( Chai ) : <EOL> def setUp ( self ) : <EOL> super ( ConnectionTest , self ) . setUp ( ) <EOL> self . connection = Connection . __new__ ( Connection ) <EOL> self . connection . _debug = False <EOL> self . connection . _logger = self . mock ( ) <EOL> self . connection . _user = '<STR_LIT>' <EOL> self . connection . _password = '<STR_LIT>' <EOL> self . connection . _host = '<STR_LIT:localhost>' <EOL> self . connection . _vhost = '<STR_LIT:/>' <EOL> self . connection . _connect_timeout = <NUM_LIT:5> <EOL> self . connection . _sock_opts = None <EOL> self . connection . _sock = None <EOL> self . connection . _heartbeat = None <EOL> self . connection . _open_cb = self . mock ( ) <EOL> self . connection . _close_cb = self . mock ( ) <EOL> self . connection . _login_method = '<STR_LIT>' <EOL> self . connection . _locale = '<STR_LIT>' <EOL> self . connection . _client_properties = None <EOL> self . connection . _properties = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> self . connection . _closed = False <EOL> self . connection . _connected = False <EOL> self . connection . _close_info = { <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:0> <EOL> } <EOL> self . connection . _class_map = { } <EOL> self . connection . _channels = { <EOL> <NUM_LIT:0> : self . mock ( ) <EOL> } <EOL> self . connection . _login_response = '<STR_LIT>' <EOL> self . connection . _channel_counter = <NUM_LIT:0> <EOL> self . connection . _channel_max = <NUM_LIT> <EOL> self . connection . _frame_max = <NUM_LIT> <EOL> self . connection . _frames_read = <NUM_LIT:0> <EOL> self . connection . _frames_written = <NUM_LIT:0> <EOL> self . connection . _strategy = self . mock ( ) <EOL> self . connection . _output_frame_buffer = [ ] <EOL> self . connection . _transport = mock ( ) <EOL> self . connection . _synchronous = False <EOL> self . connection . _synchronous_connect = False <EOL> def test_init_without_keyword_args ( self ) : <EOL> conn = Connection . __new__ ( Connection ) <EOL> strategy = mock ( ) <EOL> transport = mock ( ) <EOL> mock ( connection , '<STR_LIT>' ) <EOL> expect ( connection . ConnectionChannel ) . args ( <EOL> conn , <NUM_LIT:0> , { } ) . returns ( '<STR_LIT>' ) <EOL> expect ( socket_transport . SocketTransport ) . args ( conn ) . returns ( transport ) <EOL> expect ( conn . connect ) . args ( '<STR_LIT:localhost>' , <NUM_LIT> ) <EOL> conn . __init__ ( ) <EOL> assert_false ( conn . _debug ) <EOL> assert_equal ( logging . root , conn . _logger ) <EOL> assert_equal ( '<STR_LIT>' , conn . _user ) <EOL> assert_equal ( '<STR_LIT>' , conn . _password ) <EOL> assert_equal ( '<STR_LIT:localhost>' , conn . _host ) <EOL> assert_equal ( <NUM_LIT> , conn . _port ) <EOL> assert_equal ( '<STR_LIT:/>' , conn . _vhost ) <EOL> assert_equal ( <NUM_LIT:5> , conn . _connect_timeout ) <EOL> assert_equal ( None , conn . _sock_opts ) <EOL> assert_equal ( None , conn . _sock ) <EOL> assert_equal ( None , conn . _heartbeat ) <EOL> assert_equal ( None , conn . _open_cb ) <EOL> assert_equal ( None , conn . _close_cb ) <EOL> assert_equal ( '<STR_LIT>' , conn . _login_method ) <EOL> assert_equal ( '<STR_LIT>' , conn . _locale ) <EOL> assert_equal ( None , conn . _client_properties ) <EOL> assert_equal ( conn . _properties , { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : __version__ , <EOL> } ) <EOL> assert_false ( conn . _closed ) <EOL> assert_false ( conn . _connected ) <EOL> assert_equal ( conn . _close_info , { <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:0> <EOL> } ) <EOL> assert_equals ( { <EOL> <NUM_LIT:20> : ChannelClass , <EOL> <NUM_LIT> : ExchangeClass , <EOL> <NUM_LIT:50> : QueueClass , <EOL> <NUM_LIT> : BasicClass , <EOL> <NUM_LIT> : TransactionClass <EOL> } , conn . _class_map ) <EOL> assert_equal ( { <NUM_LIT:0> : '<STR_LIT>' } , conn . _channels ) <EOL> assert_equal ( <EOL> '<STR_LIT>' , conn . _login_response ) <EOL> assert_equal ( <NUM_LIT:0> , conn . _channel_counter ) <EOL> assert_equal ( <NUM_LIT> , conn . _channel_max ) <EOL> assert_equal ( <NUM_LIT> , conn . _frame_max ) <EOL> assert_equal ( [ ] , conn . _output_frame_buffer ) <EOL> assert_equal ( transport , conn . _transport ) <EOL> transport . synchronous = True <EOL> assert_false ( conn . _synchronous ) <EOL> assert_true ( conn . synchronous ) <EOL> assert_true ( conn . _synchronous_connect ) <EOL> def test_init_with_event_transport ( self ) : <EOL> conn = Connection . __new__ ( Connection ) <EOL> strategy = mock ( ) <EOL> transport = mock ( ) <EOL> mock ( connection , '<STR_LIT>' ) <EOL> expect ( connection . ConnectionChannel ) . args ( <EOL> conn , <NUM_LIT:0> , { } ) . returns ( '<STR_LIT>' ) <EOL> expect ( event_transport . EventTransport ) . args ( conn ) . returns ( transport ) <EOL> expect ( conn . connect ) . args ( '<STR_LIT:localhost>' , <NUM_LIT> ) <EOL> conn . __init__ ( transport = '<STR_LIT>' ) <EOL> def test_properties ( self ) : <EOL> assert_equal ( self . connection . _logger , self . connection . logger ) <EOL> assert_equal ( self . connection . _debug , self . connection . debug ) <EOL> assert_equal ( self . connection . _frame_max , self . connection . frame_max ) <EOL> assert_equal ( self . connection . _channel_max , self . connection . channel_max ) <EOL> assert_equal ( self . connection . _frames_read , self . connection . frames_read ) <EOL> assert_equal ( <EOL> self . connection . _frames_written , self . connection . frames_written ) <EOL> assert_equal ( self . connection . _closed , self . connection . closed ) <EOL> def test_synchronous_when_no_transport ( self ) : <EOL> self . connection . _transport = None <EOL> with assert_raises ( connection . ConnectionClosed ) : <EOL> self . connection . synchronous <EOL> self . connection . _close_info = { <EOL> '<STR_LIT>' : <NUM_LIT:100> , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> with assert_raises ( connection . ConnectionClosed ) : <EOL> self . connection . synchronous <EOL> def test_synchronous_when_transport ( self ) : <EOL> self . connection . _transport . synchronous = True <EOL> assert_true ( self . connection . synchronous ) <EOL> self . connection . _transport . synchronous = False <EOL> assert_false ( self . connection . synchronous ) <EOL> def test_connect_when_asynchronous_transport ( self ) : <EOL> self . connection . _transport . synchronous = False <EOL> self . connection . _connected = '<STR_LIT>' <EOL> self . connection . _closed = '<STR_LIT>' <EOL> self . connection . _debug = '<STR_LIT>' <EOL> self . connection . _connect_timeout = <NUM_LIT> <EOL> self . connection . _sock_opts = { <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) : <NUM_LIT:5> , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) : <NUM_LIT:6> <EOL> } <EOL> expect ( self . connection . _transport . connect ) . args ( ( '<STR_LIT:host>' , <NUM_LIT> ) ) <EOL> expect ( self . connection . _transport . write ) . args ( '<STR_LIT>' ) <EOL> self . connection . connect ( '<STR_LIT:host>' , <NUM_LIT> ) <EOL> assert_false ( self . connection . _connected ) <EOL> assert_false ( self . connection . _closed ) <EOL> assert_equals ( self . connection . _close_info , <EOL> { <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:0> <EOL> } ) <EOL> assert_equals ( '<STR_LIT>' , self . connection . _host ) <EOL> def test_connect_when_asynchronous_transport_but_synchronous_connect ( self ) : <EOL> self . connection . _transport . synchronous = False <EOL> self . connection . _synchronous_connect = True <EOL> self . connection . _connected = '<STR_LIT>' <EOL> self . connection . _closed = '<STR_LIT>' <EOL> self . connection . _debug = '<STR_LIT>' <EOL> self . connection . _connect_timeout = <NUM_LIT> <EOL> self . connection . _sock_opts = { <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) : <NUM_LIT:5> , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) : <NUM_LIT:6> <EOL> } <EOL> expect ( self . connection . _transport . connect ) . args ( ( '<STR_LIT:host>' , <NUM_LIT> ) ) <EOL> expect ( self . connection . _transport . write ) . args ( '<STR_LIT>' ) <EOL> expect ( self . connection . _channels [ <NUM_LIT:0> ] . add_synchronous_cb ) . args ( <EOL> self . connection . _channels [ <NUM_LIT:0> ] . _recv_start ) <EOL> expect ( self . connection . read_frames ) <EOL> expect ( self . connection . read_frames ) . side_effect ( <EOL> lambda : setattr ( self . connection , '<STR_LIT>' , True ) ) <EOL> self . connection . connect ( '<STR_LIT:host>' , <NUM_LIT> ) <EOL> assert_true ( self . connection . _connected ) <EOL> assert_false ( self . connection . _closed ) <EOL> assert_equals ( self . connection . _close_info , <EOL> { <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:0> <EOL> } ) <EOL> assert_equals ( '<STR_LIT>' , self . connection . _host ) <EOL> def test_connect_when_synchronous_transport ( self ) : <EOL> self . connection . _transport . synchronous = True <EOL> self . connection . _synchronous_connect = True <EOL> self . connection . _connected = '<STR_LIT>' <EOL> self . connection . _closed = '<STR_LIT>' <EOL> self . connection . _debug = '<STR_LIT>' <EOL> self . connection . _connect_timeout = <NUM_LIT> <EOL> self . connection . _sock_opts = { <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) : <NUM_LIT:5> , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) : <NUM_LIT:6> <EOL> } <EOL> expect ( self . connection . _transport . connect ) . args ( ( '<STR_LIT:host>' , <NUM_LIT> ) ) <EOL> expect ( self . connection . _transport . write ) . args ( '<STR_LIT>' ) <EOL> expect ( self . connection . _channels [ <NUM_LIT:0> ] . add_synchronous_cb ) <EOL> expect ( self . connection . read_frames ) <EOL> expect ( self . connection . read_frames ) . side_effect ( <EOL> lambda : setattr ( self . connection , '<STR_LIT>' , True ) ) <EOL> self . connection . connect ( '<STR_LIT:host>' , <NUM_LIT> ) <EOL> assert_true ( self . connection . _connected ) <EOL> assert_false ( self . connection . _closed ) <EOL> assert_equals ( self . connection . _close_info , <EOL> { <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:0> <EOL> } ) <EOL> assert_equals ( '<STR_LIT>' , self . connection . _host ) <EOL> def test_disconnect_when_transport_disconnects ( self ) : <EOL> self . connection . _connected = '<STR_LIT>' <EOL> expect ( self . connection . _transport . disconnect ) <EOL> self . connection . disconnect ( ) <EOL> assert_false ( self . connection . _connected ) <EOL> assert_equals ( None , self . connection . _transport ) <EOL> def test_disconnect_when_transport_disconnects_with_error ( self ) : <EOL> self . connection . _connected = '<STR_LIT>' <EOL> self . connection . _host = '<STR_LIT>' <EOL> expect ( self . connection . _transport . disconnect ) . raises ( <EOL> RuntimeError ( '<STR_LIT>' ) ) <EOL> expect ( self . connection . logger . error ) . args ( <EOL> "<STR_LIT>" , '<STR_LIT>' , exc_info = True ) <EOL> assert_raises ( RuntimeError , self . connection . disconnect ) <EOL> assert_false ( self . connection . _connected ) <EOL> assert_equals ( None , self . connection . _transport ) <EOL> def test_disconnect_when_systemexit ( self ) : <EOL> self . connection . _connected = '<STR_LIT>' <EOL> self . connection . _host = '<STR_LIT>' <EOL> expect ( self . connection . _transport . disconnect ) . raises ( SystemExit ( ) ) <EOL> stub ( self . connection . logger . error ) <EOL> assert_raises ( SystemExit , self . connection . disconnect ) <EOL> assert_false ( self . connection . _connected ) <EOL> assert_equals ( None , self . connection . _transport ) <EOL> def test_transport_closed_with_no_args ( self ) : <EOL> self . connection . _host = '<STR_LIT>' <EOL> self . connection . _connected = '<STR_LIT:yes>' <EOL> expect ( self . connection . logger . warning ) . args ( <EOL> '<STR_LIT>' ) <EOL> expect ( self . connection . _callback_close ) <EOL> self . connection . transport_closed ( ) <EOL> assert_equals ( <NUM_LIT:0> , self . connection . _close_info [ '<STR_LIT>' ] ) <EOL> assert_equals ( <EOL> '<STR_LIT>' , self . connection . _close_info [ '<STR_LIT>' ] ) <EOL> assert_equals ( <NUM_LIT:0> , self . connection . _close_info [ '<STR_LIT>' ] ) <EOL> assert_equals ( <NUM_LIT:0> , self . connection . _close_info [ '<STR_LIT>' ] ) <EOL> def test_next_channel_id_when_less_than_max ( self ) : <EOL> self . connection . _channel_counter = <NUM_LIT:32> <EOL> self . connection . _channel_max = <NUM_LIT> <EOL> assert_equals ( <NUM_LIT> , self . connection . _next_channel_id ( ) ) <EOL> def test_next_channel_id_when_at_max ( self ) : <EOL> self . connection . _channel_counter = <NUM_LIT:32> <EOL> self . connection . _channel_max = <NUM_LIT:32> <EOL> assert_equals ( <NUM_LIT:1> , self . connection . _next_channel_id ( ) ) <EOL> def test_channel_creates_new_when_not_at_limit ( self ) : <EOL> ch = mock ( ) <EOL> expect ( self . connection . _next_channel_id ) . returns ( <NUM_LIT:1> ) <EOL> mock ( connection , '<STR_LIT>' ) <EOL> expect ( connection . Channel ) . args ( <EOL> self . connection , <NUM_LIT:1> , self . connection . _class_map , synchronous = False ) . returns ( ch ) <EOL> expect ( ch . add_close_listener ) . args ( self . connection . _channel_closed ) <EOL> expect ( ch . open ) <EOL> assert_equals ( ch , self . connection . channel ( ) ) <EOL> assert_equals ( ch , self . connection . _channels [ <NUM_LIT:1> ] ) <EOL> def test_channel_creates_optionally_synchronous ( self ) : <EOL> ch = mock ( ) <EOL> expect ( self . connection . _next_channel_id ) . returns ( <NUM_LIT:1> ) <EOL> mock ( connection , '<STR_LIT>' ) <EOL> expect ( connection . Channel ) . args ( <EOL> self . connection , <NUM_LIT:1> , self . connection . _class_map , synchronous = True ) . returns ( ch ) <EOL> expect ( ch . add_close_listener ) . args ( self . connection . _channel_closed ) <EOL> expect ( ch . open ) <EOL> assert_equals ( ch , self . connection . channel ( synchronous = True ) ) <EOL> assert_equals ( ch , self . connection . _channels [ <NUM_LIT:1> ] ) <EOL> def test_channel_finds_the_first_free_channel_id ( self ) : <EOL> self . connection . _channels [ <NUM_LIT:1> ] = '<STR_LIT:foo>' <EOL> self . connection . _channels [ <NUM_LIT:2> ] = '<STR_LIT:bar>' <EOL> self . connection . _channels [ <NUM_LIT:4> ] = '<STR_LIT>' <EOL> ch = mock ( ) <EOL> expect ( self . connection . _next_channel_id ) . returns ( <NUM_LIT:1> ) <EOL> expect ( self . connection . _next_channel_id ) . returns ( <NUM_LIT:2> ) <EOL> expect ( self . connection . _next_channel_id ) . returns ( <NUM_LIT:3> ) <EOL> mock ( connection , '<STR_LIT>' ) <EOL> expect ( connection . Channel ) . args ( <EOL> self . connection , <NUM_LIT:3> , self . connection . _class_map , synchronous = False ) . returns ( ch ) <EOL> expect ( ch . add_close_listener ) . args ( self . connection . _channel_closed ) <EOL> expect ( ch . open ) <EOL> assert_equals ( ch , self . connection . channel ( ) ) <EOL> assert_equals ( ch , self . connection . _channels [ <NUM_LIT:3> ] ) <EOL> def test_channel_raises_toomanychannels ( self ) : <EOL> self . connection . _channels [ <NUM_LIT:1> ] = '<STR_LIT:foo>' <EOL> self . connection . _channels [ <NUM_LIT:2> ] = '<STR_LIT:bar>' <EOL> self . connection . _channels [ <NUM_LIT:4> ] = '<STR_LIT>' <EOL> self . connection . _channel_max = <NUM_LIT:3> <EOL> assert_raises ( Connection . TooManyChannels , self . connection . channel ) <EOL> def test_channel_returns_cached_instance_if_known ( self ) : <EOL> self . connection . _channels [ <NUM_LIT:1> ] = '<STR_LIT:foo>' <EOL> assert_equals ( '<STR_LIT:foo>' , self . connection . channel ( <NUM_LIT:1> ) ) <EOL> def test_channel_raises_invalidchannel_if_unknown_id ( self ) : <EOL> assert_raises ( Connection . InvalidChannel , self . connection . channel , <NUM_LIT> ) <EOL> def test_channel_closed ( self ) : <EOL> ch = mock ( ) <EOL> ch . channel_id = <NUM_LIT> <EOL> self . connection . _channels [ <NUM_LIT> ] = ch <EOL> self . connection . _channel_closed ( ch ) <EOL> assert_false ( <NUM_LIT> in self . connection . _channels ) <EOL> ch . channel_id = <NUM_LIT> <EOL> self . connection . _channel_closed ( ch ) <EOL> def test_close ( self ) : <EOL> self . connection . _channels [ <NUM_LIT:0> ] = mock ( ) <EOL> expect ( self . connection . _channels [ <NUM_LIT:0> ] . close ) <EOL> self . connection . close ( ) <EOL> assert_equals ( { '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> } , <EOL> self . connection . _close_info ) <EOL> self . connection . close ( <NUM_LIT:1> , '<STR_LIT:foo>' , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> assert_equals ( { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : '<STR_LIT:foo>' , '<STR_LIT>' : <NUM_LIT:2> , '<STR_LIT>' : <NUM_LIT:3> } , <EOL> self . connection . _close_info ) <EOL> def test_close_when_disconnect ( self ) : <EOL> self . connection . _channels [ <NUM_LIT:0> ] = mock ( ) <EOL> stub ( self . connection . _channels [ <NUM_LIT:0> ] . close ) <EOL> assert_false ( self . connection . _closed ) <EOL> expect ( self . connection . disconnect ) <EOL> expect ( self . connection . _callback_close ) <EOL> self . connection . close ( <NUM_LIT:1> , '<STR_LIT:foo>' , <NUM_LIT:2> , <NUM_LIT:3> , disconnect = True ) <EOL> assert_true ( self . connection . _closed ) <EOL> assert_equals ( { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : '<STR_LIT:foo>' , '<STR_LIT>' : <NUM_LIT:2> , '<STR_LIT>' : <NUM_LIT:3> } , <EOL> self . connection . _close_info ) <EOL> def test_callback_open_when_no_cb ( self ) : <EOL> self . connection . _open_cb = None <EOL> self . connection . _callback_open ( ) <EOL> def test_callback_open_when_user_cb ( self ) : <EOL> self . connection . _open_cb = mock ( ) <EOL> expect ( self . connection . _open_cb ) <EOL> self . connection . _callback_open ( ) <EOL> def test_callback_open_raises_when_user_cb_does ( self ) : <EOL> self . connection . _open_cb = mock ( ) <EOL> expect ( self . connection . _open_cb ) . raises ( SystemExit ( ) ) <EOL> assert_raises ( SystemExit , self . connection . _callback_open ) <EOL> def test_callback_close_when_no_cb ( self ) : <EOL> self . connection . _close_cb = None <EOL> self . connection . _callback_close ( ) <EOL> def test_callback_close_when_user_cb ( self ) : <EOL> self . connection . _close_cb = mock ( ) <EOL> expect ( self . connection . _close_cb ) <EOL> self . connection . _callback_close ( ) <EOL> def test_callback_close_raises_when_user_cb_does ( self ) : <EOL> self . connection . _close_cb = mock ( ) <EOL> expect ( self . connection . _close_cb ) . raises ( SystemExit ( ) ) <EOL> assert_raises ( SystemExit , self . connection . _callback_close ) <EOL> def test_read_frames_when_no_transport ( self ) : <EOL> self . connection . _transport = None <EOL> self . connection . read_frames ( ) <EOL> assert_equals ( <NUM_LIT:0> , self . connection . _frames_read ) <EOL> def test_read_frames_when_transport_returns_no_data ( self ) : <EOL> self . connection . _heartbeat = None <EOL> expect ( self . connection . _channels [ <NUM_LIT:0> ] . send_heartbeat ) <EOL> expect ( self . connection . _transport . read ) . args ( None ) . returns ( None ) <EOL> self . connection . read_frames ( ) <EOL> assert_equals ( <NUM_LIT:0> , self . connection . _frames_read ) <EOL> def test_read_frames_when_transport_when_frame_data_and_no_debug_and_no_buffer ( self ) : <EOL> reader = mock ( ) <EOL> frame = mock ( ) <EOL> frame . channel_id = <NUM_LIT> <EOL> channel = mock ( ) <EOL> mock ( connection , '<STR_LIT>' ) <EOL> self . connection . _heartbeat = <NUM_LIT:3> <EOL> expect ( self . connection . _channels [ <NUM_LIT:0> ] . send_heartbeat ) <EOL> expect ( self . connection . _transport . read ) . args ( <NUM_LIT:3> ) . returns ( '<STR_LIT:data>' ) <EOL> expect ( connection . Reader ) . args ( '<STR_LIT:data>' ) . returns ( reader ) <EOL> expect ( connection . Frame . read_frames ) . args ( reader ) . returns ( [ frame ] ) <EOL> expect ( self . connection . channel ) . args ( <NUM_LIT> ) . returns ( channel ) <EOL> expect ( channel . buffer_frame ) . args ( frame ) <EOL> expect ( self . connection . _transport . process_channels ) . args ( <EOL> set ( [ channel ] ) ) <EOL> expect ( reader . tell ) . returns ( <NUM_LIT:4> ) <EOL> self . connection . read_frames ( ) <EOL> assert_equals ( <NUM_LIT:1> , self . connection . _frames_read ) <EOL> def test_read_frames_when_transport_when_frame_data_and_debug_and_buffer ( self ) : <EOL> reader = mock ( ) <EOL> frame = mock ( ) <EOL> frame . channel_id = <NUM_LIT> <EOL> channel = mock ( ) <EOL> mock ( connection , '<STR_LIT>' ) <EOL> self . connection . _debug = <NUM_LIT:2> <EOL> expect ( self . connection . _channels [ <NUM_LIT:0> ] . send_heartbeat ) <EOL> expect ( self . connection . _transport . read ) . args ( None ) . returns ( '<STR_LIT:data>' ) <EOL> expect ( connection . Reader ) . args ( '<STR_LIT:data>' ) . returns ( reader ) <EOL> expect ( connection . Frame . read_frames ) . args ( reader ) . returns ( [ frame ] ) <EOL> expect ( self . connection . logger . debug ) . args ( '<STR_LIT>' , frame ) <EOL> expect ( self . connection . channel ) . args ( <NUM_LIT> ) . returns ( channel ) <EOL> expect ( channel . buffer_frame ) . args ( frame ) <EOL> expect ( self . connection . _transport . process_channels ) . args ( <EOL> set ( [ channel ] ) ) <EOL> expect ( reader . tell ) . times ( <NUM_LIT:2> ) . returns ( <NUM_LIT:2> ) <EOL> expect ( self . connection . _transport . buffer ) . args ( '<STR_LIT>' ) <EOL> self . connection . read_frames ( ) <EOL> assert_equals ( <NUM_LIT:1> , self . connection . _frames_read ) <EOL> def test_read_frames_when_read_frame_error ( self ) : <EOL> reader = mock ( ) <EOL> frame = mock ( ) <EOL> frame . channel_id = <NUM_LIT> <EOL> channel = mock ( ) <EOL> mock ( connection , '<STR_LIT>' ) <EOL> self . connection . _heartbeat = <NUM_LIT:3> <EOL> expect ( self . connection . _channels [ <NUM_LIT:0> ] . send_heartbeat ) <EOL> expect ( self . connection . _transport . read ) . args ( <NUM_LIT:3> ) . returns ( '<STR_LIT:data>' ) <EOL> expect ( connection . Reader ) . args ( '<STR_LIT:data>' ) . returns ( reader ) <EOL> expect ( connection . Frame . read_frames ) . args ( <EOL> reader ) . raises ( Frame . FrameError ) <EOL> stub ( self . connection . channel ) <EOL> stub ( channel . buffer_frame ) <EOL> stub ( self . connection . _transport . process_channels ) <EOL> stub ( reader . tell ) <EOL> stub ( self . connection . _transport . buffer ) <EOL> expect ( self . connection . close ) . args ( <EOL> reply_code = <NUM_LIT> , reply_text = str , class_id = <NUM_LIT:0> , method_id = <NUM_LIT:0> , disconnect = True ) <EOL> assert_raises ( ConnectionError , self . connection . read_frames ) <EOL> def test_flush_buffered_frames ( self ) : <EOL> self . connection . _output_frame_buffer = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> expect ( self . connection . send_frame ) . args ( '<STR_LIT>' ) <EOL> expect ( self . connection . send_frame ) . args ( '<STR_LIT>' ) <EOL> self . connection . _flush_buffered_frames ( ) <EOL> assert_equals ( [ ] , self . connection . _output_frame_buffer ) <EOL> def test_send_frame_when_connected_and_transport_and_no_debug ( self ) : <EOL> frame = mock ( ) <EOL> expect ( frame . write_frame ) . args ( var ( '<STR_LIT>' ) ) <EOL> expect ( self . connection . _transport . write ) . args ( var ( '<STR_LIT>' ) ) <EOL> self . connection . _connected = True <EOL> self . connection . send_frame ( frame ) <EOL> assert_true ( isinstance ( var ( '<STR_LIT>' ) . value , bytearray ) ) <EOL> assert_equals ( <NUM_LIT:1> , self . connection . _frames_written ) <EOL> def test_send_frame_when_not_connected_and_not_channel_0 ( self ) : <EOL> frame = mock ( ) <EOL> frame . channel_id = <NUM_LIT> <EOL> stub ( frame . write_frame ) <EOL> stub ( self . connection . _transport . write ) <EOL> self . connection . _connected = False <EOL> self . connection . send_frame ( frame ) <EOL> assert_equals ( [ frame ] , self . connection . _output_frame_buffer ) <EOL> def test_send_frame_when_not_connected_and_channel_0 ( self ) : <EOL> frame = mock ( ) <EOL> frame . channel_id = <NUM_LIT:0> <EOL> expect ( frame . write_frame ) . args ( var ( '<STR_LIT>' ) ) <EOL> expect ( self . connection . _transport . write ) . args ( var ( '<STR_LIT>' ) ) <EOL> self . connection . _connected = False <EOL> self . connection . send_frame ( frame ) <EOL> assert_true ( isinstance ( var ( '<STR_LIT>' ) . value , bytearray ) ) <EOL> assert_equals ( <NUM_LIT:1> , self . connection . _frames_written ) <EOL> def test_send_frame_when_debugging ( self ) : <EOL> frame = mock ( ) <EOL> expect ( self . connection . logger . debug ) . args ( '<STR_LIT>' , frame ) <EOL> expect ( frame . write_frame ) . args ( var ( '<STR_LIT>' ) ) <EOL> expect ( self . connection . _transport . write ) . args ( var ( '<STR_LIT>' ) ) <EOL> self . connection . _connected = True <EOL> self . connection . _debug = <NUM_LIT:2> <EOL> self . connection . send_frame ( frame ) <EOL> assert_true ( isinstance ( var ( '<STR_LIT>' ) . value , bytearray ) ) <EOL> assert_equals ( <NUM_LIT:1> , self . connection . _frames_written ) <EOL> def test_send_frame_when_closed ( self ) : <EOL> self . connection . _closed = True <EOL> self . connection . _close_info [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> assert_raises ( connection . ConnectionClosed , <EOL> self . connection . send_frame , '<STR_LIT>' ) <EOL> self . connection . _close_info [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> assert_raises ( connection . ConnectionClosed , <EOL> self . connection . send_frame , '<STR_LIT>' ) <EOL> self . connection . _close_info = None <EOL> assert_raises ( connection . ConnectionClosed , <EOL> self . connection . send_frame , '<STR_LIT>' ) <EOL> def test_send_frame_when_frame_overflow ( self ) : <EOL> frame = mock ( ) <EOL> self . connection . _frame_max = <NUM_LIT:100> <EOL> expect ( frame . write_frame ) . side_effect ( <EOL> lambda buf : buf . extend ( '<STR_LIT:a>' * <NUM_LIT:200> ) ) <EOL> expect ( self . connection . close ) . args ( <EOL> reply_code = <NUM_LIT> , reply_text = var ( '<STR_LIT>' ) , class_id = <NUM_LIT:0> , method_id = <NUM_LIT:0> , disconnect = True ) <EOL> stub ( self . connection . _transport . write ) <EOL> self . connection . _connected = True <EOL> with assert_raises ( ConnectionClosed ) : <EOL> self . connection . send_frame ( frame ) <EOL> class ConnectionChannelTest ( Chai ) : <EOL> def setUp ( self ) : <EOL> super ( ConnectionChannelTest , self ) . setUp ( ) <EOL> self . connection = mock ( ) <EOL> self . ch = ConnectionChannel ( self . connection , <NUM_LIT:0> , { } ) <EOL> def test_init ( self ) : <EOL> mock ( connection , '<STR_LIT>' ) <EOL> with expect ( connection , '<STR_LIT>' ) . args ( is_arg ( ConnectionChannel ) , ConnectionChannel ) . returns ( mock ( ) ) as s : <EOL> expect ( s . __init__ ) . args ( '<STR_LIT:a>' , '<STR_LIT:b>' ) <EOL> c = ConnectionChannel ( '<STR_LIT:a>' , '<STR_LIT:b>' ) <EOL> assert_equals ( c . _method_map , <EOL> { <EOL> <NUM_LIT:10> : c . _recv_start , <EOL> <NUM_LIT:20> : c . _recv_secure , <EOL> <NUM_LIT:30> : c . _recv_tune , <EOL> <NUM_LIT> : c . _recv_open_ok , <EOL> <NUM_LIT:50> : c . _recv_close , <EOL> <NUM_LIT> : c . _recv_close_ok , <EOL> } <EOL> ) <EOL> assert_equal ( <NUM_LIT:0> , c . _last_heartbeat_send ) <EOL> def test_dispatch_on_heartbeat_frame ( self ) : <EOL> frame = mock ( ) <EOL> expect ( frame . type ) . returns ( HeartbeatFrame . type ( ) ) <EOL> expect ( self . ch . send_heartbeat ) <EOL> self . ch . dispatch ( frame ) <EOL> def test_dispatch_method_frame_class_10 ( self ) : <EOL> frame = mock ( ) <EOL> frame . class_id = <NUM_LIT:10> <EOL> frame . method_id = <NUM_LIT:10> <EOL> method = self . ch . _method_map [ <NUM_LIT:10> ] = mock ( ) <EOL> expect ( frame . type ) . returns ( MethodFrame . type ( ) ) <EOL> expect ( method ) . args ( frame ) <EOL> self . ch . dispatch ( frame ) <EOL> def test_dispatch_runs_callbacks ( self ) : <EOL> frame = mock ( ) <EOL> frame . class_id = <NUM_LIT:10> <EOL> frame . method_id = <NUM_LIT:10> <EOL> method = self . ch . _method_map [ <NUM_LIT:10> ] = mock ( ) <EOL> cb = mock ( ) <EOL> expect ( frame . type ) . returns ( MethodFrame . type ( ) ) <EOL> expect ( self . ch . clear_synchronous_cb ) . args ( method ) . returns ( cb ) <EOL> expect ( cb ) . args ( frame ) <EOL> self . ch . dispatch ( frame ) <EOL> def test_dispatch_method_frame_raises_invalidmethod ( self ) : <EOL> frame = mock ( ) <EOL> frame . class_id = <NUM_LIT:10> <EOL> frame . method_id = <NUM_LIT> <EOL> expect ( frame . type ) . returns ( MethodFrame . type ( ) ) <EOL> with assert_raises ( Channel . InvalidMethod ) : <EOL> self . ch . dispatch ( frame ) <EOL> def test_dispatch_method_frame_raises_invalidclass ( self ) : <EOL> frame = mock ( ) <EOL> frame . class_id = <NUM_LIT:11> <EOL> frame . method_id = <NUM_LIT:10> <EOL> expect ( frame . type ) . returns ( MethodFrame . type ( ) ) <EOL> with assert_raises ( Channel . InvalidClass ) : <EOL> self . ch . dispatch ( frame ) <EOL> def test_dispatch_method_frame_raises_invalidframetype ( self ) : <EOL> frame = mock ( ) <EOL> expect ( frame . type ) . returns ( HeaderFrame . type ( ) ) <EOL> with assert_raises ( Frame . InvalidFrameType ) : <EOL> self . ch . dispatch ( frame ) <EOL> def test_close ( self ) : <EOL> expect ( self . ch . _send_close ) <EOL> self . ch . close ( ) <EOL> def test_send_heartbeat_when_no_heartbeat ( self ) : <EOL> stub ( self . ch . send_frame ) <EOL> self . ch . connection . _heartbeat = None <EOL> self . ch . send_heartbeat ( ) <EOL> def test_send_heartbeat_when_not_sent_yet ( self ) : <EOL> mock ( connection , '<STR_LIT:time>' ) <EOL> self . ch . connection . _heartbeat = <NUM_LIT:3> <EOL> self . ch . _last_heartbeat_send = <NUM_LIT:0> <EOL> expect ( connection . time . time ) . returns ( <NUM_LIT> ) . times ( <NUM_LIT:2> ) <EOL> expect ( self . ch . send_frame ) . args ( HeartbeatFrame ) <EOL> self . ch . send_heartbeat ( ) <EOL> assert_equals ( <NUM_LIT> , self . ch . _last_heartbeat_send ) <EOL> def test_send_heartbeat_when_sent_long_ago ( self ) : <EOL> mock ( connection , '<STR_LIT:time>' ) <EOL> self . ch . connection . _heartbeat = <NUM_LIT:3> <EOL> self . ch . _last_heartbeat_send = <NUM_LIT> <EOL> expect ( connection . time . time ) . returns ( <NUM_LIT> ) . times ( <NUM_LIT:2> ) <EOL> expect ( self . ch . send_frame ) . args ( HeartbeatFrame ) <EOL> self . ch . send_heartbeat ( ) <EOL> assert_equals ( <NUM_LIT> , self . ch . _last_heartbeat_send ) <EOL> def test_send_heart_when_sent_recently ( self ) : <EOL> mock ( connection , '<STR_LIT:time>' ) <EOL> self . ch . connection . _heartbeat = <NUM_LIT:3> <EOL> self . ch . _last_heartbeat_send = <NUM_LIT> <EOL> expect ( connection . time . time ) . returns ( <NUM_LIT> ) <EOL> stub ( self . ch . send_frame ) <EOL> self . ch . send_heartbeat ( ) <EOL> assert_equals ( <NUM_LIT> , self . ch . _last_heartbeat_send ) <EOL> def test_recv_start ( self ) : <EOL> expect ( self . ch . _send_start_ok ) <EOL> self . ch . connection . _closed = '<STR_LIT>' <EOL> self . ch . _recv_start ( '<STR_LIT>' ) <EOL> assert_false ( self . ch . connection . _closed ) <EOL> def test_send_start_ok ( self ) : <EOL> self . ch . connection . _properties = '<STR_LIT>' <EOL> self . ch . connection . _login_method = '<STR_LIT>' <EOL> self . ch . connection . _login_response = '<STR_LIT>' <EOL> self . ch . connection . _locale = '<STR_LIT>' <EOL> with expect ( mock ( connection , '<STR_LIT>' ) ) . returns ( mock ( ) ) as writer : <EOL> expect ( writer . write_table ) . args ( '<STR_LIT>' ) <EOL> expect ( writer . write_shortstr ) . args ( '<STR_LIT>' ) <EOL> expect ( writer . write_longstr ) . args ( '<STR_LIT>' ) <EOL> expect ( writer . write_shortstr ) . args ( '<STR_LIT>' ) <EOL> expect ( mock ( connection , '<STR_LIT>' ) ) . args ( <EOL> <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT:11> , writer ) . returns ( '<STR_LIT>' ) <EOL> expect ( self . ch . send_frame ) . args ( '<STR_LIT>' ) <EOL> expect ( self . ch . add_synchronous_cb ) . args ( self . ch . _recv_tune ) <EOL> self . ch . _send_start_ok ( ) <EOL> def test_recv_tune_when_no_broker_max_and_defined_heartbeat ( self ) : <EOL> self . ch . connection . _channel_max = <NUM_LIT> <EOL> self . ch . connection . _frame_max = <NUM_LIT> <EOL> self . ch . connection . _heartbeat = <NUM_LIT:8> <EOL> frame = mock ( ) <EOL> expect ( frame . args . read_short ) . returns ( <NUM_LIT:0> ) <EOL> expect ( frame . args . read_long ) . returns ( <NUM_LIT:0> ) <EOL> expect ( self . ch . _send_tune_ok ) <EOL> expect ( self . ch . _send_open ) <EOL> expect ( self . ch . send_heartbeat ) <EOL> self . ch . _recv_tune ( frame ) <EOL> assert_equals ( <NUM_LIT> , self . ch . connection . _channel_max ) <EOL> assert_equals ( <NUM_LIT> , self . ch . connection . _frame_max ) <EOL> assert_equals ( <NUM_LIT:8> , self . ch . connection . _heartbeat ) <EOL> def test_recv_tune_when_broker_max_and_undefined_heartbeat ( self ) : <EOL> self . ch . connection . _channel_max = <NUM_LIT> <EOL> self . ch . connection . _frame_max = <NUM_LIT> <EOL> self . ch . connection . _heartbeat = None <EOL> frame = mock ( ) <EOL> expect ( frame . args . read_short ) . returns ( <NUM_LIT> ) <EOL> expect ( frame . args . read_long ) . returns ( <NUM_LIT> ) <EOL> expect ( frame . args . read_short ) . returns ( <NUM_LIT:7> ) <EOL> expect ( self . ch . _send_tune_ok ) <EOL> expect ( self . ch . _send_open ) <EOL> expect ( self . ch . send_heartbeat ) <EOL> self . ch . _recv_tune ( frame ) <EOL> assert_equals ( <NUM_LIT> , self . ch . connection . _channel_max ) <EOL> assert_equals ( <NUM_LIT> , self . ch . connection . _frame_max ) <EOL> assert_equals ( <NUM_LIT:7> , self . ch . connection . _heartbeat ) <EOL> def test_send_tune_ok_when_heartbeat ( self ) : <EOL> self . ch . connection . _channel_max = <NUM_LIT> <EOL> self . ch . connection . _frame_max = <NUM_LIT> <EOL> self . ch . connection . _heartbeat = <NUM_LIT:8> <EOL> with expect ( mock ( connection , '<STR_LIT>' ) ) . returns ( mock ( ) ) as writer : <EOL> expect ( writer . write_short ) . args ( <NUM_LIT> ) <EOL> expect ( writer . write_long ) . args ( <NUM_LIT> ) <EOL> expect ( writer . write_short ) . args ( <NUM_LIT:8> ) <EOL> expect ( mock ( connection , '<STR_LIT>' ) ) . args ( <EOL> <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT> , writer ) . returns ( '<STR_LIT>' ) <EOL> expect ( self . ch . send_frame ) . args ( '<STR_LIT>' ) <EOL> self . ch . _send_tune_ok ( ) <EOL> def test_send_tune_ok_when_no_heartbeat ( self ) : <EOL> self . ch . connection . _channel_max = <NUM_LIT> <EOL> self . ch . connection . _frame_max = <NUM_LIT> <EOL> self . ch . connection . _heartbeat = None <EOL> with expect ( mock ( connection , '<STR_LIT>' ) ) . returns ( mock ( ) ) as writer : <EOL> expect ( writer . write_short ) . args ( <NUM_LIT> ) <EOL> expect ( writer . write_long ) . args ( <NUM_LIT> ) <EOL> expect ( writer . write_short ) . args ( <NUM_LIT:0> ) <EOL> expect ( mock ( connection , '<STR_LIT>' ) ) . args ( <EOL> <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT> , writer ) . returns ( '<STR_LIT>' ) <EOL> expect ( self . ch . send_frame ) . args ( '<STR_LIT>' ) <EOL> self . ch . _send_tune_ok ( ) <EOL> def test_recv_secure ( self ) : <EOL> expect ( self . ch . _send_open ) <EOL> self . ch . _recv_secure ( '<STR_LIT>' ) <EOL> def test_send_open ( self ) : <EOL> self . connection . _vhost = '<STR_LIT>' <EOL> with expect ( mock ( connection , '<STR_LIT>' ) ) . returns ( mock ( ) ) as writer : <EOL> expect ( writer . write_shortstr ) . args ( '<STR_LIT>' ) <EOL> expect ( writer . write_shortstr ) . args ( '<STR_LIT>' ) <EOL> expect ( writer . write_bit ) . args ( True ) <EOL> expect ( mock ( connection , '<STR_LIT>' ) ) . args ( <EOL> <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT> , writer ) . returns ( '<STR_LIT>' ) <EOL> expect ( self . ch . send_frame ) . args ( '<STR_LIT>' ) <EOL> expect ( self . ch . add_synchronous_cb ) . args ( self . ch . _recv_open_ok ) <EOL> self . ch . _send_open ( ) <EOL> def test_recv_open_ok ( self ) : <EOL> self . ch . connection . _connected = False <EOL> expect ( self . ch . connection . _flush_buffered_frames ) <EOL> expect ( self . ch . connection . _callback_open ) <EOL> self . ch . _recv_open_ok ( '<STR_LIT>' ) <EOL> assert_true ( self . ch . connection . _connected ) <EOL> def test_send_close ( self ) : <EOL> self . ch . connection . _close_info = { <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' * <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT:4> , <EOL> '<STR_LIT>' : <NUM_LIT:20> , <EOL> } <EOL> with expect ( mock ( connection , '<STR_LIT>' ) ) . returns ( mock ( ) ) as writer : <EOL> expect ( writer . write_short ) . args ( <NUM_LIT> ) <EOL> expect ( writer . write_shortstr ) . args ( ( '<STR_LIT>' * <NUM_LIT> ) [ : <NUM_LIT:255> ] ) <EOL> expect ( writer . write_short ) . args ( <NUM_LIT:4> ) <EOL> expect ( writer . write_short ) . args ( <NUM_LIT:20> ) <EOL> expect ( mock ( connection , '<STR_LIT>' ) ) . args ( <EOL> <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT:50> , writer ) . returns ( '<STR_LIT>' ) <EOL> expect ( self . ch . send_frame ) . args ( '<STR_LIT>' ) <EOL> expect ( self . ch . add_synchronous_cb ) . args ( self . ch . _recv_close_ok ) <EOL> self . ch . _send_close ( ) <EOL> def test_recv_close ( self ) : <EOL> self . ch . connection . _closed = False <EOL> frame = mock ( ) <EOL> expect ( frame . args . read_short ) . returns ( <NUM_LIT> ) <EOL> expect ( frame . args . read_shortstr ) . returns ( '<STR_LIT>' ) <EOL> expect ( frame . args . read_short ) . returns ( <NUM_LIT:4> ) <EOL> expect ( frame . args . read_short ) . returns ( <NUM_LIT:20> ) <EOL> expect ( self . ch . _send_close_ok ) <EOL> expect ( self . ch . connection . disconnect ) <EOL> expect ( self . ch . connection . _callback_close ) <EOL> self . ch . _recv_close ( frame ) <EOL> assert_equals ( self . ch . connection . _close_info , { <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:4> , <EOL> '<STR_LIT>' : <NUM_LIT:20> , <EOL> } ) <EOL> assert_true ( self . ch . connection . _closed ) <EOL> def test_send_close_ok ( self ) : <EOL> expect ( mock ( connection , '<STR_LIT>' ) ) . args ( <EOL> <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT> ) . returns ( '<STR_LIT>' ) <EOL> expect ( self . ch . send_frame ) . args ( '<STR_LIT>' ) <EOL> self . ch . _send_close_ok ( ) <EOL> def test_recv_close_ok ( self ) : <EOL> self . ch . connection . _closed = False <EOL> expect ( self . ch . connection . disconnect ) <EOL> expect ( self . ch . connection . _callback_close ) <EOL> self . ch . _recv_close_ok ( '<STR_LIT>' ) <EOL> assert_true ( self . ch . connection . _closed ) </s>
