tests/test-wireproto-clientreactor.py
changeset 43076 2372284d9457
parent 41119 685cf59a134f
child 45942 89a2afe31e82
--- a/tests/test-wireproto-clientreactor.py	Sat Oct 05 10:29:34 2019 -0400
+++ b/tests/test-wireproto-clientreactor.py	Sun Oct 06 09:45:02 2019 -0400
@@ -9,12 +9,11 @@
     ui as uimod,
     wireprotoframing as framing,
 )
-from mercurial.utils import (
-    cborutil,
-)
+from mercurial.utils import cborutil
 
 try:
     from mercurial import zstd
+
     zstd.__version__
 except ImportError:
     zstd = None
@@ -23,18 +22,24 @@
 
 globalui = uimod.ui()
 
+
 def sendframe(reactor, frame):
     """Send a frame bytearray to a reactor."""
     header = framing.parseheader(frame)
-    payload = frame[framing.FRAME_HEADER_SIZE:]
+    payload = frame[framing.FRAME_HEADER_SIZE :]
     assert len(payload) == header.length
 
-    return reactor.onframerecv(framing.frame(header.requestid,
-                                             header.streamid,
-                                             header.streamflags,
-                                             header.typeid,
-                                             header.flags,
-                                             payload))
+    return reactor.onframerecv(
+        framing.frame(
+            header.requestid,
+            header.streamid,
+            header.streamflags,
+            header.typeid,
+            header.flags,
+            payload,
+        )
+    )
+
 
 class SingleSendTests(unittest.TestCase):
     """A reactor that can only send once rejects subsequent sends."""
@@ -42,13 +47,14 @@
     if not getattr(unittest.TestCase, 'assertRaisesRegex', False):
         # Python 3.7 deprecates the regex*p* version, but 2.7 lacks
         # the regex version.
-        assertRaisesRegex = (# camelcase-required
-            unittest.TestCase.assertRaisesRegexp)
+        assertRaisesRegex = (  # camelcase-required
+            unittest.TestCase.assertRaisesRegexp
+        )
 
     def testbasic(self):
-        reactor = framing.clientreactor(globalui,
-                                        hasmultiplesend=False,
-                                        buffersends=True)
+        reactor = framing.clientreactor(
+            globalui, hasmultiplesend=False, buffersends=True
+        )
 
         request, action, meta = reactor.callcommand(b'foo', {})
         self.assertEqual(request.state, b'pending')
@@ -62,20 +68,24 @@
 
         self.assertEqual(request.state, b'sent')
 
-        with self.assertRaisesRegex(error.ProgrammingError,
-                                     'cannot issue new commands'):
+        with self.assertRaisesRegex(
+            error.ProgrammingError, 'cannot issue new commands'
+        ):
             reactor.callcommand(b'foo', {})
 
-        with self.assertRaisesRegex(error.ProgrammingError,
-                                     'cannot issue new commands'):
+        with self.assertRaisesRegex(
+            error.ProgrammingError, 'cannot issue new commands'
+        ):
             reactor.callcommand(b'foo', {})
 
+
 class NoBufferTests(unittest.TestCase):
     """A reactor without send buffering sends requests immediately."""
+
     def testbasic(self):
-        reactor = framing.clientreactor(globalui,
-                                        hasmultiplesend=True,
-                                        buffersends=False)
+        reactor = framing.clientreactor(
+            globalui, hasmultiplesend=True, buffersends=False
+        )
 
         request, action, meta = reactor.callcommand(b'command1', {})
         self.assertEqual(request.requestid, 1)
@@ -101,29 +111,34 @@
 
         self.assertEqual(request.state, b'sent')
 
+
 class BadFrameRecvTests(unittest.TestCase):
     if not getattr(unittest.TestCase, 'assertRaisesRegex', False):
         # Python 3.7 deprecates the regex*p* version, but 2.7 lacks
         # the regex version.
