Beispiel #1
0
 def test_01_executable_not_found(self):
     try:
         manager = process.ProcessManager(name="dummy",
                                          command=["you_will_not_find_me"])
     except process.ManagedProcessError:
         pass
     else:
         self.fail(
             "Should have thrown error since executable not possible to find."
         )
Beispiel #2
0
    def XXtest_01_start(self):
        def _callback(result, test_case):
            return test_case.globals["manager"].stop()

        kwargs = {
            "command": ["xlogo"],
        }
        self.globals["manager"] = process.ProcessManager(**kwargs)
        deferred = self.globals["manager"].start()
        deferred.addCallback(_callback, self)
Beispiel #3
0
    def test_04_start_and_stop_mplayer(self):
        """
        Mplayer process using twisted and JACK.
        """
        def _stop_callback(result, deferred):
            deferred.callback(True)
            return True

        def _stop_err(err, deferred):
            #print("ERROR %s" % (err))
            #return True
            deferred.errback(err)
            return True  #return err

        def _later(deferred, manager):
            deferred2 = manager.stop()
            deferred2.addCallback(_stop_callback, deferred)
            deferred2.addErrback(_stop_err, deferred)
            #deferred2.callback()
            #deferred.callback(deferred2)

        def _start_err(err, manager):
            # stops reactor in case of error starting process
            #print("ERROR %s" % (err))
            #reactor.stop()
            #return True
            return err

        def _start_callback(result, manager):
            DURATION = 2.0
            deferred = defer.Deferred()
            reactor.callLater(DURATION, _later, deferred, manager)
            # stops the process
            #print(str(result))
            #deferred.addCallback(_stop)
            #return True #
            return deferred

        global MOVIEFILENAME
        if not os.path.exists(MOVIEFILENAME):
            warnings.warn("File %s is needed for this test." % (MOVIEFILENAME))
        else:
            # starts the process
            #manager = process.ProcessManager(name="xeyes", command=["xeyes"])
            #  "-vo", "gl2",
            manager = process.ProcessManager(
                name="mplayer",
                command=["mplayer", "-ao", "jack", MOVIEFILENAME])
            deferred = manager.start()
            deferred.addCallback(_start_callback, manager)
            deferred.addErrback(_start_err, manager)
            return deferred
Beispiel #4
0
    def test_03_start_and_stop_sleep_that_dies(self):
        """
        Catches when the process dies.
        """
        def _stop_callback(result, deferred, test_case):
            global _globals_04
            # XXX: calling stop() when done doesnt give any error anymore
            #if result != "NO ERROR DUDE":
            #    msg = "The process was still running and has been killed succesfully... Stop() should have created an error."
            #    fail = failure.Failure(Exception(msg))
            #    deferred.errback(fail)
            #    #test_case.fail(msg) # for some reason this doesn;t work, since we returned a deferred ! IMPORTANT

            if not _globals_04["obs"].called:
                raise Exception("Observer never called !!")
            return True
            #return fail

        def _stop_err(err, deferred, test_case):
            # That's what wer expected
            deferred.callback(True)
            #deferred.errback(err)
            return "NO ERROR DUDE"  #return err
            #return err

        def _later(deferred, manager, test_case):
            deferred2 = manager.stop()
            deferred2.addErrback(_stop_err, deferred,
                                 test_case)  # order matters ! this first.
            deferred2.addCallback(_stop_callback, deferred, test_case)

        def _start_err(err, manager, test_case):
            return err

        def _start_callback(result, manager, test_case):
            DURATION = 4.0
            deferred = defer.Deferred()
            reactor.callLater(DURATION, _later, deferred, manager, test_case)
            return deferred

        # starts the process
        manager = process.ProcessManager(name="sleep", command=["sleep", "2"])
        deferred = manager.start()
        deferred.addCallback(_start_callback, manager, self)
        deferred.addErrback(_start_err, manager, self)
        return deferred  # only possible to fail it by calling deferred.errback() !!
Beispiel #5
0
    def test_02_start_and_stop_xeyes(self):
        """
        xeyes process using twisted
        """
        def _stop_callback(result, deferred):
            deferred.callback(True)
            return True

        def _stop_err(err, deferred):
            deferred.errback(err)
            return True  #return err

        def _later(deferred, manager):
            deferred2 = manager.stop()
            deferred2.addCallback(_stop_callback, deferred)
            deferred2.addErrback(_stop_err, deferred)

        def _start_err(err, manager):
            return err

        def _start_callback(result, manager):
            DURATION = 2.0
            deferred = defer.Deferred()
            reactor.callLater(DURATION, _later, deferred, manager)
            return deferred

        # starts the process
        global _globals_04
        #obs = DummyObserver(self)
        #_globals_04["obs"] = obs # XXX Needs to be a global since observer uses a weakref !!!
        manager = process.ProcessManager(
            name="xeyes", command=["xeyes", "-geometry", "640x480"])
        #obs.append(manager.subject)
        #print(manager.subject.observers.values())
        #d = manager.subject.observers
        #for v in d.itervalues():
        #    print v
        #print("Subjects:" + str(manager.subject.observers))
        deferred = manager.start()
        deferred.addCallback(_start_callback, manager)
        deferred.addErrback(_start_err, manager)
        return deferred
Beispiel #6
0
 def start(self):
     """
     Creates args and start pd.
     
     Returns True
     Blocking.
     """
     command = "pd"
     if self.driver == "jack":
         command += " -jack"
     elif self.driver == "alsa":
         command += " -alsa"
         if self.audioindev is not None:
             command += " -audioindev %d" % (self.audioindev)
         if self.audiooutdev is not None:
             command += " -audiooutdev %d" % (self.audiooutdev)
         command += " -listdev"
     else:
         warnings.warn("Driver %s is not supported - yet." % (self.driver))
     if self.verbose:
         command += " -verbose"
     command += " -r %d" % (self.rate)
     command += " -inchannels %d" % (self.inchannels)
     command += " -outchannels %d" % (self.outchannels)
     command += " %s" % (self.patch)
     #print("Using process tool %s" % (self.process_tool))
     if self.process_tool == "subprocess":
         run_command(command, variables_dict={}, die_on_ctrl_c=True)
         #return True
         return defer.succeed(True)  # right now
     elif self.process_tool == "manager":
         #TODO: env vars
         self._process_manager = process.ProcessManager(
             name="puredata", command=command.split(), verbose=True)
         d = self._process_manager.start()  # deferred
         # print("process manager deferred: %s" % (d))
         return d
     else:
         raise NotImplementedError("no such process tool")