def test_lineReceivedNotImplemented(self): """ When L{LineReceiver.lineReceived} is not overridden in a subclass, calling it raises C{NotImplementedError}. """ proto = basic.LineReceiver() self.assertRaises(NotImplementedError, proto.lineReceived, 'foo')
def errLineReceived(self, line): if 'starting data transfer loop' in line: os.system('chmod 777 /dev/ttyUSB0') self.serialPort = SerialPort(basic.LineReceiver(), '/dev/ttyToUSB', reactor, timeout=3) self.loop = LoopingCall(writeToSerialPort, self.serialPort, self.emulator) self.loop.start(2)
def test_maximumLineLengthRemaining(self): """ C{LineReceiver} disconnects the transport it if receives a non-finished line longer than its C{MAX_LENGTH}. """ proto = basic.LineReceiver() transport = proto_helpers.StringTransport() proto.makeConnection(transport) proto.dataReceived(b'x' * (proto.MAX_LENGTH + 1)) self.assertTrue(transport.disconnecting)
def test_maximumLineLength(self): """ C{LineReceiver} disconnects the transport if it receives a line longer than its C{MAX_LENGTH}. """ proto = basic.LineReceiver() transport = proto_helpers.StringTransport() proto.makeConnection(transport) proto.dataReceived(b"x" * (proto.MAX_LENGTH + 1) + b"\r\nr") self.assertTrue(transport.disconnecting)
def test_rawDataError(self): """ C{LineReceiver.dataReceived} forwards errors returned by C{rawDataReceived}. """ proto = basic.LineReceiver() proto.rawDataReceived = lambda data: RuntimeError("oops") transport = proto_helpers.StringTransport() proto.makeConnection(transport) proto.setRawMode() why = proto.dataReceived(b'data') self.assertIsInstance(why, RuntimeError)
def test_notQuiteMaximumLineLengthUnfinished(self): """ C{LineReceiver} doesn't disconnect the transport it if receives a non-finished line whose length, counting the delimiter, is longer than its C{MAX_LENGTH} but shorter than its C{MAX_LENGTH} + len(delimiter). (When the first part that exceeds the max is the beginning of the delimiter.) """ proto = basic.LineReceiver() # '\r\n' is the default, but we set it just to be explicit in # this test. proto.delimiter = b'\r\n' transport = proto_helpers.StringTransport() proto.makeConnection(transport) proto.dataReceived((b'x' * proto.MAX_LENGTH) + proto.delimiter[:len(proto.delimiter) - 1]) self.assertFalse(transport.disconnecting)
def connectionMade(self): #print "process started" self.lineParser = basic.LineReceiver() self.lineParser.delimiter = "\n" self.lineParser.makeConnection(None) self.lineParser.lineReceived = self.lineReceived