-        assertRaisesRegex = (# camelcase-required
-            unittest.TestCase.assertRaisesRegexp)
+        assertRaisesRegex = (  # camelcase-required
+            unittest.TestCase.assertRaisesRegexp
+        )
 
     def testoddstream(self):
         reactor = framing.clientreactor(globalui)
 
         action, meta = sendframe(reactor, ffs(b'1 1 0 1 0 foo'))
         self.assertEqual(action, b'error')
-        self.assertEqual(meta[b'message'],
-                         b'received frame with odd numbered stream ID: 1')
+        self.assertEqual(
+            meta[b'message'], b'received frame with odd numbered stream ID: 1'
+        )
 
     def testunknownstream(self):
         reactor = framing.clientreactor(globalui)
 
         action, meta = sendframe(reactor, ffs(b'1 0 0 1 0 foo'))
         self.assertEqual(action, b'error')
-        self.assertEqual(meta[b'message'],
-                         b'received frame on unknown stream without beginning '
-                         b'of stream flag set')
+        self.assertEqual(
+            meta[b'message'],
+            b'received frame on unknown stream without beginning '
+            b'of stream flag set',
+        )
 
     def testunhandledframetype(self):
         reactor = framing.clientreactor(globalui, buffersends=False)
@@ -132,10 +147,12 @@
         for frame in meta[b'framegen']:
             pass
 
-        with self.assertRaisesRegex(error.ProgrammingError,
-                                     'unhandled frame type'):
+        with self.assertRaisesRegex(
+            error.ProgrammingError, 'unhandled frame type'
+        ):
             sendframe(reactor, ffs(b'1 0 stream-begin text-output 0 foo'))
 
+
 class StreamTests(unittest.TestCase):
     def testmultipleresponseframes(self):
         reactor = framing.clientreactor(globalui, buffersends=False)
@@ -148,15 +165,18 @@
 
         action, meta = sendframe(
             reactor,
-            ffs(b'%d 0 stream-begin command-response 0 foo' %
-                request.requestid))
+            ffs(
+                b'%d 0 stream-begin command-response 0 foo' % request.requestid
+            ),
+        )
         self.assertEqual(action, b'responsedata')
 
         action, meta = sendframe(
-            reactor,
-            ffs(b'%d 0 0 command-response eos bar' % request.requestid))
+            reactor, ffs(b'%d 0 0 command-response eos bar' % request.requestid)
+        )
         self.assertEqual(action, b'responsedata')
 
+
 class RedirectTests(unittest.TestCase):
     def testredirect(self):
         reactor = framing.clientreactor(globalui, buffersends=False)
@@ -167,18 +187,24 @@
         }
 
         request, action, meta = reactor.callcommand(
-            b'foo', {}, redirect=redirect)
+            b'foo', {}, redirect=redirect
+        )
 
         self.assertEqual(action, b'sendframes')
 
         frames = list(meta[b'framegen'])
         self.assertEqual(len(frames), 1)
 
-        self.assertEqual(frames[0],
-                         ffs(b'1 1 stream-begin command-request new '
-                             b"cbor:{b'name': b'foo', "
-                             b"b'redirect': {b'targets': [b'a', b'b'], "
-                             b"b'hashes': [b'sha256']}}"))
+        self.assertEqual(
+            frames[0],
+            ffs(
+                b'1 1 stream-begin command-request new '
+                b"cbor:{b'name': b'foo', "
+                b"b'redirect': {b'targets': [b'a', b'b'], "
+                b"b'hashes': [b'sha256']}}"
+            ),
+        )
+
 
 class StreamSettingsTests(unittest.TestCase):
     def testnoflags(self):
@@ -188,14 +214,18 @@
         for f in meta[b'framegen']:
             pass
 
-        action, meta = sendframe(reactor,
-            ffs(b'1 2 stream-begin stream-settings 0 '))
+        action, meta = sendframe(
+            reactor, ffs(b'1 2 stream-begin stream-settings 0 ')
+        )
 
         self.assertEqual(action, b'error')
