Ejemplo n.º 1
0
 def __init__(self, command, key=None, handler=None,
              stderr=False, timeout=-1, autoclose=False):
     """Initialize Popen worker."""
     WorkerSimple.__init__(self, None, None, None, key, handler, stderr,
                           timeout, autoclose, client_class=PopenClient)
     self.command = command
     if not self.command:
         raise ValueError("missing command parameter in WorkerPopen "
                          "constructor")
Ejemplo n.º 2
0
 def __init__(self, command, key=None, handler=None,
              stderr=False, timeout=-1, autoclose=False):
     """Initialize Popen worker."""
     WorkerSimple.__init__(self, None, None, None, key, handler, stderr,
                           timeout, autoclose, client_class=PopenClient)
     self.command = command
     if not self.command:
         raise ValueError("missing command parameter in WorkerPopen "
                          "constructor")
     self.key = key
Ejemplo n.º 3
0
 def testWorkerSimplePipeStdout(self):
     task = task_self()
     rfd, wfd = os.pipe()
     os.write(wfd, "test\n")
     os.close(wfd)
     worker = WorkerSimple(os.fdopen(rfd), None, None, "pipe", None,
                           stderr=True, timeout=-1, autoclose=False,
                           closefd=False)
     self.assertEqual(worker.reader_fileno(), rfd)
     task.schedule(worker)
     task.resume()
     self.assertEqual(task.key_buffer("pipe"), 'test')
     dummy = os.fstat(rfd) # just to check that rfd is still valid here
Ejemplo n.º 4
0
 def testWorkerSimplePipeStdout(self):
     task = task_self()
     rfd, wfd = os.pipe()
     os.write(wfd, b"test\n")
     os.close(wfd)
     worker = WorkerSimple(os.fdopen(rfd), None, None, "pipe", None,
                           stderr=True, timeout=-1, autoclose=False,
                           closefd=False)
     self.assertEqual(worker.reader_fileno(), rfd)
     task.schedule(worker)
     task.resume()
     self.assertEqual(task.key_buffer("pipe"), b'test')
     dummy = os.fstat(rfd) # just to check that rfd is still valid here
Ejemplo n.º 5
0
 def testWorkerSimplePipeStdErr(self):
     task = task_self()
     rfd, wfd = os.pipe()
     os.write(wfd, b"test\n")
     os.close(wfd)
     # be careful, stderr is arg #3
     worker = WorkerSimple(None, None, os.fdopen(rfd), "pipe", None,
                           stderr=True, timeout=-1, autoclose=False,
                           closefd=False)
     self.assertEqual(worker.error_fileno(), rfd)
     task.schedule(worker)
     task.resume()
     self.assertEqual(task.key_error("pipe"), b'test')
     dummy = os.fstat(rfd) # just to check that rfd is still valid here
Ejemplo n.º 6
0
 def testWorkerSimplePipeStdErr(self):
     task = task_self()
     rfd, wfd = os.pipe()
     os.write(wfd, "test\n")
     os.close(wfd)
     # be careful, stderr is arg #3
     worker = WorkerSimple(None, None, os.fdopen(rfd), "pipe", None,
                           stderr=True, timeout=-1, autoclose=False,
                           closefd=False)
     self.assertEqual(worker.error_fileno(), rfd)
     task.schedule(worker)
     task.resume()
     self.assertEqual(task.key_error("pipe"), 'test')
     dummy = os.fstat(rfd) # just to check that rfd is still valid here
Ejemplo n.º 7
0
    def testInvalidCommunication(self):
        """test detecting invalid data upon reception"""
        ftest = tempfile.NamedTemporaryFile()
        ftest.write('<?xml version="1.0" encoding="UTF-8"?>\n')
        ftest.write('This is an invalid line\n')
        ftest.write('<channel>\n')
        ftest.write('</channel>\n')

        ## write data on the disk
        # actually we should do more but this seems sufficient
        ftest.flush()

        chan = _TestingChannel()
        task = task_self()

        fin = open(ftest.name)
        fout = open('/dev/null', 'w')
        worker = WorkerSimple(fin, fout, None, None, handler=chan)
        task.schedule(worker)

        self.assertRaises(MessageProcessingError, task.resume)

        fin.close()
        fout.close()
        ftest.close()
