import unittest
from caravan.task import Task
from caravan.tables import Tables


class TestRun(unittest.TestCase):
    def setUp(self):
        self.t = Tables.get()
        self.t.clear()

    def test_task(self):
        t = Task(1234, "echo hello world")
        self.assertEqual(t.id(), 1234)
        self.assertEqual(t.is_finished(), False)
        self.assertEqual(t.command(), "echo hello world")
        t._store_result([1.0, 2.0, 3.0], 0, 3, 111, 222)
        self.assertTrue(t.is_finished())
        self.assertEqual(t.rc(), 0)
        self.assertEqual(t.rank(), 3)
        self.assertEqual(t.start_at(), 111)
        self.assertEqual(t.finish_at(), 222)

    def test_create(self):
        for i in range(10):
            t = Task.create("echo %d" % i)
            self.assertEqual(t.id(), i)
            self.assertEqual(t.is_finished(), False)
        self.assertEqual(len(Task.all()), 10)

    def test_all(self):
        tasks = [Task.create("echo %d" % i) for i in range(10)]
        self.assertEqual(Task.all(), tasks)

    def test_find(self):
        tasks = [Task.create("echo %d" % i) for i in range(10)]
        self.assertEqual(Task.find(5).id(), 5)
        self.assertEqual(Task.find(5), tasks[5])


if __name__ == '__main__':
    unittest.main()

[((1256, 1271), 'unittest.main', 'unittest.main', ([], {}), '()\n', (1269, 1271), False, 'import unittest\n'), ((154, 166), 'caravan.tables.Tables.get', 'Tables.get', ([], {}), '()\n', (164, 166), False, 'from caravan.tables import Tables\n'), ((228, 258), 'caravan.task.Task', 'Task', (['(1234)', '"""echo hello world"""'], {}), "(1234, 'echo hello world')\n", (232, 258), False, 'from caravan.task import Task\n'), ((738, 764), 'caravan.task.Task.create', 'Task.create', (["('echo %d' % i)"], {}), "('echo %d' % i)\n", (749, 764), False, 'from caravan.task import Task\n'), ((946, 972), 'caravan.task.Task.create', 'Task.create', (["('echo %d' % i)"], {}), "('echo %d' % i)\n", (957, 972), False, 'from caravan.task import Task\n'), ((1018, 1028), 'caravan.task.Task.all', 'Task.all', ([], {}), '()\n', (1026, 1028), False, 'from caravan.task import Task\n'), ((1080, 1106), 'caravan.task.Task.create', 'Task.create', (["('echo %d' % i)"], {}), "('echo %d' % i)\n", (1091, 1106), False, 'from caravan.task import Task\n'), ((1199, 1211), 'caravan.task.Task.find', 'Task.find', (['(5)'], {}), '(5)\n', (1208, 1211), False, 'from caravan.task import Task\n'), ((887, 897), 'caravan.task.Task.all', 'Task.all', ([], {}), '()\n', (895, 897), False, 'from caravan.task import Task\n'), ((1152, 1164), 'caravan.task.Task.find', 'Task.find', (['(5)'], {}), '(5)\n', (1161, 1164), False, 'from caravan.task import Task\n')]