예제 #1
0
    def test_apply_target(self):

        scratch = {}
        counter = count(0)

        def gen_callback(name, retval=None):

            def callback(*args):
                scratch[name] = (next(counter), args)
                return retval

            return callback

        apply_target(gen_callback('target', 42),
                     args=(8, 16),
                     callback=gen_callback('callback'),
                     accept_callback=gen_callback('accept_callback'))

        self.assertDictContainsSubset(
            {'target': (1, (8, 16)),
             'callback': (2, (42, ))}, scratch)
        pa1 = scratch['accept_callback']
        self.assertEqual(0, pa1[0])
        self.assertEqual(pa1[1][0], os.getpid())
        self.assertTrue(pa1[1][1])

        # No accept callback
        scratch.clear()
        apply_target(gen_callback('target', 42),
                     args=(8, 16),
                     callback=gen_callback('callback'),
                     accept_callback=None)
        self.assertDictEqual(scratch,
                              {'target': (3, (8, 16)),
                               'callback': (4, (42, ))})
예제 #2
0
    def test_apply_target(self):

        scratch = {}
        counter = count(0)

        def gen_callback(name, retval=None):
            def callback(*args):
                scratch[name] = (next(counter), args)
                return retval

            return callback

        apply_target(gen_callback('target', 42),
                     args=(8, 16),
                     callback=gen_callback('callback'),
                     accept_callback=gen_callback('accept_callback'))

        assert scratch['target'] == (1, (8, 16))
        assert scratch['callback'] == (2, (42, ))
        pa1 = scratch['accept_callback']
        assert pa1[0] == 0
        assert pa1[1][0] == os.getpid()
        assert pa1[1][1]

        # No accept callback
        scratch.clear()
        apply_target(gen_callback('target', 42),
                     args=(8, 16),
                     callback=gen_callback('callback'),
                     accept_callback=None)
        assert scratch == {
            'target': (3, (8, 16)),
            'callback': (4, (42, )),
        }
예제 #3
0
    def test_apply_target(self):

        scratch = {}
        counter = count(0).next

        def gen_callback(name, retval=None):

            def callback(*args):
                scratch[name] = (counter(), args)
                return retval

            return callback

        apply_target(gen_callback("target", 42),
                     args=(8, 16),
                     callback=gen_callback("callback"),
                     accept_callback=gen_callback("accept_callback"))

        self.assertDictContainsSubset({
                              "target": (1, (8, 16)),
                              "callback": (2, (42, ))}, scratch)
        pa1 = scratch["accept_callback"]
        self.assertEqual(0, pa1[0])
        self.assertEqual(pa1[1][0], os.getpid())
        self.assertTrue(pa1[1][1])

        # No accept callback
        scratch.clear()
        apply_target(gen_callback("target", 42),
                     args=(8, 16),
                     callback=gen_callback("callback"),
                     accept_callback=None)
        self.assertDictEqual(scratch,
                              {"target": (3, (8, 16)),
                               "callback": (4, (42, ))})
예제 #4
0
    def test_apply_target(self):

        scratch = {}
        counter = count(0)

        def gen_callback(name, retval=None):

            def callback(*args):
                scratch[name] = (next(counter), args)
                return retval

            return callback

        apply_target(gen_callback('target', 42),
                     args=(8, 16),
                     callback=gen_callback('callback'),
                     accept_callback=gen_callback('accept_callback'))

        assert scratch['target'] == (1, (8, 16))
        assert scratch['callback'] == (2, (42,))
        pa1 = scratch['accept_callback']
        assert pa1[0] == 0
        assert pa1[1][0] == os.getpid()
        assert pa1[1][1]

        # No accept callback
        scratch.clear()
        apply_target(gen_callback('target', 42),
                     args=(8, 16),
                     callback=gen_callback('callback'),
                     accept_callback=None)
        assert scratch == {
            'target': (3, (8, 16)),
            'callback': (4, (42,)),
        }
예제 #5
0
 def test_apply_target__raises_BaseException_raises_else(self, reraise):
     target = Mock(name='target')
     callback = Mock(name='callback')
     reraise.side_effect = KeyError()
     target.side_effect = BaseException()
     with self.assertRaises(KeyError):
         apply_target(target, callback=callback)
     callback.assert_not_called()
예제 #6
0
 def test_apply_target__raises_BaseException_raises_else(self, reraise):
     target = Mock(name='target')
     callback = Mock(name='callback')
     reraise.side_effect = KeyError()
     target.side_effect = BaseException()
     with pytest.raises(KeyError):
         apply_target(target, callback=callback)
     callback.assert_not_called()
예제 #7
0
 def on_apply(self,
              target,
              args,
              kwargs,
              callback=None,
              accept_callback=None,
              **_):
     return apply_target(target, args, kwargs, callback, accept_callback,
                         self.pid)
