def assertCommandExceptionResponse(self,
                                        exception, tag, expectedResponse):
        """
        Assert that the given exception results in the expected
        response.

        @param exception: The exception to raise.
        @type exception: L{Exception}

        @param: The IMAP tag.

        @type: L{bytes}

        @param expectedResponse: The expected bad response.
        @type expectedResponse: L{bytes}
        """
        def raises(serverInstance, tag, user, passwd):
            raise exception

        self.assertEqual(self.server.state, "unauth")

        self.server.unauth_LOGIN = (raises,) + self.server.unauth_LOGIN[1:]

        self.server.dispatchCommand(tag, b"LOGIN", b"user passwd")

        self.assertEqual(self.transport.value(),
                         b' '.join([tag, expectedResponse]))

        Assert that the given exception results in the expected
        response.

        @param exception: The exception to raise.
        @type exception: L{Exception}

        @param: The IMAP tag.

        @type: L{bytes}

        @param expectedResponse: The expected bad response.
        @type expectedResponse: L{bytes}
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/mail/test/test_imap.py