class DateConstraintsTC(TestCase): def setUp(self): self.parent = Task('parent') self.child = Task('child') self.parent.append(self.child) def test_parent_begin_at(self): self.assertEqual(self.child.get_date_constraints(), set()) self.parent.add_date_constraint(BEGIN_AT_DATE, DateTime(2005, 01, 01)) constraints = self.child.get_date_constraints() expected = set([(BEGIN_AFTER_DATE, DateTime(2005, 01, 01), 1)]) self.assertEqual(constraints, expected) def test_parent_begin_after(self): self.assertEqual(self.child.get_date_constraints(), set()) self.parent.add_date_constraint(BEGIN_AFTER_DATE, DateTime(2005, 01, 01)) constraints = self.child.get_date_constraints() expected = set([(BEGIN_AFTER_DATE, DateTime(2005, 01, 01), 1)]) self.assertEqual(constraints, expected) def test_parent_end_at(self): self.assertEqual(self.child.get_date_constraints(), set()) self.parent.add_date_constraint(END_AT_DATE, DateTime(2005, 01, 01)) constraints = self.child.get_date_constraints() expected = set([(END_BEFORE_DATE, DateTime(2005, 01, 01), 1)]) self.assertEqual(constraints, expected) def test_parent_end_before(self): self.assertEqual(self.child.get_date_constraints(), set()) self.parent.add_date_constraint(END_BEFORE_DATE, DateTime(2005, 01, 01)) constraints = self.child.get_date_constraints() expected = set([(END_BEFORE_DATE, DateTime(2005, 01, 01), 1)]) self.assertEqual(constraints, expected)
def test_get_progress(self): """tests progress' getter""" t = Task('hello') t.duration = 10 self.assertEqual(t.progress, 0.) #activity = [100, DateTime(2005, 8, 1), DateTime(2005, 8, 4)] # #self.assertEqual(t.progress, 0.4) t.progress = 0.8 self.assertEqual(t.progress, 0.8)
def test_project_errors(self): """tests inconsistent projects""" # expliclity add duplicate node id self.parent.append(Task('child1')) self.assertEqual(self.project.check_consistency(), ['Duplicate task id: child1'])
def simple_project(): """build a simple project for testing the Project class parent (inge1/1, inge2/1) | |--- child1 (inge1/1), 10 | |--- child2 | | | |--- child2_1 (inge1/0.6), 5 | | | `--- child2_2 (inge2/1), 12 | `--- stone [milestone]""" # create project project = Project() # create tasks project.root_task = parent = Task('parent') child1 = Task('child1') child2 = Task('child2') child2_1 = Task('child2_1') child2_2 = Task('child2_2') stone = MileStone('stone') project.milestones['stone'] = stone # building tree parent.append(child1) parent.append(child2) child2.append(child2_1) child2.append(child2_2) parent.append(stone) # set duration child1.duration = 10 child2_1.duration = 5 child2_2.duration = 12 # calendar calendar = Calendar('typic', 'Typical Calendar') project.calendars['typic'] = calendar cdp = ResourceRole('cdp', 'Chef', 100.0, 'EUR') ingpy = ResourceRole('ingpy', 'Python Developper', 80.0, 'EUR') ingihm = ResourceRole('ingihm', 'Human Interface Ingineer', 70.0, 'EUR') toto = Resource('toto', 'Mike', calendar, [cdp, ingpy]) tata = Resource('tata', 'Mila', calendar, [ingpy, ingihm]) project.resources_roles = dict(cdp=cdp, ingpy=ingpy, ingihm=ingihm) roles = (cdp, ingpy, ingihm) project.resources['toto'] = toto project.resources['tata'] = tata resources = (tata, toto) tasks = (parent, child1, child2, child2_1, child2_2) return project, tasks, resources, roles, stone, calendar
def test_set_progress(self): t = Task('hello') self.assertRaises(ValueError, setattr, t, 'progress', 12) self.assertRaises(ValueError, setattr, t, 'progress', -1) t.progress = 1 self.assertEqual(t.progress, 1.)
def setUp(self): self.parent = Task('parent') self.child = Task('child') self.parent.append(self.child)
def setUp(self): self.date1 = DateTime(2005, 01, 01) self.date2 = DateTime(2005, 01, 02) self.date3 = DateTime(2005, 01, 03) self.date4 = DateTime(2005, 01, 04) date2 = self.date2 date3 = self.date3 self.parent = Task('parent') # add a child per constraint type self.child_begin_at = Task('child_begin_at') self.child_begin_at.add_date_constraint(BEGIN_AT_DATE, date2) self.parent.append(self.child_begin_at) self.child_begin_after = Task('child_begin_after') self.child_begin_after.add_date_constraint(BEGIN_AFTER_DATE, date2) self.parent.append(self.child_begin_after) self.child_begin_before = Task('child_begin_before') self.child_begin_before.add_date_constraint(BEGIN_BEFORE_DATE, date2) self.parent.append(self.child_begin_before) self.child_end_at = Task('child_end_at') self.child_end_at.add_date_constraint(END_AT_DATE, date3) self.parent.append(self.child_end_at) self.child_end_after = Task('child_end_after') self.child_end_after.add_date_constraint(END_AFTER_DATE, date3) self.parent.append(self.child_end_after) self.child_end_before = Task('child_end_before') self.child_end_before.add_date_constraint(END_BEFORE_DATE, date3) self.parent.append(self.child_end_before)
class ConsistencyTC(TestCase): def setUp(self): self.date1 = DateTime(2005, 01, 01) self.date2 = DateTime(2005, 01, 02) self.date3 = DateTime(2005, 01, 03) self.date4 = DateTime(2005, 01, 04) date2 = self.date2 date3 = self.date3 self.parent = Task('parent') # add a child per constraint type self.child_begin_at = Task('child_begin_at') self.child_begin_at.add_date_constraint(BEGIN_AT_DATE, date2) self.parent.append(self.child_begin_at) self.child_begin_after = Task('child_begin_after') self.child_begin_after.add_date_constraint(BEGIN_AFTER_DATE, date2) self.parent.append(self.child_begin_after) self.child_begin_before = Task('child_begin_before') self.child_begin_before.add_date_constraint(BEGIN_BEFORE_DATE, date2) self.parent.append(self.child_begin_before) self.child_end_at = Task('child_end_at') self.child_end_at.add_date_constraint(END_AT_DATE, date3) self.parent.append(self.child_end_at) self.child_end_after = Task('child_end_after') self.child_end_after.add_date_constraint(END_AFTER_DATE, date3) self.parent.append(self.child_end_after) self.child_end_before = Task('child_end_before') self.child_end_before.add_date_constraint(END_BEFORE_DATE, date3) self.parent.append(self.child_end_before) def test_parent_conflict(self): self.parent.add_date_constraint(BEGIN_AT_DATE, self.date1) self.assertEqual(self.parent.check_consistency(), []) self.parent.add_date_constraint(BEGIN_AT_DATE, self.date2) self.assertEqual(len(self.parent.check_consistency()), 1) def test_parent_begin_at2(self): self.parent.add_date_constraint(BEGIN_AT_DATE, self.date2) self.assertEqual(self.parent.check_consistency(), []) def test_parent_begin_at3(self): self.parent.add_date_constraint(BEGIN_AT_DATE, self.date3) self.assertEqual(self.parent.check_consistency(), []) def test_parent_begin_at4(self): self.parent.add_date_constraint(BEGIN_AT_DATE, self.date4) self.assertEqual(self.parent.check_consistency(), [])