-        self.assertEqual(meta, {
-            b'message': b'stream encoding settings frame must have '
-                        b'continuation or end of stream flag set',
-        })
+        self.assertEqual(
+            meta,
+            {
+                b'message': b'stream encoding settings frame must have '
+                b'continuation or end of stream flag set',
+            },
+        )
 
     def testconflictflags(self):
         reactor = framing.clientreactor(globalui, buffersends=False)
@@ -204,14 +234,18 @@
         for f in meta[b'framegen']:
             pass
 
-        action, meta = sendframe(reactor,
-            ffs(b'1 2 stream-begin stream-settings continuation|eos '))
+        action, meta = sendframe(
+            reactor, ffs(b'1 2 stream-begin stream-settings continuation|eos ')
+        )
 
         self.assertEqual(action, b'error')
-        self.assertEqual(meta, {
-            b'message': b'stream encoding settings frame cannot have both '
-                        b'continuation and end of stream flags set',
-        })
+        self.assertEqual(
+            meta,
+            {
+                b'message': b'stream encoding settings frame cannot have both '
+                b'continuation and end of stream flags set',
+            },
+        )
 
     def testemptypayload(self):
         reactor = framing.clientreactor(globalui, buffersends=False)
@@ -220,14 +254,18 @@
         for f in meta[b'framegen']:
             pass
 
-        action, meta = sendframe(reactor,
-            ffs(b'1 2 stream-begin stream-settings eos '))
+        action, meta = sendframe(
+            reactor, ffs(b'1 2 stream-begin stream-settings eos ')
+        )
 
         self.assertEqual(action, b'error')
-        self.assertEqual(meta, {
-            b'message': b'stream encoding settings frame did not contain '
-                        b'CBOR data'
-        })
+        self.assertEqual(
+            meta,
+            {
+                b'message': b'stream encoding settings frame did not contain '
+                b'CBOR data'
+            },
+        )
 
     def testbadcbor(self):
         reactor = framing.clientreactor(globalui, buffersends=False)
@@ -236,8 +274,9 @@
         for f in meta[b'framegen']:
             pass
 
-        action, meta = sendframe(reactor,
-            ffs(b'1 2 stream-begin stream-settings eos badvalue'))
+        action, meta = sendframe(
+            reactor, ffs(b'1 2 stream-begin stream-settings eos badvalue')
+        )
 
         self.assertEqual(action, b'error')
 
@@ -248,8 +287,10 @@
         for f in meta[b'framegen']:
             pass
 
-        action, meta = sendframe(reactor,
-            ffs(b'1 2 stream-begin stream-settings eos cbor:b"identity"'))
+        action, meta = sendframe(
+            reactor,
+            ffs(b'1 2 stream-begin stream-settings eos cbor:b"identity"'),
+        )
 
         self.assertEqual(action, b'noop')
         self.assertEqual(meta, {})
@@ -261,19 +302,25 @@
         for f in meta[b'framegen']:
             pass
 
-        data = b''.join([
-            b''.join(cborutil.streamencode(b'identity')),
-            b''.join(cborutil.streamencode({b'foo', b'bar'})),
-        ])
+        data = b''.join(
+            [
+                b''.join(cborutil.streamencode(b'identity')),
+                b''.join(cborutil.streamencode({b'foo', b'bar'})),
+            ]
+        )
 
-        action, meta = sendframe(reactor,
-            ffs(b'1 2 stream-begin stream-settings eos %s' % data))
+        action, meta = sendframe(
+            reactor, ffs(b'1 2 stream-begin stream-settings eos %s' % data)
+        )
 
         self.assertEqual(action, b'error')
-        self.assertEqual(meta, {
-            b'message': b'error setting stream decoder: identity decoder '
-                        b'received unexpected additional values',
-        })
+        self.assertEqual(
+            meta,
+            {
+                b'message': b'error setting stream decoder: identity decoder '
+                b'received unexpected additional values',
+            },
+        )
 
     def testmultipleframes(self):
         reactor = framing.clientreactor(globalui, buffersends=False)
