コード例 #1
0
def test_setdata_returns_false_on_invalid_index():
    """ When setting data, false is returned for invalid index """
    # Given
    model = TreeModel()
    project = ResearchProject("")
    plan = ResearchPlan()
    project.plans.append(plan)

    model.set_project(project)

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

    assert retval is False
コード例 #2
0
def test_setdata_returns_false_on_invalid_column():
    """ When setting data, false is returned for invalid column """
    # Given
    model = TreeModel()
    project = ResearchProject("")
    plan = ResearchPlan()
    project.plans.append(plan)

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

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

    assert retval is False
コード例 #3
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"
コード例 #4
0
def test_setdata_fires_signal_on_change(qtbot):
    """ When setting data, the dataChanged signal is emitted on changes """
    # Given
    model = TreeModel()
    project = ResearchProject("")
    plan = ResearchPlan()
    project.plans.append(plan)

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

    # When
    with qtbot.waitSignal(model.dataChanged):
        retval = model.setData(plan_index, "Foo")

    assert retval is True
コード例 #5
0
def test_setdata_doesnot_fire_signal_if_no_change(qtbot):
    """ When setting data, the dataChanged signal should only be emitted on actual changes """
    # Given
    model = TreeModel()
    project = ResearchProject("")
    plan = ResearchPlan()
    project.plans.append(plan)

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

    # When
    with qtbot.assertNotEmitted(model.dataChanged):
        retval = model.setData(plan_index, plan.ancestor)

    assert retval is True
コード例 #6
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
コード例 #7
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