Exemplo n.º 1
0
 def test_raise_exceptions(self):
     """Test that exceptions raised by a task are propagated"""
     m = _util.Manager(output='raiseexc%d.out')
     m.add_slave(IMP.parallel.LocalSlave())
     c = m.get_context()
     c.add_task(_tasks.error_task)
     self.assertRaises(IMP.parallel.RemoteError, list,
                       c.get_results_unordered())
     _util.unlink("raiseexc0.out")
Exemplo n.º 2
0
 def test_pass_exceptions(self):
     """Test that exceptions can be passed to and from tasks"""
     m = _util.Manager(output='passexc%d.out')
     m.add_slave(IMP.parallel.LocalSlave())
     c = m.get_context()
     c.add_task(_tasks.SimpleTask(IndexError("test")))
     results = list(c.get_results_unordered())
     self.assertIsInstance(results[0], IndexError)
     _util.unlink("passexc0.out")
Exemplo n.º 3
0
 def test_simple(self):
     """Test that slave tasks can start up and communicate"""
     m = _util.Manager(output='simple%d.out')
     m.add_slave(IMP.parallel.LocalSlave())
     c = m.get_context()
     for i in range(10):
         c.add_task(_tasks.SimpleTask(i))
     results = sorted(c.get_results_unordered())
     self.assertEqual(results, list(range(10)))
     _util.unlink("simple0.out")
Exemplo n.º 4
0
 def test_startup(self):
     """Test context startup callable"""
     m = _util.Manager(output='startup%d.out')
     m.add_slave(IMP.parallel.LocalSlave())
     c = m.get_context(startup=_tasks.SimpleTask(("foo", "bar")))
     c.add_task(_tasks.simple_func)
     c.add_task(_tasks.simple_func)
     results = list(c.get_results_unordered())
     self.assertEqual(results, [('foo', 'bar'), ('foo', 'bar')])
     _util.unlink("startup0.out")
Exemplo n.º 5
0
 def test_startup(self):
     """Test context startup callable"""
     m = _util.Manager(output='startup%d.out')
     m.add_slave(IMP.parallel.LocalSlave())
     c = m.get_context(startup=_tasks.SimpleTask(("foo", "bar")))
     c.add_task(_tasks.simple_func)
     c.add_task(_tasks.simple_func)
     results = list(c.get_results_unordered())
     self.assertEqual(results, [('foo', 'bar'), ('foo', 'bar')])
     _util.unlink("startup0.out")
Exemplo n.º 6
0
 def test_simple(self):
     """Test that slave tasks can start up and communicate"""
     m = _util.Manager(output='simple%d.out')
     m.add_slave(IMP.parallel.LocalSlave())
     c = m.get_context()
     for i in range(10):
         c.add_task(_tasks.SimpleTask(i))
     results = sorted(c.get_results_unordered())
     self.assertEqual(results, list(range(10)))
     _util.unlink("simple0.out")
Exemplo n.º 7
0
 def test_startup_heartbeat(self):
     """Make sure that startup failures cause a timeout"""
     def empty_task():
         pass
     m = _util.Manager(python="/path/does/not/exist",
                       output='heartbeat%d.out')
     m.heartbeat_timeout = 0.1
     m.add_slave(IMP.parallel.LocalSlave())
     c = m.get_context()
     c.add_task(empty_task)
     self.assertRaises(IMP.parallel.NetworkError, list,
                       c.get_results_unordered())
     _util.unlink('heartbeat0.out')
Exemplo n.º 8
0
    def test_startup_heartbeat(self):
        """Make sure that startup failures cause a timeout"""
        def empty_task():
            pass

        m = _util.Manager(python="/path/does/not/exist",
                          output='heartbeat%d.out')
        m.heartbeat_timeout = 0.1
        m.add_slave(IMP.parallel.LocalSlave())
        c = m.get_context()
        c.add_task(empty_task)
        self.assertRaises(IMP.parallel.NetworkError, list,
                          c.get_results_unordered())
        _util.unlink('heartbeat0.out')
Exemplo n.º 9
0
    def test_floats(self):
        """Check that NaN and Inf floats are pickled correctly"""
        if sys.platform in ('irix6', 'osf1V5'):
            self.skipTest(
                "Cannot reliably handle NaN and Inf on Irix or Alpha")

        m = _util.Manager(output='floats%d.out')
        m.add_slave(IMP.parallel.LocalSlave())
        c = m.get_context()

        try:
            inf = float('inf')
            nan = float('nan')
        except ValueError:
            # Python 2.5 on Windows reports 'invalid literal', so use another
            # method to get inf and nan:
            inf = 1e300 * 1e300
            nan = inf - inf
        for f in (inf, nan):
            c.add_task(_tasks.SimpleTask(f))
        results = list(c.get_results_unordered())
        _util.unlink("floats0.out")