@@ -284,15 +331,19 @@
 
         data = b''.join(cborutil.streamencode(b'identity'))
 
-        action, meta = sendframe(reactor,
-            ffs(b'1 2 stream-begin stream-settings continuation %s' %
-                data[0:3]))
+        action, meta = sendframe(
+            reactor,
+            ffs(
+                b'1 2 stream-begin stream-settings continuation %s' % data[0:3]
+            ),
+        )
 
         self.assertEqual(action, b'noop')
         self.assertEqual(meta, {})
 
-        action, meta = sendframe(reactor,
-            ffs(b'1 2 0 stream-settings eos %s' % data[3:]))
+        action, meta = sendframe(
+            reactor, ffs(b'1 2 0 stream-settings eos %s' % data[3:])
+        )
 
         self.assertEqual(action, b'noop')
         self.assertEqual(meta, {})
@@ -304,14 +355,19 @@
         for f in meta[b'framegen']:
             pass
 
-        action, meta = sendframe(reactor,
-            ffs(b'1 2 stream-begin stream-settings eos cbor:b"badvalue"'))
+        action, meta = sendframe(
+            reactor,
+            ffs(b'1 2 stream-begin stream-settings eos cbor:b"badvalue"'),
+        )
 
         self.assertEqual(action, b'error')
-        self.assertEqual(meta, {
-            b'message': b'error setting stream decoder: unknown stream '
-                        b'decoder: badvalue',
-        })
+        self.assertEqual(
+            meta,
+            {
+                b'message': b'error setting stream decoder: unknown stream '
+                b'decoder: badvalue',
+            },
+        )
 
     def testzlibencoding(self):
         reactor = framing.clientreactor(globalui, buffersends=False)
@@ -320,9 +376,13 @@
         for f in meta[b'framegen']:
             pass
 
-        action, meta = sendframe(reactor,
-            ffs(b'%d 2 stream-begin stream-settings eos cbor:b"zlib"' %
-                request.requestid))
+        action, meta = sendframe(
+            reactor,
+            ffs(
+                b'%d 2 stream-begin stream-settings eos cbor:b"zlib"'
+                % request.requestid
+            ),
+        )
 
         self.assertEqual(action, b'noop')
         self.assertEqual(meta, {})
@@ -335,9 +395,13 @@
         compressed = zlib.compress(encoded)
         self.assertEqual(zlib.decompress(compressed), encoded)
 
-        action, meta = sendframe(reactor,
-            ffs(b'%d 2 encoded command-response eos %s' %
-                (request.requestid, compressed)))
+        action, meta = sendframe(
+            reactor,
+            ffs(
+                b'%d 2 encoded command-response eos %s'
+                % (request.requestid, compressed)
+            ),
+        )
 
         self.assertEqual(action, b'responsedata')
         self.assertEqual(meta[b'data'], encoded)
@@ -349,9 +413,13 @@
         for f in meta[b'framegen']:
             pass
 
-        action, meta = sendframe(reactor,
-            ffs(b'%d 2 stream-begin stream-settings eos cbor:b"zlib"' %
-                request.requestid))
+        action, meta = sendframe(
+            reactor,
+            ffs(
+                b'%d 2 stream-begin stream-settings eos cbor:b"zlib"'
+                % request.requestid
+            ),
+        )
 
         self.assertEqual(action, b'noop')
         self.assertEqual(meta, {})
@@ -367,12 +435,16 @@
         chunks = []
 
         for i in range(len(compressed)):
-            char = compressed[i:i + 1]
+            char = compressed[i : i + 1]
             if char == b'\\':
                 char = b'\\\\'
-            action, meta = sendframe(reactor,
-                ffs(b'%d 2 encoded command-response continuation %s' %
-                    (request.requestid, char)))
+            action, meta = sendframe(
+                reactor,
+                ffs(
+                    b'%d 2 encoded command-response continuation %s'
+                    % (request.requestid, char)
+                ),
+            )
 
             self.assertEqual(action, b'responsedata')
             chunks.append(meta[b'data'])
