def test_real_endpoint(self): echoText = "hello world!" expectedGatheredData = [echoTransform(echoText)] expectedConnectionLostReason = ConnectionDone command = "%s %r" % (ECHO_COMMAND, echoText) endpoint = InductorEndpoint(self.inductor, command=command, timeout=1) protocolFactory = protocol.ClientFactory() protocolFactory.protocol = GatherProtocol clientDeferred = endpoint.connect(protocolFactory) @clientDeferred.addCallback def checkClient(client): self.assertIsInstance(client, GatherProtocol) return client.resultDeferred @clientDeferred.addCallback def checkGatheredData(res): gatheredData, connectionLostReason = res self.assertEqual(gatheredData, expectedGatheredData) return connectionLostReason # Check that the connection was lost as expected return self.assertFailure(clientDeferred, expectedConnectionLostReason) return clientDeferred
def test_endpoint(self): fauxProcessData = [(stdout, 'some output'), (stderr, 'error message'), (stdout, 'info message'), (stderr, 'os failure')] inductor = MockProcessInductor(reactor, fauxProcessData) endpoint = InductorEndpoint(inductor, 'foo', ('foo'), timeout=1) dataDeferred = defer.Deferred() connDeferred = defer.Deferred() class MockProtocol(protocol.Protocol): data = [] def dataReceived(self, data): self.transport.write(data) self.data.append(data) def connectionLost(self, reason): connDeferred.callback(reason) dataDeferred.callback(self.data) protocolFactory = protocol.ClientFactory() protocolFactory.protocol = MockProtocol clientDeferred = endpoint.connect(protocolFactory) @clientDeferred.addCallback def check_client(client): self.assertIsInstance(client, MockProtocol) @dataDeferred.addCallback def check_received_data(data): expected = [d for _, d in fauxProcessData] return self.assertEqual(data, expected) # Check that the connectionLost reason self.assertFailure(connDeferred, ConnectionDone) return defer.DeferredList([clientDeferred, dataDeferred, connDeferred], fireOnOneErrback=True)
def test_endpoint(self): fauxProcessData = [(stdout, 'some output'), (stderr, 'error message'), (stdout, 'info message'), (stderr, 'os failure')] inductor = MockProcessInductor(reactor, fauxProcessData) endpoint = InductorEndpoint(inductor, 'foo', ('foo'), timeout=1) dataDeferred = defer.Deferred() connDeferred = defer.Deferred() class MockProtocol(protocol.Protocol): data = [] def dataReceived (self, data): self.transport.write(data) self.data.append(data) def connectionLost (self, reason): connDeferred.callback(reason) dataDeferred.callback(self.data) protocolFactory = protocol.ClientFactory() protocolFactory.protocol = MockProtocol clientDeferred = endpoint.connect(protocolFactory) @clientDeferred.addCallback def check_client(client): self.assertIsInstance(client, MockProtocol) @dataDeferred.addCallback def check_received_data(data): expected = [d for _, d in fauxProcessData] return self.assertEqual(data, expected) # Check that the connectionLost reason self.assertFailure(connDeferred, ConnectionDone) return defer.DeferredList([clientDeferred, dataDeferred, connDeferred], fireOnOneErrback=True)