コード例 #1
0
class TestRecordingInterpreter:
    
    def setup_method(self, method):
        self.interpreter = RecordingInterpreter()
        
    def test_interpret_startSessionCommand(self):
        line = "BeginRecordSession(lambada)"
        command = self.interpreter.interpret(line)
        
        assert command.__class__ == BeginRecordSessionCommand
    
    def test_interpret_startSessionCommand_condensed(self):
        packed = struct.pack("!c", chr(20))
        command = self.interpreter.interpret(packed)

        assert command.__class__ == BeginRecordSessionCommand
    
    def test_interpret_stopSessionCommand(self):
        line = "EndRecordSession()"
        command = self.interpreter.interpret(line)
        
        assert command.__class__ == EndRecordSessionCommand
    
    def test_interpret_stopSessionCommand_condensed(self):
        packed = struct.pack("!c", chr(21))
        command = self.interpreter.interpret(packed)

        assert command.__class__ == EndRecordSessionCommand    
        
    def test_interpret_startRecCommand(self):
        line = "StartRecording()"
        command = self.interpreter.interpret(line)
        
        assert command.__class__ == StartRecordCommand
        
    def test_interpret_startRecCommand_condensed(self):
        packed = struct.pack("!c", chr(22))
        command = self.interpreter.interpret(packed)

        assert command.__class__ == StartRecordCommand        
        
    def test_interpret_stopRecCommand(self):
        line = "StopRecording()"
        command = self.interpreter.interpret(line)
        
        assert command.__class__ == StopRecordCommand
        
    def test_interpret_stopRecCommand_condensed(self):
        packed = struct.pack("!c", chr(23))
        command = self.interpreter.interpret(packed)

        assert command.__class__ == StopRecordCommand
        
    def teardown_method(self, method):
        del self.interpreter
コード例 #2
0
class SocketReceiverHandler(SocketServer.BaseRequestHandler):
    
    def setup(self):
        self.positionInterpreter = PositionCommandLineInterpreter.PositionCommandLineInterpreter()
        self.positionInterpreter.concurentCommands = True
        self.recordingInterpreter = RecordingInterpreter()
        SocketServer.BaseRequestHandler.setup(self)
    
    def finish(self):
        del self.positionInterpreter
        del self.recordingInterpreter
        SocketServer.BaseRequestHandler.finish(self)
        
    def handle(self):
        
        socket = self.request[1]
        messageCounter = self.queue.qsize()
        socket.sendto(str(messageCounter).encode('ascii')+"\n", self.client_address)
        
        if self.queue.full():
            return #if queue is full: quit
        
        data = self.request[0].strip()
        
        print "%s wrote:" % self.client_address[0]
        print data
        
        command = self.interpret_absolute(data)
        self.queue.put( command )
        
    def interpret_absolute(self, data):
        attempt = self.positionInterpreter.interpret(data)
        if( attempt == -1 ):
            attempt = self.recordingInterpreter.interpret(data)
        
        return attempt
コード例 #3
0
 def setup_method(self, method):
     self.interpreter = RecordingInterpreter()
コード例 #4
0
 def setup(self):
     self.positionInterpreter = PositionCommandLineInterpreter.PositionCommandLineInterpreter()
     self.positionInterpreter.concurentCommands = True
     self.recordingInterpreter = RecordingInterpreter()
     SocketServer.BaseRequestHandler.setup(self)