@@ -384,8 +456,10 @@
         self.assertEqual(b''.join(chunks), encoded)
 
         # End the stream for good measure.
-        action, meta = sendframe(reactor,
-            ffs(b'%d 2 stream-end command-response eos ' % request.requestid))
+        action, meta = sendframe(
+            reactor,
+            ffs(b'%d 2 stream-end command-response eos ' % request.requestid),
+        )
 
         self.assertEqual(action, b'responsedata')
         self.assertEqual(meta[b'data'], b'')
@@ -395,8 +469,9 @@
     def testzlibmultipleresponses(self):
         # We feed in zlib compressed data on the same stream but belonging to
         # 2 different requests. This tests our flushing behavior.
-        reactor = framing.clientreactor(globalui, buffersends=False,
-                                        hasmultiplesend=True)
+        reactor = framing.clientreactor(
+            globalui, buffersends=False, hasmultiplesend=True
+        )
 
         request1, action, meta = reactor.callcommand(b'foo', {})
         for f in meta[b'framegen']:
@@ -409,48 +484,70 @@
         outstream = framing.outputstream(2)
         outstream.setencoder(globalui, b'zlib')
 
-        response1 = b''.join(cborutil.streamencode({
-            b'status': b'ok',
-            b'extra': b'response1' * 10,
-        }))
+        response1 = b''.join(
+            cborutil.streamencode(
+                {b'status': b'ok', b'extra': b'response1' * 10,}
+            )
+        )
 
-        response2 = b''.join(cborutil.streamencode({
-            b'status': b'error',
-            b'extra': b'response2' * 10,
-        }))
+        response2 = b''.join(
+            cborutil.streamencode(
+                {b'status': b'error', b'extra': b'response2' * 10,}
+            )
+        )
 
-        action, meta = sendframe(reactor,
-            ffs(b'%d 2 stream-begin stream-settings eos cbor:b"zlib"' %
-                request1.requestid))
+        action, meta = sendframe(
+            reactor,
+            ffs(
+                b'%d 2 stream-begin stream-settings eos cbor:b"zlib"'
+                % request1.requestid
+            ),
+        )
 
         self.assertEqual(action, b'noop')
         self.assertEqual(meta, {})
 
         # Feeding partial data in won't get anything useful out.
-        action, meta = sendframe(reactor,
-            ffs(b'%d 2 encoded command-response continuation %s' % (
-                request1.requestid, outstream.encode(response1))))
+        action, meta = sendframe(
+            reactor,
+            ffs(
+                b'%d 2 encoded command-response continuation %s'
+                % (request1.requestid, outstream.encode(response1))
+            ),
+        )
         self.assertEqual(action, b'responsedata')
         self.assertEqual(meta[b'data'], b'')
 
         # But flushing data at both ends will get our original data.
-        action, meta = sendframe(reactor,
-            ffs(b'%d 2 encoded command-response eos %s' % (
-                request1.requestid, outstream.flush())))
+        action, meta = sendframe(
+            reactor,
+            ffs(
+                b'%d 2 encoded command-response eos %s'
+                % (request1.requestid, outstream.flush())
+            ),
+        )
         self.assertEqual(action, b'responsedata')
         self.assertEqual(meta[b'data'], response1)
 
         # We should be able to reuse the compressor/decompressor for the
         # 2nd response.
-        action, meta = sendframe(reactor,
-            ffs(b'%d 2 encoded command-response continuation %s' % (
-                request2.requestid, outstream.encode(response2))))
+        action, meta = sendframe(
+            reactor,
+            ffs(
+                b'%d 2 encoded command-response continuation %s'
+                % (request2.requestid, outstream.encode(response2))
+            ),
+        )
         self.assertEqual(action, b'responsedata')
         self.assertEqual(meta[b'data'], b'')
 
