@@ -448,10 +448,23 @@ def test_fatal_error(self, m_exc):
448448 tr ._force_close = mock .Mock ()
449449 tr ._fatal_error (exc )
450450
451+ m_exc .assert_not_called ()
452+
453+ tr ._force_close .assert_called_with (exc )
454+
455+ @mock .patch ('asyncio.log.logger.error' )
456+ def test_fatal_error_custom_exception (self , m_exc ):
457+ class MyError (Exception ):
458+ pass
459+ exc = MyError ()
460+ tr = self .create_transport ()
461+ tr ._force_close = mock .Mock ()
462+ tr ._fatal_error (exc )
463+
451464 m_exc .assert_called_with (
452465 test_utils .MockPattern (
453466 'Fatal error on transport\n protocol:.*\n transport:.*' ),
454- exc_info = (OSError , MOCK_ANY , MOCK_ANY ))
467+ exc_info = (MyError , MOCK_ANY , MOCK_ANY ))
455468
456469 tr ._force_close .assert_called_with (exc )
457470
@@ -1338,10 +1351,20 @@ def test_fatal_error_connected(self, m_exc):
13381351 err = ConnectionRefusedError ()
13391352 transport ._fatal_error (err )
13401353 self .assertFalse (self .protocol .error_received .called )
1354+ m_exc .assert_not_called ()
1355+
1356+ @mock .patch ('asyncio.base_events.logger.error' )
1357+ def test_fatal_error_connected_custom_error (self , m_exc ):
1358+ class MyException (Exception ):
1359+ pass
1360+ transport = self .datagram_transport (address = ('0.0.0.0' , 1 ))
1361+ err = MyException ()
1362+ transport ._fatal_error (err )
1363+ self .assertFalse (self .protocol .error_received .called )
13411364 m_exc .assert_called_with (
13421365 test_utils .MockPattern (
13431366 'Fatal error on transport\n protocol:.*\n transport:.*' ),
1344- exc_info = (ConnectionRefusedError , MOCK_ANY , MOCK_ANY ))
1367+ exc_info = (MyException , MOCK_ANY , MOCK_ANY ))
13451368
13461369
13471370if __name__ == '__main__' :
0 commit comments