def test_service(self):
        """
        Test that the transport can set the running service and dispatches
        packets to the service's packetReceived method.
        """
        service = MockService()
        self.proto.setService(service)
        self.assertEqual(self.proto.service, service)
        self.assertTrue(service.started)
        self.proto.dispatchMessage(0xff, b"test")
        self.assertEqual(self.packets, [(0xff, b"test")])

        service2 = MockService()
        self.proto.setService(service2)
        self.assertTrue(service2.started)
        self.assertTrue(service.stopped)

        self.proto.connectionLost(None)
        self.assertTrue(service2.stopped)

        Test that the transport can set the running service and dispatches
        packets to the service's packetReceived method.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py