-        action, meta = sendframe(reactor,
-            ffs(b'%d 2 encoded command-response eos %s' % (
-                request2.requestid, outstream.flush())))
+        action, meta = sendframe(
+            reactor,
+            ffs(
+                b'%d 2 encoded command-response eos %s'
+                % (request2.requestid, outstream.flush())
+            ),
+        )
         self.assertEqual(action, b'responsedata')
         self.assertEqual(meta[b'data'], response2)
 
@@ -462,9 +559,13 @@
         for f in meta[b'framegen']:
             pass
 
-        action, meta = sendframe(reactor,
-            ffs(b'%d 2 stream-begin stream-settings eos cbor:b"zstd-8mb"' %
-                request.requestid))
+        action, meta = sendframe(
+            reactor,
+            ffs(
+                b'%d 2 stream-begin stream-settings eos cbor:b"zstd-8mb"'
+                % request.requestid
+            ),
+        )
 
         self.assertEqual(action, b'noop')
         self.assertEqual(meta, {})
@@ -476,12 +577,20 @@
 
         encoder = framing.zstd8mbencoder(globalui)
         compressed = encoder.encode(encoded) + encoder.finish()
-        self.assertEqual(zstd.ZstdDecompressor().decompress(
-            compressed, max_output_size=len(encoded)), encoded)
+        self.assertEqual(
+            zstd.ZstdDecompressor().decompress(
+                compressed, max_output_size=len(encoded)
+            ),
+            encoded,
+        )
 
-        action, meta = sendframe(reactor,
-            ffs(b'%d 2 encoded command-response eos %s' %
-                (request.requestid, compressed)))
+        action, meta = sendframe(
+            reactor,
+            ffs(
+                b'%d 2 encoded command-response eos %s'
+                % (request.requestid, compressed)
+            ),
+        )
 
         self.assertEqual(action, b'responsedata')
         self.assertEqual(meta[b'data'], encoded)
@@ -494,9 +603,13 @@
         for f in meta[b'framegen']:
             pass
 
-        action, meta = sendframe(reactor,
-            ffs(b'%d 2 stream-begin stream-settings eos cbor:b"zstd-8mb"' %
-                request.requestid))
+        action, meta = sendframe(
+            reactor,
+            ffs(
+                b'%d 2 stream-begin stream-settings eos cbor:b"zstd-8mb"'
+                % request.requestid
+            ),
+        )
 
         self.assertEqual(action, b'noop')
         self.assertEqual(meta, {})
@@ -507,18 +620,23 @@
         encoded = b''.join(cborutil.streamencode(result))
 
         compressed = zstd.ZstdCompressor().compress(encoded)
-        self.assertEqual(zstd.ZstdDecompressor().decompress(compressed),
-                         encoded)
+        self.assertEqual(
+            zstd.ZstdDecompressor().decompress(compressed), encoded
+        )
 
         chunks = []
 
         for i in range(len(compressed)):
-            char = compressed[i:i + 1]
+            char = compressed[i : i + 1]
             if char == b'\\':
                 char = b'\\\\'
-            action, meta = sendframe(reactor,
-                ffs(b'%d 2 encoded command-response continuation %s' %
-                    (request.requestid, char)))
+            action, meta = sendframe(
+                reactor,
+                ffs(
+                    b'%d 2 encoded command-response continuation %s'
+                    % (request.requestid, char)
+                ),
+            )
 
             self.assertEqual(action, b'responsedata')
             chunks.append(meta[b'data'])
@@ -529,8 +647,10 @@
         self.assertEqual(b''.join(chunks), encoded)
 
         # End the stream for good measure.
-        action, meta = sendframe(reactor,
-            ffs(b'%d 2 stream-end command-response eos ' % request.requestid))
+        action, meta = sendframe(
+            reactor,
+            ffs(b'%d 2 stream-end command-response eos ' % request.requestid),
+        )
 
         self.assertEqual(action, b'responsedata')
         self.assertEqual(meta[b'data'], b'')
@@ -541,8 +661,9 @@
     def testzstd8mbmultipleresponses(self):
         # We feed in zstd compressed data on the same stream but belonging to
         # 2 different requests. This tests our flushing behavior.
