Exemplo n.º 1
0
def project():
    '''
    1 ->           5
        |-> 3 -> |
    2 ->           6
         | 4
    '''
    task1 = task_factory('1', 1)
    task2 = task_factory('2', 2)
    task3 = task_factory('3', 3)
    task4 = task_factory('4', 2)
    task5 = task_factory('5', 1)
    task6 = task_factory('6', 2)
    current_time = datetime(year=2018, month=5, day=14)
    task4.latest_finish_date_pdf = make_deterministic_date_pdf(current_time, 5)
    task5.latest_finish_date_pdf = make_deterministic_date_pdf(current_time, 9)
    task6.latest_finish_date_pdf = make_deterministic_date_pdf(current_time, 7)

    class MockModel:
        def predict(self, data):
            return DurationPdf(DeterministicPdf(data['a']))

    proj = Project('proj', MockModel())
    proj.add_dependencies([(task1, task3), (task2, task3), (task2, task4),
                           (task3, task5), (task3, task6)])
    return proj, {
        task.name: task
        for task in [task1, task2, task3, task4, task5, task6]
    }
Exemplo n.º 2
0
def test_artist_base_find_longest_path_length_no_path():
    project = Project('proj', MockModel())
    tasks = {str(i): Task(str(i), data={'a': i}) for i in range(1, 4)}
    project.add_tasks(tasks.values())
    project.add_dependency(tasks['1'], tasks['2'])
    start_tasks, terminal_tasks = project.get_starting_and_terminal_tasks()
    assert ArtistBase(project)._find_longest_path_length(
        start_tasks, terminal_tasks) == 2
Exemplo n.º 3
0
def test_init():
    class MockModel:
        pass

    model = MockModel()
    project = Project('important_proc', model=model)
    assert project.name == 'important_proc'
    assert project.model == model
Exemplo n.º 4
0
def test_project_from_dict_no_tasks():
    dict_in = {'name': 'proj1'}

    class MockModel:
        pass

    model = MockModel()
    proj = Project.from_dict(dict_in, model)
    assert proj.uid is not None
    assert proj.name == 'proj1'
    assert proj.model is model
Exemplo n.º 5
0
def large_project():
    project = Project('proj', MockModel())
    tasks = {str(i): Task(str(i), data={'a': i}) for i in range(1, 9)}

    # Longest path will be {1, 2}-3-4-6-{7, 8}
    project.add_dependencies([
        (tasks['1'], tasks['3']), (tasks['2'], tasks['3']),
        (tasks['3'], tasks['4']), (tasks['4'], tasks['5']),
        (tasks['4'], tasks['6']), (tasks['6'], tasks['7']),
        (tasks['6'], tasks['8'])
    ])
    return project, tasks
Exemplo n.º 6
0
def simple_project():
    '''
    1 ->
        |-> 3
    2 ->
    '''
    task1 = task_factory('1', 1)
    task2 = task_factory('2', 2)
    task3 = task_factory('3', 3)
    current_time = datetime(year=2018, month=5, day=14)
    task3.latest_finish_date_pdf = make_deterministic_date_pdf(current_time, 5)

    proj = Project('proj', MockModel())
    proj.add_dependencies([(task1, task3), (task2, task3)])
    return proj, {task.name: task for task in [task1, task2, task3]}
Exemplo n.º 7
0
def test_project_get_starting_and_terminal_tasks():
    project = Project('proj', MockModel())
    tasks = {str(i): Task(str(i), data={'a': i}) for i in range(1, 9)}
    start_tasks = [tasks['1'], tasks['2']]
    terminal_tasks = [tasks['5'], tasks['7'], tasks['8']]
    current_date = datetime.utcnow()
    for task in terminal_tasks:
        task.latest_finish_date_pdf = make_deterministic_date_pdf(
            current_date, 1)

    # Longest path will be {1, 2}-3-4-6-{7, 8}
    project.add_dependencies([
        (tasks['1'], tasks['3']), (tasks['2'], tasks['3']),
        (tasks['3'], tasks['4']), (tasks['4'], tasks['5']),
        (tasks['4'], tasks['6']), (tasks['6'], tasks['7']),
        (tasks['6'], tasks['8'])
    ])
    found_start, found_terminal = project.get_starting_and_terminal_tasks()
    assert (set(found_start), set(found_terminal)) == (set(start_tasks),
                                                       set(terminal_tasks))
Exemplo n.º 8
0
def test_project_from_dict_with_tasks_with_durations():
    task1 = task_factory('1', 1)
    task2 = task_factory('2', 2)
    task3 = task_factory('3', 3)
    task4 = task_factory('4', 2)
    task5 = task_factory('5', 1)
    task6 = task_factory('6', 2)
    tasks = [task1, task2, task3, task4, task5, task6]
    data_in = {
        'name':
        'proj',
        'tasks':
        tasks,
        'dependencies': [{
            'source': source.uid,
            'destination': destination.uid
        } for source, destination in [(task1, task3), (
            task2, task3), (task2, task4), (task3, task5), (task3, task6)]]
    }

    class MockModel:
        pass

    model = MockModel()
    proj = Project.from_dict(data_in, model)
    assert proj.uid is not None
    assert proj.name == 'proj'
    assert proj.model is model
    for task in tasks:
        assert task in proj.tasks
    assert set(proj.successors(task1)) == {task3}
    assert set(proj.successors(task2)) == {task4, task3}
    assert set(proj.successors(task3)) == {task5, task6}
    for task in {task5, task6}:
        assert set(proj.successors(task)) == set()
    for task in {task1, task2}:
        assert set(proj.predecessors(task)) == set()
    assert set(proj.predecessors(task3)) == {task1, task2}
    assert set(proj.predecessors(task4)) == {task2}
    assert set(proj.predecessors(task5)) == {task3}
    assert set(proj.predecessors(task6)) == {task3}
Exemplo n.º 9
0
def test_project_from_dict_with_tasks_without_durations():
    task1 = Task('1', data={'a': 1})
    task2 = Task('2', data={'a': 2})
    task3 = Task('3', data={'a': 3})
    tasks = [task1, task2, task3]
    data_in = {
        'name':
        'proj',
        'tasks':
        tasks,
        'dependencies': [{
            'source': source.uid,
            'destination': destination.uid
        } for source, destination in [(task1, task3), (task2, task3)]]
    }

    class MockModel:
        def predict(self, data):
            return DeterministicPdf(data['a'])

    model = MockModel()
    proj = Project.from_dict(data_in, model)

    assert proj.uid is not None
    assert proj.name == 'proj'
    assert proj.model is model
    for task in tasks:
        assert task in proj.tasks
        assert task.project_uid == proj.uid
    for task in {task1, task2}:
        assert set(proj.successors(task)) == {task3}
    assert set(proj.successors(task3)) == set()
    for task in {task1, task2}:
        assert set(proj.predecessors(task)) == set()
    assert set(proj.predecessors(task3)) == {task1, task2}

    for task in tasks:
        assert task.duration_pdf.mean == task.data['a']