Esempio n. 1
0
 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)
Esempio n. 2
0
 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)
Esempio n. 3
0
    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)
Esempio n. 4
0
 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)
Esempio n. 5
0
    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)
Esempio n. 6
0
 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')
Esempio n. 7
0
 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')
Esempio n. 8
0
    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)
Esempio n. 9
0
 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())
Esempio n. 10
0
    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())
Esempio n. 11
0
 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())
Esempio n. 12
0
 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)
Esempio n. 13
0
    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)
Esempio n. 14
0
 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())
Esempio n. 15
0
 def test_init3(self):
     Task(name='task', cmd='echo hello world')
Esempio n. 16
0
 def test_add_duplicate_task(self):
     wf = jetstream.Workflow()
     t1 = Task()
     t2 = Task()
     wf.add(t1)
     self.assertRaises(ValueError, wf.add, t2)
Esempio n. 17
0
 def test_init2(self):
     Task(name='task')
Esempio n. 18
0
 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')
Esempio n. 19
0
 def test_change_status(self):
     t = Task(name='task')
     self.assertEqual(t.status, 'new')
Esempio n. 20
0
 def test_init(self):
     Task()
Esempio n. 21
0
 def test_fail(self):
     t = Task(name='task')
     t.fail()
     self.assertEqual(t.status, 'failed')
Esempio n. 22
0
 def new_task(self, *args, **kwargs):
     task = Task(*args, **kwargs)
     self.add(task)
     return task