Esempio n. 1
0
    def testThreadTaskBuffers(self):
        """test task data access methods after join()"""
        task = Task()
        # test data access from main thread

        # test stderr separated
        task.set_default("stderr", True)
        task.shell("echo foobar", key="OUT")
        task.shell("echo raboof 1>&2", key="ERR")
        task.resume()
        task.join()
        self.assertEqual(task.key_buffer("OUT"), b"foobar")
        self.assertEqual(task.key_error("OUT"), b"")
        self.assertEqual(task.key_buffer("ERR"), b"")
        self.assertEqual(task.key_error("ERR"), b"raboof")

        # test stderr merged
        task.set_default("stderr", False)
        task.shell("echo foobar", key="OUT")
        task.shell("echo raboof 1>&2", key="ERR")
        task.resume()
        task.join()
        self.assertEqual(task.key_buffer("OUT"), b"foobar")
        self.assertEqual(task.key_error("OUT"), b"")
        self.assertEqual(task.key_buffer("ERR"), b"raboof")
        self.assertEqual(task.key_error("ERR"), b"")
Esempio n. 2
0
    def testThreadTaskBuffers(self):
        """test task data access methods after join()"""
        task = Task()
        # test data access from main thread

        # test stderr separated
        task.set_default("stderr", True)
        task.shell("echo foobar", key="OUT")
        task.shell("echo raboof 1>&2", key="ERR")
        task.resume()
        task.join()
        self.assertEqual(task.key_buffer("OUT"), "foobar")
        self.assertEqual(task.key_error("OUT"), "")
        self.assertEqual(task.key_buffer("ERR"), "")
        self.assertEqual(task.key_error("ERR"), "raboof")

        # test stderr merged
        task.set_default("stderr", False)
        task.shell("echo foobar", key="OUT")
        task.shell("echo raboof 1>&2", key="ERR")
        task.resume()
        task.join()
        self.assertEqual(task.key_buffer("OUT"), "foobar")
        self.assertEqual(task.key_error("OUT"), "")
        self.assertEqual(task.key_buffer("ERR"), "raboof")
        self.assertEqual(task.key_error("ERR"), "")
Esempio n. 3
0
    def testThreadTaskUnhandledException(self):
        """test task unhandled exception in thread"""
        class TestUnhandledException(Exception):
            """test exception"""
        class RaiseOnRead(EventHandler):
            def ev_read(self, worker):
                raise TestUnhandledException("you should see this exception")

        task = Task()
        # test data access from main thread
        task.shell("echo raisefoobar", key=1, handler=RaiseOnRead())
        task.resume()
        task.join()
        self.assertEqual(task.key_buffer(1), b"raisefoobar")
        time.sleep(1) # for pretty display, because unhandled exception
                      # traceback may be sent to stderr after the join()
        self.assertFalse(task.running())
Esempio n. 4
0
    def testThreadTaskUnhandledException(self):
        """test task unhandled exception in thread"""
        class TestUnhandledException(Exception):
            """test exception"""
        class RaiseOnRead(EventHandler):
            def ev_read(self, worker):
                raise TestUnhandledException("you should see this exception")

        task = Task()
        # test data access from main thread
        task.shell("echo raisefoobar", key=1, handler=RaiseOnRead())
        task.resume()
        task.join()
        self.assertEqual(task.key_buffer(1), "raisefoobar")
        time.sleep(1) # for pretty display, because unhandled exception
                      # traceback may be sent to stderr after the join()
        self.assertFalse(task.running())
Esempio n. 5
0
 def testThreadSimpleTaskSupervisor(self):
     """test task methods from another thread"""
     #print "PASS 1"
     task = Task()
     task.shell("sleep 3")
     task.shell("echo testing", key=1)
     task.resume()
     task.join()
     self.assertEqual(task.key_buffer(1), b"testing")
     #print "PASS 2"
     task.shell("echo ok", key=2)
     task.resume()
     task.join()
     #print "PASS 3"
     self.assertEqual(task.key_buffer(2), b"ok")
     task.shell("sleep 1 && echo done", key=3)
     task.resume()
     task.join()
     #print "PASS 4"
     self.assertEqual(task.key_buffer(3), b"done")
     task.abort()
Esempio n. 6
0
 def testThreadSimpleTaskSupervisor(self):
     """test task methods from another thread"""
     #print "PASS 1"
     task = Task()
     task.shell("sleep 3")
     task.shell("echo testing", key=1)
     task.resume()
     task.join()
     self.assertEqual(task.key_buffer(1), "testing")
     #print "PASS 2"
     task.shell("echo ok", key=2)
     task.resume()
     task.join()
     #print "PASS 3"
     self.assertEqual(task.key_buffer(2), "ok")
     task.shell("sleep 1 && echo done", key=3)
     task.resume()
     task.join()
     #print "PASS 4"
     self.assertEqual(task.key_buffer(3), "done")
     task.abort()