Exemplo n.º 1
0
def test_data_returns_none_for_invalid_index():
    """ When getting data, nothing is returned for invalid index """
    # Given
    model = TreeModel()
    project = ResearchProject("")
    plan = ResearchPlan()
    project.plans.append(plan)

    model.set_project(project)

    # When
    retval = model.data(QModelIndex(), Qt.DisplayRole)

    # Then
    assert retval is None
Exemplo n.º 2
0
def test_setdata_updates_description():
    """ setData() works on the description """
    # Given
    model = TreeModel()
    project = ResearchProject("")
    plan = ResearchPlan()
    project.plans.append(plan)

    model.set_project(project)
    plan_index = model.index(0, 1, model.plans_index)

    # When
    retval = model.setData(plan_index, "Foo")

    assert retval is True
    assert model.data(plan_index, Qt.DisplayRole) == "Foo"
Exemplo n.º 3
0
def test_data_returns_none_for_invalid_role():
    """ When getting data, invalid role returns None """
    # Given
    model = TreeModel()
    project = ResearchProject("")
    plan = ResearchPlan()
    plan.ancestor = "Foo"
    project.plans.append(plan)

    model.set_project(project)
    plan_index = model.index(0, 0, model.plans_index)

    # When
    retval = model.data(plan_index, Qt.UserRole)

    # Then
    assert retval is None
Exemplo n.º 4
0
def test_data_returns_qicon_for_decoration_role():
    """ When getting data, decoration role returns an icon """
    # Given
    model = TreeModel()
    project = ResearchProject("")
    plan = ResearchPlan()
    plan.ancestor = "Foo"
    project.plans.append(plan)

    model.set_project(project)
    plan_index = model.index(0, 0, model.plans_index)

    # When
    retval = model.data(plan_index, Qt.DecorationRole)

    # Then
    assert isinstance(retval, QIcon)
Exemplo n.º 5
0
def test_data_returns_string_for_valid_index():
    """ When getting data, ancestor is returned for valid index """
    # Given
    model = TreeModel()
    project = ResearchProject("")
    plan = ResearchPlan()
    plan.ancestor = "Foo"
    project.plans.append(plan)

    model.set_project(project)
    plan_index = model.index(0, 0, model.plans_index)

    # When
    retval = model.data(plan_index, Qt.DisplayRole)

    # Then
    assert retval is plan.ancestor
Exemplo n.º 6
0
def test_data_returns_none_for_invalid_column():
    """ When getting data, invalid column returns None """
    # Given
    model = TreeModel()
    project = ResearchProject("")
    plan = ResearchPlan()
    plan.ancestor = "Foo"
    project.plans.append(plan)

    model.set_project(project)
    plan_index = model.index(0,
                             len(list(TreeModelCols)) + 1, model.plans_index)

    # When
    retval = model.data(plan_index, Qt.DisplayRole)

    # Then
    assert retval is None
Exemplo n.º 7
0
def test_setdata_updates_link():
    """ setData() works on the link """
    # Given
    model = TreeModel()
    project = ResearchProject("")
    plan = ResearchPlan()
    project.plans.append(plan)
    project.plans[0].add_task()

    model.set_project(project)
    plan_index = model.index(0, 0, model.plans_index)
    task_index = model.index(0, TreeModelCols.LINK, plan_index)

    # When
    retval = model.setData(task_index, 1234)

    assert retval is True
    assert model.data(task_index, Qt.DisplayRole) == 1234
Exemplo n.º 8
0
def test_get_font_returns_strikeout_for_task_with_result():
    """ A task with a nil result should show up as strike-out """
    # Given
    model = TreeModel()
    project = ResearchProject("")
    plan = ResearchPlan()
    task = ResearchTask()
    task.result = ResearchResult(False)
    plan.tasks.append(task)
    project.plans.append(plan)

    model.set_project(project)

    plan_index = model.index(0, 0, model.plans_index)
    task_index = model.index(0, 0, plan_index)

    # When
    font = model.data(task_index, Qt.FontRole)

    # Then
    assert font.strikeOut() is True
Exemplo n.º 9
0
def test_setdata_updates_result():
    """ setData() works on the result """
    # Given
    model = TreeModel()
    project = ResearchProject("")
    plan = ResearchPlan()
    project.plans.append(plan)
    project.plans[0].add_task()

    model.set_project(project)
    plan_index = model.index(0, 0, model.plans_index)
    task_index = model.index(0, 2, plan_index)

    result = ResearchResult(True)
    result.description = "Test"

    # When
    retval = model.setData(task_index, result)

    assert retval is True
    assert model.data(task_index, Qt.DisplayRole) == result