Ejemplo n.º 8
0
 def testWorkerSimpleStdin(self):
     """test WorkerSimple (stdin)"""
     task = task_self()
     self.assert_(task != None)
     file_reader = sys.stdin
     worker = WorkerSimple(file_reader, None, None, "stdin", None, 0, True)
     self.assert_(worker != None)
     task.schedule(worker)
     task.resume()
Ejemplo n.º 9
0
 def testWorkerSimplePipe(self):
     task = task_self()
     self.assert_(task != None)
     rfd, wfd = os.pipe()
     os.write(wfd, "test\n")
     worker = WorkerSimple(os.fdopen(rfd), None, None, "pipe", None, 0, True)
     self.assert_(worker != None)
     task.schedule(worker)
     task.resume()
     self.assertEqual(task.key_buffer("pipe"), 'test')
     dummy = os.fstat(rfd) # just to check that rfd is still valid here
     os.close(wfd)
Ejemplo n.º 10
0
 def testWorkerSimplePipeStdin(self):
     task = task_self()
     rfd, wfd = os.pipe()
     # be careful, stdin is arg #2
     worker = WorkerSimple(None, os.fdopen(wfd, "w"), None, "pipe", None,
                           stderr=True, timeout=-1, autoclose=False,
                           closefd=False)
     self.assertEqual(worker.writer_fileno(), wfd)
     worker.write(b"write to stdin test\n")
     worker.set_write_eof() # close stream after write!
     task.schedule(worker)
     task.resume()
     self.assertEqual(os.read(rfd, 1024), b"write to stdin test\n")
     os.close(rfd)
Ejemplo n.º 11
0
 def testWorkerSimplePipeStdin(self):
     task = task_self()
     rfd, wfd = os.pipe()
     # be careful, stdin is arg #2
     worker = WorkerSimple(None, os.fdopen(wfd, "w"), None, "pipe", None,
                           stderr=True, timeout=-1, autoclose=False,
                           closefd=False)
     self.assertEqual(worker.writer_fileno(), wfd)
     worker.write("write to stdin test\n")
     worker.set_write_eof() # close stream after write!
     task.schedule(worker)
     task.resume()
     self.assertEqual(os.read(rfd, 1024), "write to stdin test\n")
     os.close(rfd)
Ejemplo n.º 12
0
    def testLocalChannel(self):
        """schyzophrenic self local communication"""
        # create a bunch of messages
        spec = {
            # msg type: number of samples
            ConfigurationMessage.ident: 1,
            ControlMessage.ident: 1,
            ACKMessage.ident: 1,
            ErrorMessage.ident: 1
        }
        ftest = tempfile.NamedTemporaryFile()
        ftest.write('<?xml version="1.0" encoding="UTF-8"?>\n')
        ftest.write('<channel>\n')
        for mtype, count in spec.items():
            for i in range(count):
                sample = gen_map[mtype]()
                sample.msgid = i
                ftest.write(sample.xml() + '\n')
        ftest.write('</channel>\n')

        ## write data on the disk
        # actually we should do more but this seems sufficient
        ftest.flush()

        fin = open(ftest.name)
        fout = open('/dev/null', 'w')

        chan = _TestingChannel()
        worker = WorkerSimple(fin, fout, None, None, handler=chan)

        task = task_self()
        task.schedule(worker)
        task.resume()

        ftest.close()
        fin.close()
        fout.close()
        self.assertEquals(chan.validate(spec), True)
Ejemplo n.º 13
0
 def _on_rc(self, rc):
     """
     Set return code.
     """
     self.rc = rc  # 1.4- compat
     WorkerSimple._on_rc(self, rc)
Ejemplo n.º 14
0
 def _on_rc(self, rc):
     """
     Set return code.
     """
     self.rc = rc  # 1.4- compat
     WorkerSimple._on_rc(self, rc)