def test_save_load(self): task1 = Task("task1") start = datetime(2019, 1, 10, 11, 11) end = datetime(2019, 1, 10, 11, 22) task1.start(dt=start) task1.end(dt=end) task2 = Task("task2") task3 = Task("task3") wok1 = Wok() job1 = Job("job1") wok1.jobs.append(job1) wok1.current_job_idx = 0 job2 = Job("job2") wok1.jobs.append(job2) job1.add_task(task1) job1.add_task(task2) job2.add_task(task3) path = Path.cwd() / ".wok_test" wok1.save(dir=path) wok2 = Wok() wok2.load(dir=path) self.assertEqual(wok2.jobs[wok2.current_job_idx].name, "job1") self.assertEqual(len(wok2.jobs), 2) out = (path / "job1" / "task1").read_text() self.assertEqual( out, "2019-01-10T11:11:00.000000->2019-01-10T11:22:00.000000")
class TestTask(unittest.TestCase): def setUp(self): self.task = Task("tested_task") def test_init(self): self.assertEqual(self.task.name, "tested_task") self.assertEqual(self.task.datetimes, []) self.assertFalse(self.task.is_running()) def test_start(self): now = datetime.now() res = self.task.start(dt=now) self.assertTrue(res) self.assertEqual(self.task.current_datetime, now) self.assertTrue(self.task.is_running()) def test_start_twice(self): now = datetime.now() res = self.task.start(dt=now) self.assertTrue(res) self.assertTrue(self.task.is_running()) res, _ = self.task.start(dt=now) self.assertFalse(res) def test_end(self): res, _ = self.task.end() self.assertFalse(res) self.assertFalse(self.task.is_running()) def test_start_end_save(self): start = datetime(2019, 1, 10, 11, 11) end = datetime(2019, 1, 10, 11, 22) self.task.start(dt=start) self.task.end(dt=end) self.assertEqual(self.task.datetimes, [(start, end)]) self.assertEqual(self.task.current_datetime, None) out = self.task.save() self.assertEqual( out, "2019-01-10T11:11:00.000000->2019-01-10T11:22:00.000000") start2 = datetime(2019, 1, 10, 11, 23) self.task.start(dt=start2) self.assertEqual(self.task.datetimes, [(start, end)]) self.assertEqual(self.task.current_datetime, start2) out = self.task.save() self.assertEqual( out, "2019-01-10T11:11:00.000000->2019-01-10T11:22:00.000000\nC:2019-01-10T11:23:00.000000", ) def test_load(self): start = datetime(2019, 1, 10, 11, 11) end = datetime(2019, 1, 10, 11, 22) self.task.load( ["2019-01-10T11:11:00.000000->2019-01-10T11:22:00.000000"]) self.assertEqual(self.task.datetimes, [(start, end)]) self.assertEqual(self.task.current_datetime, None)