-        reactor = framing.clientreactor(globalui, buffersends=False,
-                                        hasmultiplesend=True)
+        reactor = framing.clientreactor(
+            globalui, buffersends=False, hasmultiplesend=True
+        )
 
         request1, action, meta = reactor.callcommand(b'foo', {})
         for f in meta[b'framegen']:
@@ -555,51 +676,74 @@
         outstream = framing.outputstream(2)
         outstream.setencoder(globalui, b'zstd-8mb')
 
-        response1 = b''.join(cborutil.streamencode({
-            b'status': b'ok',
-            b'extra': b'response1' * 10,
-        }))
+        response1 = b''.join(
+            cborutil.streamencode(
+                {b'status': b'ok', b'extra': b'response1' * 10,}
+            )
+        )
 
-        response2 = b''.join(cborutil.streamencode({
-            b'status': b'error',
-            b'extra': b'response2' * 10,
-        }))
+        response2 = b''.join(
+            cborutil.streamencode(
+                {b'status': b'error', b'extra': b'response2' * 10,}
+            )
+        )
 
-        action, meta = sendframe(reactor,
-            ffs(b'%d 2 stream-begin stream-settings eos cbor:b"zstd-8mb"' %
-                request1.requestid))
+        action, meta = sendframe(
+            reactor,
+            ffs(
+                b'%d 2 stream-begin stream-settings eos cbor:b"zstd-8mb"'
+                % request1.requestid
+            ),
+        )
 
         self.assertEqual(action, b'noop')
         self.assertEqual(meta, {})
 
         # Feeding partial data in won't get anything useful out.
-        action, meta = sendframe(reactor,
-            ffs(b'%d 2 encoded command-response continuation %s' % (
-                request1.requestid, outstream.encode(response1))))
+        action, meta = sendframe(
+            reactor,
+            ffs(
+                b'%d 2 encoded command-response continuation %s'
+                % (request1.requestid, outstream.encode(response1))
+            ),
+        )
         self.assertEqual(action, b'responsedata')
         self.assertEqual(meta[b'data'], b'')
 
         # But flushing data at both ends will get our original data.
-        action, meta = sendframe(reactor,
-            ffs(b'%d 2 encoded command-response eos %s' % (
-                request1.requestid, outstream.flush())))
+        action, meta = sendframe(
+            reactor,
+            ffs(
+                b'%d 2 encoded command-response eos %s'
+                % (request1.requestid, outstream.flush())
+            ),
+        )
         self.assertEqual(action, b'responsedata')
         self.assertEqual(meta[b'data'], response1)
 
         # We should be able to reuse the compressor/decompressor for the
         # 2nd response.
-        action, meta = sendframe(reactor,
-            ffs(b'%d 2 encoded command-response continuation %s' % (
-                request2.requestid, outstream.encode(response2))))
+        action, meta = sendframe(
+            reactor,
+            ffs(
+                b'%d 2 encoded command-response continuation %s'
+                % (request2.requestid, outstream.encode(response2))
+            ),
+        )
         self.assertEqual(action, b'responsedata')
         self.assertEqual(meta[b'data'], b'')
 
-        action, meta = sendframe(reactor,
-            ffs(b'%d 2 encoded command-response eos %s' % (
-                request2.requestid, outstream.flush())))
+        action, meta = sendframe(
+            reactor,
+            ffs(
+                b'%d 2 encoded command-response eos %s'
+                % (request2.requestid, outstream.flush())
+            ),
+        )
         self.assertEqual(action, b'responsedata')
         self.assertEqual(meta[b'data'], response2)
 
+
 if __name__ == '__main__':
     if (3, 6, 0) <= sys.version_info < (3, 6, 4):
         # Python 3.6.0 through 3.6.3 inclusive shipped with
@@ -607,4 +751,5 @@
         # tests on those specific versions of Python. Sigh.
         sys.exit(80)
     import silenttestrunner
+
     silenttestrunner.main(__name__)