@@ -850,10 +850,23 @@ def test_fatal_error(self, m_exc):
850850 tr ._force_close = mock .Mock ()
851851 tr ._fatal_error (exc )
852852
853+ m_exc .assert_not_called ()
854+
855+ tr ._force_close .assert_called_with (exc )
856+
857+ @mock .patch ('asyncio.log.logger.error' )
858+ def test_fatal_error_custom_exception (self , m_exc ):
859+ class MyError (Exception ):
860+ pass
861+ exc = MyError ()
862+ tr = self .create_transport ()
863+ tr ._force_close = mock .Mock ()
864+ tr ._fatal_error (exc )
865+
853866 m_exc .assert_called_with (
854867 test_utils .MockPattern (
855868 'Fatal error on transport\n protocol:.*\n transport:.*' ),
856- exc_info = (OSError , MOCK_ANY , MOCK_ANY ))
869+ exc_info = (MyError , MOCK_ANY , MOCK_ANY ))
857870
858871 tr ._force_close .assert_called_with (exc )
859872
@@ -1740,10 +1753,20 @@ def test_fatal_error_connected(self, m_exc):
17401753 err = ConnectionRefusedError ()
17411754 transport ._fatal_error (err )
17421755 self .assertFalse (self .protocol .error_received .called )
1756+ m_exc .assert_not_called ()
1757+
1758+ @mock .patch ('asyncio.base_events.logger.error' )
1759+ def test_fatal_error_connected_custom_error (self , m_exc ):
1760+ class MyException (Exception ):
1761+ pass
1762+ transport = self .datagram_transport (address = ('0.0.0.0' , 1 ))
1763+ err = MyException ()
1764+ transport ._fatal_error (err )
1765+ self .assertFalse (self .protocol .error_received .called )
17431766 m_exc .assert_called_with (
17441767 test_utils .MockPattern (
17451768 'Fatal error on transport\n protocol:.*\n transport:.*' ),
1746- exc_info = (ConnectionRefusedError , MOCK_ANY , MOCK_ANY ))
1769+ exc_info = (MyException , MOCK_ANY , MOCK_ANY ))
17471770
17481771
17491772if __name__ == '__main__' :
0 commit comments