def test_bufferedServerStatus(self):
        """
        When a server status change occurs during an ongoing FETCH
        command, the server status is buffered until the FETCH
        completes.
        """
        self.server.dataReceived(
            b'01 FETCH 1,2 BODY[]\r\n'
        )

        # Two iterations yields the untagged response and the first
        # fetched message's body
        twice = functools.partial(next, iter([True,  True, False]))
        self.flushPending(asLongAs=twice)

        self.assertEqual(
            self.transport.value(), b''.join([
                # The untagged response...
                b'* 1 FETCH (BODY[] )\r\n',
                # ...and its body
                networkString(
                    '{5}\r\n\r\n\r\n%s' % (
                        nativeString(self.messages[0].getBodyFile().read()),
                    )
                ),
            ]))

        self.transport.clear()

        # A server status change...
        self.server.modeChanged(writeable=True)

        # ...remains buffered...
        self.assertFalse(self.transport.value())

        self.flushPending()

        self.assertEqual(self.transport.value(), b''.join([
            # The untagged response...
            b'* 2 FETCH (BODY[] )\r\n',
            # ...the status change...
            b"* [READ-WRITE]\r\n",
            # ...and the completion status and final message's body
            networkString(
                '01 OK FETCH completed\r\n{5}\r\n\r\n\r\n%s' % (
                    nativeString(self.messages[1].getBodyFile().read()),
                )
            ),
        ]))

        When a server status change occurs during an ongoing FETCH
        command, the server status is buffered until the FETCH
        completes.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/mail/test/test_imap.py