예제 #8
0
def apply_target(target,
                 args=(),
                 kwargs={},
                 callback=None,
                 accept_callback=None,
                 getpid=None):
    return base.apply_target(target,
                             args,
                             kwargs,
                             callback,
                             accept_callback,
                             pid=getpid())
예제 #9
0
    def test_apply_target(self):

        scratch = {}
        counter = count(0)

        def gen_callback(name, retval=None):
            def callback(*args):
                scratch[name] = (next(counter), args)
                return retval

            return callback

        apply_target(gen_callback('target', 42),
                     args=(8, 16),
                     callback=gen_callback('callback'),
                     accept_callback=gen_callback('accept_callback'))

        self.assertDictContainsSubset(
            {
                'target': (1, (8, 16)),
                'callback': (2, (42, ))
            },
            scratch,
        )
        pa1 = scratch['accept_callback']
        self.assertEqual(0, pa1[0])
        self.assertEqual(pa1[1][0], os.getpid())
        self.assertTrue(pa1[1][1])

        # No accept callback
        scratch.clear()
        apply_target(gen_callback('target', 42),
                     args=(8, 16),
                     callback=gen_callback('callback'),
                     accept_callback=None)
        self.assertDictEqual(scratch, {
            'target': (3, (8, 16)),
            'callback': (4, (42, ))
        })
예제 #10
0
 def test_apply_target__raises_WorkerShutdown(self):
     target = Mock(name="target")
     target.side_effect = WorkerShutdown()
     with self.assertRaises(WorkerShutdown):
         apply_target(target)
예제 #11
0
 def test_apply_target__raises_BaseException(self):
     target = Mock(name='target')
     callback = Mock(name='callback')
     target.side_effect = BaseException()
     apply_target(target, callback=callback)
     callback.assert_called()
예제 #12
0
 def test_apply_target__raises_WorkerTerminate(self):
     target = Mock(name='target')
     target.side_effect = WorkerTerminate()
     with self.assertRaises(WorkerTerminate):
         apply_target(target)
예제 #13
0
 def test_apply_target__raises_WorkerShutdown(self):
     target = Mock(name='target')
     target.side_effect = WorkerShutdown()
     with self.assertRaises(WorkerShutdown):
         apply_target(target)
예제 #14
0
 def test_apply_target__raises(self):
     target = Mock(name='target')
     target.side_effect = KeyError()
     with self.assertRaises(KeyError):
         apply_target(target)
예제 #15
0
 def test_apply_target__propagate(self):
     target = Mock(name='target')
     target.side_effect = KeyError()
     with self.assertRaises(KeyError):
         apply_target(target, propagate=(KeyError,))
예제 #16
0
 def test_apply_target__raises(self):
     target = Mock(name='target')
     target.side_effect = KeyError()
     with pytest.raises(KeyError):
         apply_target(target)
예제 #17
0
 def test_apply_target__raises_WorkerTerminate(self):
     target = Mock(name="target")
     target.side_effect = WorkerTerminate()
     with self.assertRaises(WorkerTerminate):
         apply_target(target)
예제 #18
0
 def on_apply(self, target, args, kwargs, callback=None,
         accept_callback=None, **_):
     return apply_target(target, args, kwargs,
                         callback, accept_callback, self.pid)
예제 #19
0
 def test_apply_target__propagate(self):
     target = Mock(name="target")
     target.side_effect = KeyError()
     with self.assertRaises(KeyError):
         apply_target(target, propagate=(KeyError,))
예제 #20
0
 def test_apply_target__raises_BaseException(self):
     target = Mock(name='target')
     callback = Mock(name='callback')
     target.side_effect = BaseException()
     apply_target(target, callback=callback)
     callback.assert_called()
예제 #21
0
 def test_apply_target__raises_WorkerTerminate(self):
     target = Mock(name='target')
     target.side_effect = WorkerTerminate()
     with pytest.raises(WorkerTerminate):
         apply_target(target)
예제 #22
0
 def test_apply_target__raises_WorkerShutdown(self):
     target = Mock(name='target')
     target.side_effect = WorkerShutdown()
     with pytest.raises(WorkerShutdown):
         apply_target(target)
예제 #23
0
 def test_apply_target__raises(self):
     target = Mock(name="target")
     target.side_effect = KeyError()
     with self.assertRaises(KeyError):
         apply_target(target)
예제 #24
0
def apply_target(target, args=(), kwargs={}, callback=None,
                 accept_callback=None, getpid=None):
    return base.apply_target(target, args, kwargs, callback, accept_callback,
                             pid=getpid())
예제 #25
0
 def test_apply_target__propagate(self):
     target = Mock(name='target')
     target.side_effect = KeyError()
     with pytest.raises(KeyError):
         apply_target(target, propagate=(KeyError,))