def test_equality_vs_id(self): """Tasks can be equal but distinct objects""" t1 = Task(name='taskA') t2 = Task(name='taskA') self.assertEqual(t1, t2) self.assertIsNot(t1, t2) self.assertEqual(t1.identity, t2.identity)
def test_workflow_contains(self): t1 = Task(name='taskA') t2 = Task(name='taskB') wf = Workflow() wf.add(t1) self.assertIn(t1, wf) self.assertNotIn(t2, wf)
def test_contains(self): """Equality handling means we can test for tasks in containers""" t1 = Task(name='taskA') t2 = Task(name='taskB') l = [1, 2, 3, t1, 'A', 'B', 'C'] self.assertIn(t1, l) self.assertNotIn(t2, l)
def test_equality2(self): """State should not change equality""" t1 = Task(name='taskA') t2 = Task(name='taskA') t1.complete() self.assertEqual(t1, t2) self.assertEqual(t1.name, t2.name) self.assertEqual(t1.identity, t2.identity)
def test_hash_contains(self): """Hash method means tasks can be present in containers that require hashing. """ t1 = Task(name='taskA') t2 = Task(name='taskB') d = {t1: True, 'something': 42} self.assertIn(t1, d) self.assertNotIn(t2, d)
def test_to_dict(self): cmd = 'echo hello world' t = Task(name='task', cmd=cmd, foo='bar') t.complete() d = t.to_dict() self.assertEqual(d['name'], 'task') self.assertEqual(d['cmd'], cmd) self.assertEqual(d['foo'], 'bar') self.assertEqual(d['state']['status'], 'complete')
def test_fail_retry(self): t = Task(name='task', retry=3) t.fail() self.assertEqual(t.status, 'new') t.fail() self.assertEqual(t.status, 'new') t.fail() self.assertEqual(t.status, 'new') t.fail() self.assertEqual(t.status, 'failed')
def test_identity(self): """Equivalent tasks should maintain a single identity across instances """ t1 = Task('foo') t2 = Task('foo') self.assertEqual(t1, t2) self.assertEqual(t1.identity, t2.identity) t1 = Task('foo', cmd='echo hello world') t2 = Task('foo') self.assertEqual(t1, t2) self.assertNotEqual(t1.identity, t2.identity)
def test_complete(self): t = Task(name='task') t.complete() self.assertEqual(t.status, 'complete') self.assertTrue(t.is_complete()) self.assertTrue(t.is_done()) self.assertFalse(t.is_failed())
def test_workflow_mash(self): wf1 = jetstream.random_workflow(n=10) wf2 = jetstream.random_workflow(n=20) common_task = Task(name='in_common') wf1.add(common_task) wf2.add(common_task) for t in wf1: t.complete() wf3 = jetstream.workflows.mash(wf1, wf2) self.assertIn(common_task, wf3) t = wf3['in_common'] self.assertTrue(t.is_complete())
def test_skipped(self): t = Task() t.skip(foo='bar') self.assertEqual(t.status, 'skipped') self.assertTrue(t.is_skipped()) self.assertTrue(t.is_done())
def test_equality(self): """Rehydrated tasks should be equal to initted tasks""" t1 = tasks.from_dict({'name': 'taskA', 'state': {'status': 'new'}}) t2 = Task(name='taskA') self.assertEqual(t1, t2) self.assertEqual(t1.name, t2.name)
def test_task_serializedeserialze(self): t1 = Task(name='task1', cmd='echo hello world', before='foo') t2 = tasks.from_dict(t1.to_dict()) self.assertEqual(t1, t2)
def test_pending_task(self): t = Task(name='task') t.pending() self.assertEqual(t.status, 'pending') self.assertTrue(t.is_pending()) self.assertFalse(t.is_done())
def test_init3(self): Task(name='task', cmd='echo hello world')
def test_add_duplicate_task(self): wf = jetstream.Workflow() t1 = Task() t2 = Task() wf.add(t1) self.assertRaises(ValueError, wf.add, t2)
def test_init2(self): Task(name='task')
def test_change_state(self): t = Task(name='task') t.state['foo'] = 'bar' self.assertEqual(t.state['foo'], 'bar') t.state.update(foo='baz') self.assertEqual(t.state['foo'], 'baz')
def test_change_status(self): t = Task(name='task') self.assertEqual(t.status, 'new')
def test_init(self): Task()
def test_fail(self): t = Task(name='task') t.fail() self.assertEqual(t.status, 'failed')
def new_task(self, *args, **kwargs): task = Task(*args, **kwargs) self.add(task) return task