#NEWLINE# @ mock . patch ( 'aiohttp.client.WebSocketWriter' ) #NEWLINE# @ mock . patch ( 'aiohttp.client.os' ) #NEWLINE# @ mock . patch ( 'aiohttp.client.ClientSession.get' ) #NEWLINE# def test_close_exc( self , m_req , m_os , WebSocketWriter ) : #NEWLINE# #INDENT# resp = mock . Mock ( ) #NEWLINE# resp . status = 101 #NEWLINE# resp . headers = { #NEWLINE# #INDENT# hdrs . UPGRADE : hdrs . WEBSOCKET , #NEWLINE# hdrs . CONNECTION : hdrs . UPGRADE , #NEWLINE# hdrs . SEC_WEBSOCKET_ACCEPT : self . ws_key , #NEWLINE# #UNINDENT# } #NEWLINE# m_os . urandom . return_value = WebSocketWriter . key_data #NEWLINE# m_req . return_value = asyncio . Future ( loop = self . loop ) #NEWLINE# m_req . return_value . set_result ( resp ) #NEWLINE# WebSocketWriter . return_value = mock . Mock ( ) #NEWLINE# reader = resp . connection . reader . set_parser . return_value = mock . Mock ( ) #NEWLINE# resp = self . loop . run_until_complete ( aiohttp . ws_connect ( 'http://test.org' , loop = self . loop ) ) #NEWLINE# self . assertFalse ( resp . closed ) #NEWLINE# exc = ValueError ( ) #NEWLINE# reader . read . return_value = asyncio . Future ( loop = self . loop ) #NEWLINE# reader . read . return_value . set_exception ( exc ) #NEWLINE# self . loop . run_until_complete ( resp . close ( ) ) #NEWLINE# self . assertTrue ( resp . closed ) #NEWLINE# self . assertIs ( resp . exception ( ) , exc )