class TestFailedTaskSetResult(TestTaskSetResult): def setup(self): self.size = 11 subtasks = make_mock_taskset(10) failed = mock_task("ts11", states.FAILURE, KeyError("Baz")) save_result(failed) failed_res = AsyncResult(failed["id"]) self.ts = TaskSetResult(uuid(), subtasks + [failed_res]) def test_itersubtasks(self): it = self.ts.itersubtasks() for i in xrange(self.size - 1): t = it.next() self.assertEqual(t.get(), i) with self.assertRaises(KeyError): t = it.next() # need to do this in two lines or 2to3 borks. t.get() def test_completed_count(self): self.assertEqual(self.ts.completed_count(), len(self.ts) - 1) def test___iter__(self): it = iter(self.ts) def consume(): return list(it) with self.assertRaises(KeyError): consume() def test_join(self): with self.assertRaises(KeyError): self.ts.join() def test_successful(self): self.assertFalse(self.ts.successful()) def test_failed(self): self.assertTrue(self.ts.failed())
class TestTaskSetResult(unittest.TestCase): def setUp(self): self.size = 10 self.ts = TaskSetResult(gen_unique_id(), make_mock_taskset(self.size)) def test_total(self): self.assertEquals(self.ts.total, self.size) def test_itersubtasks(self): it = self.ts.itersubtasks() for i, t in enumerate(it): self.assertEquals(t.get(), i) def test___iter__(self): it = iter(self.ts) results = sorted(list(it)) self.assertEquals(results, list(xrange(self.size))) def test_join(self): joined = self.ts.join() self.assertEquals(joined, list(xrange(self.size))) def test_successful(self): self.assertTrue(self.ts.successful()) def test_failed(self): self.assertFalse(self.ts.failed()) def test_waiting(self): self.assertFalse(self.ts.waiting()) def test_ready(self): self.assertTrue(self.ts.ready()) def test_completed_count(self): self.assertEquals(self.ts.completed_count(), self.ts.total)
class TestFailedTaskSetResult(TestTaskSetResult): def setUp(self): self.size = 11 subtasks = make_mock_taskset(10) failed = mock_task("ts11", states.FAILURE, KeyError("Baz")) save_result(failed) failed_res = AsyncResult(failed["id"]) self.ts = TaskSetResult(gen_unique_id(), subtasks + [failed_res]) def test_itersubtasks(self): it = self.ts.itersubtasks() for i in xrange(self.size - 1): t = it.next() self.assertEqual(t.get(), i) self.assertRaises(KeyError, it.next().get) def test_completed_count(self): self.assertEqual(self.ts.completed_count(), self.ts.total - 1) def test___iter__(self): it = iter(self.ts) def consume(): return list(it) self.assertRaises(KeyError, consume) def test_join(self): self.assertRaises(KeyError, self.ts.join) def test_successful(self): self.assertFalse(self.ts.successful()) def test_failed(self): self.assertTrue(self.ts.failed())
class TestTaskSetResult(unittest.TestCase): def setUp(self): self.size = 10 self.ts = TaskSetResult(gen_unique_id(), make_mock_taskset(self.size)) def test_total(self): self.assertEqual(self.ts.total, self.size) def test_iterate_raises(self): ar = MockAsyncResultFailure(gen_unique_id()) ts = TaskSetResult(gen_unique_id(), [ar]) it = iter(ts) self.assertRaises(KeyError, it.next) def test_iterate_yields(self): ar = MockAsyncResultSuccess(gen_unique_id()) ar2 = MockAsyncResultSuccess(gen_unique_id()) ts = TaskSetResult(gen_unique_id(), [ar, ar2]) it = iter(ts) self.assertEqual(it.next(), 42) self.assertEqual(it.next(), 42) def test_join_timeout(self): ar = MockAsyncResultSuccess(gen_unique_id()) ar2 = MockAsyncResultSuccess(gen_unique_id()) ar3 = AsyncResult(gen_unique_id()) ts = TaskSetResult(gen_unique_id(), [ar, ar2, ar3]) self.assertRaises(TimeoutError, ts.join, timeout=0.0000001) def test_itersubtasks(self): it = self.ts.itersubtasks() for i, t in enumerate(it): self.assertEqual(t.get(), i) def test___iter__(self): it = iter(self.ts) results = sorted(list(it)) self.assertListEqual(results, list(xrange(self.size))) def test_join(self): joined = self.ts.join() self.assertListEqual(joined, list(xrange(self.size))) def test_successful(self): self.assertTrue(self.ts.successful()) def test_failed(self): self.assertFalse(self.ts.failed()) def test_waiting(self): self.assertFalse(self.ts.waiting()) def test_ready(self): self.assertTrue(self.ts.ready()) def test_completed_count(self): self.assertEqual(self.ts.completed_count(), self.ts.total)
class TestTaskSetResult(AppCase): def setup(self): self.size = 10 self.ts = TaskSetResult(uuid(), make_mock_taskset(self.size)) def test_total(self): self.assertEqual(self.ts.total, self.size) def test_iterate_raises(self): ar = MockAsyncResultFailure(uuid()) ts = TaskSetResult(uuid(), [ar]) it = iter(ts) self.assertRaises(KeyError, it.next) def test_forget(self): subs = [MockAsyncResultSuccess(uuid()), MockAsyncResultSuccess(uuid())] ts = TaskSetResult(uuid(), subs) ts.forget() for sub in subs: self.assertTrue(sub.forgotten) def test_getitem(self): subs = [MockAsyncResultSuccess(uuid()), MockAsyncResultSuccess(uuid())] ts = TaskSetResult(uuid(), subs) self.assertIs(ts[0], subs[0]) def test_save_restore(self): subs = [MockAsyncResultSuccess(uuid()), MockAsyncResultSuccess(uuid())] ts = TaskSetResult(uuid(), subs) ts.save() self.assertRaises(AttributeError, ts.save, backend=object()) self.assertEqual(TaskSetResult.restore(ts.taskset_id).subtasks, ts.subtasks) ts.delete() self.assertIsNone(TaskSetResult.restore(ts.taskset_id)) self.assertRaises(AttributeError, TaskSetResult.restore, ts.taskset_id, backend=object()) def test_join_native(self): backend = SimpleBackend() subtasks = [AsyncResult(uuid(), backend=backend) for i in range(10)] ts = TaskSetResult(uuid(), subtasks) backend.ids = [subtask.task_id for subtask in subtasks] res = ts.join_native() self.assertEqual(res, range(10)) def test_iter_native(self): backend = SimpleBackend() subtasks = [AsyncResult(uuid(), backend=backend) for i in range(10)] ts = TaskSetResult(uuid(), subtasks) backend.ids = [subtask.task_id for subtask in subtasks] self.assertEqual(len(list(ts.iter_native())), 10) def test_iterate_yields(self): ar = MockAsyncResultSuccess(uuid()) ar2 = MockAsyncResultSuccess(uuid()) ts = TaskSetResult(uuid(), [ar, ar2]) it = iter(ts) self.assertEqual(it.next(), 42) self.assertEqual(it.next(), 42) def test_iterate_eager(self): ar1 = EagerResult(uuid(), 42, states.SUCCESS) ar2 = EagerResult(uuid(), 42, states.SUCCESS) ts = TaskSetResult(uuid(), [ar1, ar2]) it = iter(ts) self.assertEqual(it.next(), 42) self.assertEqual(it.next(), 42) def test_join_timeout(self): ar = MockAsyncResultSuccess(uuid()) ar2 = MockAsyncResultSuccess(uuid()) ar3 = AsyncResult(uuid()) ts = TaskSetResult(uuid(), [ar, ar2, ar3]) self.assertRaises(TimeoutError, ts.join, timeout=0.0000001) def test_itersubtasks(self): it = self.ts.itersubtasks() for i, t in enumerate(it): self.assertEqual(t.get(), i) def test___iter__(self): it = iter(self.ts) results = sorted(list(it)) self.assertListEqual(results, list(xrange(self.size))) def test_join(self): joined = self.ts.join() self.assertListEqual(joined, list(xrange(self.size))) def test_successful(self): self.assertTrue(self.ts.successful()) def test_failed(self): self.assertFalse(self.ts.failed()) def test_waiting(self): self.assertFalse(self.ts.waiting()) def test_ready(self): self.assertTrue(self.ts.ready()) def test_completed_count(self): self.assertEqual(self.ts.completed_count(), self.ts.total)
class TestTaskSetResult(unittest.TestCase): def setUp(self): self.size = 10 self.ts = TaskSetResult(gen_unique_id(), make_mock_taskset(self.size)) def test_total(self): self.assertEqual(self.ts.total, self.size) def test_iterate_raises(self): ar = MockAsyncResultFailure(gen_unique_id()) ts = TaskSetResult(gen_unique_id(), [ar]) it = iter(ts) self.assertRaises(KeyError, it.next) def test_forget(self): subs = [ MockAsyncResultSuccess(gen_unique_id()), MockAsyncResultSuccess(gen_unique_id()) ] ts = TaskSetResult(gen_unique_id(), subs) ts.forget() for sub in subs: self.assertTrue(sub.forgotten) def test_getitem(self): subs = [ MockAsyncResultSuccess(gen_unique_id()), MockAsyncResultSuccess(gen_unique_id()) ] ts = TaskSetResult(gen_unique_id(), subs) self.assertIs(ts[0], subs[0]) def test_save_restore(self): subs = [ MockAsyncResultSuccess(gen_unique_id()), MockAsyncResultSuccess(gen_unique_id()) ] ts = TaskSetResult(gen_unique_id(), subs) ts.save() self.assertRaises(AttributeError, ts.save, backend=object()) self.assertEqual( TaskSetResult.restore(ts.taskset_id).subtasks, ts.subtasks) ts.delete() self.assertIsNone(TaskSetResult.restore(ts.taskset_id)) self.assertRaises(AttributeError, TaskSetResult.restore, ts.taskset_id, backend=object()) def test_join_native(self): backend = SimpleBackend() subtasks = [ AsyncResult(gen_unique_id(), backend=backend) for i in range(10) ] ts = TaskSetResult(gen_unique_id(), subtasks) backend.ids = [subtask.task_id for subtask in subtasks] res = ts.join_native() self.assertEqual(res, range(10)) def test_iter_native(self): backend = SimpleBackend() subtasks = [ AsyncResult(gen_unique_id(), backend=backend) for i in range(10) ] ts = TaskSetResult(gen_unique_id(), subtasks) backend.ids = [subtask.task_id for subtask in subtasks] self.assertEqual(len(list(ts.iter_native())), 10) def test_iterate_yields(self): ar = MockAsyncResultSuccess(gen_unique_id()) ar2 = MockAsyncResultSuccess(gen_unique_id()) ts = TaskSetResult(gen_unique_id(), [ar, ar2]) it = iter(ts) self.assertEqual(it.next(), 42) self.assertEqual(it.next(), 42) def test_iterate_eager(self): ar1 = EagerResult(gen_unique_id(), 42, states.SUCCESS) ar2 = EagerResult(gen_unique_id(), 42, states.SUCCESS) ts = TaskSetResult(gen_unique_id(), [ar1, ar2]) it = iter(ts) self.assertEqual(it.next(), 42) self.assertEqual(it.next(), 42) def test_join_timeout(self): ar = MockAsyncResultSuccess(gen_unique_id()) ar2 = MockAsyncResultSuccess(gen_unique_id()) ar3 = AsyncResult(gen_unique_id()) ts = TaskSetResult(gen_unique_id(), [ar, ar2, ar3]) self.assertRaises(TimeoutError, ts.join, timeout=0.0000001) def test_itersubtasks(self): it = self.ts.itersubtasks() for i, t in enumerate(it): self.assertEqual(t.get(), i) def test___iter__(self): it = iter(self.ts) results = sorted(list(it)) self.assertListEqual(results, list(xrange(self.size))) def test_join(self): joined = self.ts.join() self.assertListEqual(joined, list(xrange(self.size))) def test_successful(self): self.assertTrue(self.ts.successful()) def test_failed(self): self.assertFalse(self.ts.failed()) def test_waiting(self): self.assertFalse(self.ts.waiting()) def test_ready(self): self.assertTrue(self.ts.ready()) def test_completed_count(self): self.assertEqual(self.ts.completed_count(), self.ts.total)
class test_TaskSetResult(AppCase): def setup(self): self.size = 10 self.ts = TaskSetResult(uuid(), make_mock_taskset(self.size)) def test_total(self): self.assertEqual(len(self.ts), self.size) self.assertEqual(self.ts.total, self.size) def test_compat_properties(self): self.assertEqual(self.ts.taskset_id, self.ts.id) self.ts.taskset_id = "foo" self.assertEqual(self.ts.taskset_id, "foo") def test_eq_other(self): self.assertFalse(self.ts == 1) def test_reduce(self): self.assertTrue(loads(dumps(self.ts))) def test_compat_subtasks_kwarg(self): x = TaskSetResult(uuid(), subtasks=[1, 2, 3]) self.assertEqual(x.results, [1, 2, 3]) def test_iterate_raises(self): ar = MockAsyncResultFailure(uuid()) ts = TaskSetResult(uuid(), [ar]) it = iter(ts) with self.assertRaises(KeyError): it.next() def test_forget(self): subs = [MockAsyncResultSuccess(uuid()), MockAsyncResultSuccess(uuid())] ts = TaskSetResult(uuid(), subs) ts.forget() for sub in subs: self.assertTrue(sub.forgotten) def test_getitem(self): subs = [MockAsyncResultSuccess(uuid()), MockAsyncResultSuccess(uuid())] ts = TaskSetResult(uuid(), subs) self.assertIs(ts[0], subs[0]) def test_save_restore(self): subs = [MockAsyncResultSuccess(uuid()), MockAsyncResultSuccess(uuid())] ts = TaskSetResult(uuid(), subs) ts.save() with self.assertRaises(AttributeError): ts.save(backend=object()) self.assertEqual( TaskSetResult.restore(ts.taskset_id).subtasks, ts.subtasks) ts.delete() self.assertIsNone(TaskSetResult.restore(ts.taskset_id)) with self.assertRaises(AttributeError): TaskSetResult.restore(ts.taskset_id, backend=object()) def test_join_native(self): backend = SimpleBackend() subtasks = [AsyncResult(uuid(), backend=backend) for i in range(10)] ts = TaskSetResult(uuid(), subtasks) backend.ids = [subtask.id for subtask in subtasks] res = ts.join_native() self.assertEqual(res, range(10)) def test_iter_native(self): backend = SimpleBackend() subtasks = [AsyncResult(uuid(), backend=backend) for i in range(10)] ts = TaskSetResult(uuid(), subtasks) backend.ids = [subtask.id for subtask in subtasks] self.assertEqual(len(list(ts.iter_native())), 10) def test_iterate_yields(self): ar = MockAsyncResultSuccess(uuid()) ar2 = MockAsyncResultSuccess(uuid()) ts = TaskSetResult(uuid(), [ar, ar2]) it = iter(ts) self.assertEqual(it.next(), 42) self.assertEqual(it.next(), 42) def test_iterate_eager(self): ar1 = EagerResult(uuid(), 42, states.SUCCESS) ar2 = EagerResult(uuid(), 42, states.SUCCESS) ts = TaskSetResult(uuid(), [ar1, ar2]) it = iter(ts) self.assertEqual(it.next(), 42) self.assertEqual(it.next(), 42) def test_join_timeout(self): ar = MockAsyncResultSuccess(uuid()) ar2 = MockAsyncResultSuccess(uuid()) ar3 = AsyncResult(uuid()) ts = TaskSetResult(uuid(), [ar, ar2, ar3]) with self.assertRaises(TimeoutError): ts.join(timeout=0.0000001) def test_itersubtasks(self): it = self.ts.itersubtasks() for i, t in enumerate(it): self.assertEqual(t.get(), i) def test___iter__(self): it = iter(self.ts) results = sorted(list(it)) self.assertListEqual(results, list(xrange(self.size))) def test_join(self): joined = self.ts.join() self.assertListEqual(joined, list(xrange(self.size))) def test_successful(self): self.assertTrue(self.ts.successful()) def test_failed(self): self.assertFalse(self.ts.failed()) def test_waiting(self): self.assertFalse(self.ts.waiting()) def test_ready(self): self.assertTrue(self.ts.ready()) def test_completed_count(self): self.assertEqual(self.ts.completed_count(), len(self.ts))