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, ))})
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, )), }
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, ))})
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,)), }
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()
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()
def on_apply(self, target, args, kwargs, callback=None, accept_callback=None, **_): return apply_target(target, args, kwargs, callback, accept_callback, self.pid)
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())
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, )) })
def test_apply_target__raises_WorkerShutdown(self): target = Mock(name="target") target.side_effect = WorkerShutdown() with self.assertRaises(WorkerShutdown): apply_target(target)
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()
def test_apply_target__raises_WorkerTerminate(self): target = Mock(name='target') target.side_effect = WorkerTerminate() with self.assertRaises(WorkerTerminate): apply_target(target)
def test_apply_target__raises_WorkerShutdown(self): target = Mock(name='target') target.side_effect = WorkerShutdown() with self.assertRaises(WorkerShutdown): apply_target(target)
def test_apply_target__raises(self): target = Mock(name='target') target.side_effect = KeyError() with self.assertRaises(KeyError): apply_target(target)
def test_apply_target__propagate(self): target = Mock(name='target') target.side_effect = KeyError() with self.assertRaises(KeyError): apply_target(target, propagate=(KeyError,))
def test_apply_target__raises(self): target = Mock(name='target') target.side_effect = KeyError() with pytest.raises(KeyError): apply_target(target)
def test_apply_target__raises_WorkerTerminate(self): target = Mock(name="target") target.side_effect = WorkerTerminate() with self.assertRaises(WorkerTerminate): apply_target(target)
def test_apply_target__propagate(self): target = Mock(name="target") target.side_effect = KeyError() with self.assertRaises(KeyError): apply_target(target, propagate=(KeyError,))
def test_apply_target__raises_WorkerTerminate(self): target = Mock(name='target') target.side_effect = WorkerTerminate() with pytest.raises(WorkerTerminate): apply_target(target)
def test_apply_target__raises_WorkerShutdown(self): target = Mock(name='target') target.side_effect = WorkerShutdown() with pytest.raises(WorkerShutdown): apply_target(target)
def test_apply_target__raises(self): target = Mock(name="target") target.side_effect = KeyError() with self.assertRaises(KeyError): apply_target(target)
def test_apply_target__propagate(self): target = Mock(name='target') target.side_effect = KeyError() with pytest.raises(KeyError): apply_target(target, propagate=(KeyError,))