def test_get_task_ratio_relative(self): ratio = _get_task_ratio([MyTaskSet], False, 1.0) self.assertEqual(1.0, ratio["MyTaskSet"]["ratio"]) self.assertEqual(0.75, ratio["MyTaskSet"]["tasks"]["root_task"]["ratio"]) self.assertEqual(0.25, ratio["MyTaskSet"]["tasks"]["MySubTaskSet"]["ratio"]) self.assertEqual(0.5, ratio["MyTaskSet"]["tasks"]["MySubTaskSet"]["tasks"]["task1"]["ratio"]) self.assertEqual(0.5, ratio["MyTaskSet"]["tasks"]["MySubTaskSet"]["tasks"]["task2"]["ratio"])
def test_get_task_ratio_total(self): ratio = _get_task_ratio([MyTaskSet], True, 1.0) self.assertEqual(1.0, ratio["MyTaskSet"]["ratio"]) self.assertEqual(0.75, ratio["MyTaskSet"]["tasks"]["root_task"]["ratio"]) self.assertEqual(0.25, ratio["MyTaskSet"]["tasks"]["MySubTaskSet"]["ratio"]) self.assertEqual(0.125, ratio["MyTaskSet"]["tasks"]["MySubTaskSet"]["tasks"]["task1"]["ratio"]) self.assertEqual(0.125, ratio["MyTaskSet"]["tasks"]["MySubTaskSet"]["tasks"]["task2"]["ratio"])
def test_task_ratio_command(self): class Tasks(TaskSet): @task def root_task1(self): pass @task class SubTasks(TaskSet): @task def task1(self): pass @task def task2(self): pass class MyUser(User): tasks = [Tasks] ratio_dict = _get_task_ratio(Tasks.tasks, True, 1.0) self.assertEqual( { "SubTasks": { "tasks": { "task1": { "ratio": 0.25 }, "task2": { "ratio": 0.25 } }, "ratio": 0.5 }, "root_task1": { "ratio": 0.5 }, }, ratio_dict, )