Пример #1
0
def three_indi_model():
    """ Fixture to create a basic model """
    individuals = []
    individuals.append(Individual("I001", "Foo1", "Person", 1901, 1951))
    individuals.append(Individual("I002", "Foo2", "Person", 1902, 1952))
    individuals.append(Individual("I003", "Foo3", "Person", 1903, 1953))

    return IndividualsModel(individuals)
Пример #2
0
def test_plan_links_are_checked():
    """
    Check the following:
    * Unchanged links are respected
    * Broken links are identified
    * Updated links are identified
    """

    # Given
    project = ResearchProject("")
    individuals = []
    sources = []

    indi_linked = Individual("I1234", "Link", "Indi", 1000, 2000)
    individuals.append(indi_linked)
    plan_linked = ResearchPlan()
    plan_linked.ancestor = indi_linked.autocomplete_name()
    plan_linked.ancestor_link = indi_linked.pointer
    project.plans.append(plan_linked)

    plan_broken = ResearchPlan()
    plan_broken.ancestor = "Broken Ancestor 1234/5678"
    plan_broken.ancestor_link = "FooBar"
    project.plans.append(plan_broken)

    indi_altered = Individual("I9876", "Altered", "Indi", 1000, 2000)
    individuals.append(indi_altered)
    plan_altered = ResearchPlan()
    plan_altered.ancestor = "Altered Ancestor 1000/2000"
    plan_altered.ancestor_link = indi_altered.pointer
    project.plans.append(plan_altered)

    tree_model = TreeModel()
    tree_model.set_project(project)

    individuals_model = IndividualsModel(individuals)
    sources_model = SourcesModel(sources)

    context = DataContext(
        data_model=tree_model,
        individuals_model=individuals_model,
        sources_model=sources_model,
    )
    updater = LinkUpdater(context)

    # When
    updater.calculate_updates()

    # Then
    assert updater.has_pending_updates() is True
    assert len(updater.ancestor_updates) == 1
    assert len(updater.source_updates) == 0
Пример #3
0
def test_data_returns_values_in_individual_record():
    """ Check the first name """
    # Given
    individuals = []
    indi = Individual("I001", "Test", "Person", 1901, 1951)
    individuals.append(indi)

    model = IndividualsModel(individuals)

    # When
    pointer = model.data(model.index(0, IndividualsModelColumns.POINTER))
    first = model.data(model.index(0, IndividualsModelColumns.FIRST_NAME))
    last = model.data(model.index(0, IndividualsModelColumns.LAST_NAME))
    birth = model.data(model.index(0, IndividualsModelColumns.BIRTH_YEAR))
    death = model.data(model.index(0, IndividualsModelColumns.DEATH_YEAR))
    autocomplete = model.data(
        model.index(0, IndividualsModelColumns.AUTOCOMPLETE))
    # Then
    assert model.columnCount() == 6
    assert pointer == indi.pointer
    assert first == indi.first_name
    assert last == indi.last_name
    assert birth == indi.birth_year
    assert death == indi.death_year
    assert autocomplete != ""
Пример #4
0
def test_format_year_returns_placeholder_for_invalid_year():
    """ When format_year is called with an invalid year, some placeholder is returned """
    # Given

    # When
    text = Individual.format_year(-200)

    # Then
    assert text == "?"
Пример #5
0
def test_format_year_returns_year_stringified():
    """ When format_year is called with an invalid year, some placeholder is returned """
    # Given

    # When
    text = Individual.format_year(1967)

    # Then
    assert text == "1967"
Пример #6
0
def test_clear_link_removes_caches():
    """ When the link is removed, the caches should be cleared too """
    # Given
    manager = GedcomManager(DataContext())
    manager.individuals.append(Individual("I000", "Test", "User", 1900, 1999))
    manager.sources.append(Source("S000", "Test", "User", "S/O", "ABB"))

    # When
    manager.clear_link()

    # Then
    assert len(manager.individuals) == 0
    assert len(manager.sources) == 0
Пример #7
0
def test_refresh_link_reloads_file():
    """ When the link is removed, the caches should be cleared too """
    # Given
    manager = GedcomManager(DataContext())
    manager.individuals.append(Individual("IND01", "Test", "User", 1900, 1999))
    manager.sources.append(Source("SOU01", "Test", "User", "S/O", "ABB"))

    # When
    manager.refresh_link("tests/unit/test.ged")

    # Then
    assert len(manager.individuals) == 2
    assert manager.individuals[0].pointer == "I0000"
    assert len(manager.sources) == 2
    assert manager.sources[0].pointer == "S0000"
Пример #8
0
def test_update_list_changes_data(qtbot):
    """ Check the first name """
    # Given
    model = IndividualsModel()
    assert model.rowCount() == 0

    individuals = []
    indi = Individual("I001", "Test", "Person", 1901, 1951)
    individuals.append(indi)

    # When
    with qtbot.waitSignals([model.modelAboutToBeReset, model.modelReset]):
        model.update_list(individuals)

    # Then
    assert model.rowCount() == 1
Пример #9
0
def test_autocomplete_name_includes_relevant_data():
    """ Check the first name """
    # Given
    individuals = []
    indi = Individual("I001", "Test", "Person", 1901, 1951)
    individuals.append(indi)

    model = IndividualsModel(individuals)
    index = model.index(0, IndividualsModelColumns.AUTOCOMPLETE)

    # When
    descriptive_name = model.data(index)

    # Then
    assert indi.pointer not in descriptive_name
    assert indi.first_name in descriptive_name
    assert indi.last_name in descriptive_name
    assert str(indi.birth_year) in descriptive_name
    assert str(indi.death_year) in descriptive_name