예제 #1
0
def test_instance_container_load():
    instances = get_gedcom_instance_container(os.path.join(os.path.dirname(__file__),'gramps_sample.ged'))

    assert len(instances._data) == 2
    # autocreate
    i = instances[('i', '@I1@')]
    assert len(instances._data) == 3
    assert i.plain_name == 'Keith Lloyd Smith'

    f = instances[('f', '@F1@')]
    assert len(instances._data) == 4
    assert f.wife_individual_id == '@I25@'
    assert f.husband_individual_id == '@I27@'

    # asking does not instantiate
    assert not ('i', '@I2@') in instances

    # load all
    instances.instantiate_all(instances)
    assert len(instances._data) == 59

    assert ('i', '@I2@') in instances

    # get all individuals   
    individuals = [instance for key, instance in instances.items() if key[0] == 'i']
    assert len(individuals) == 42
예제 #2
0
def test_generate_svg_file_with_two_roots():
    max_generations = 20
    x_position = 0
    last_individual_pos = None
    graph = AncestorGraph(
        instance_container=lambda: get_gedcom_instance_container(
            os.path.join(os.path.dirname(__file__), 'autogenerated.ged')))

    # select individual to show
    gedcom_data = open(
        os.path.join(os.path.dirname(__file__), 'autogenerated.ged'),
        'r').read()
    last_individual_pos = gedcom_data.rfind(' FAMC ', 0, last_individual_pos)
    last_individual_pos = gedcom_data.rfind('\n0 @I', 0, last_individual_pos)
    individual_id = gedcom_data[last_individual_pos + 3:gedcom_data.
                                find(' INDI', last_individual_pos + 1)]

    graph.select_individuals(graph._instances[('i', individual_id)],
                             generations=max_generations)

    cof_ids = graph._instances[('i', individual_id)].child_of_family_id
    child_of_family = None
    if cof_ids:
        child_of_family = graph._instances[('f', cof_ids[0])]
    graph.place_selected_individuals(graph._instances[('i', individual_id)],
                                     None, None, child_of_family, x_position)
    width = graph._instances[(
        'i', individual_id)].graphical_representations[0].get_width(None)
    x_position += width
    graph.modify_layout(individual_id)

    # select individual to show
    # gedcom_data = open(os.path.join(os.path.dirname(__file__), 'autogenerated.ged'),'r').read()
    last_individual_pos = gedcom_data.rfind(
        ' FAMC ', 0, last_individual_pos - int(len(gedcom_data) * 0.2))
    last_individual_pos = gedcom_data.rfind(' FAMC ', 0, last_individual_pos)
    last_individual_pos = gedcom_data.rfind('\n0 @I', 0, last_individual_pos)
    individual_id = gedcom_data[last_individual_pos + 3:gedcom_data.
                                find(' INDI', last_individual_pos + 1)]

    graph.select_individuals(graph._instances[('i', individual_id)],
                             generations=max_generations)

    cof_ids = graph._instances[('i', individual_id)].child_of_family_id
    child_of_family = None
    if cof_ids:
        child_of_family = graph._instances[('f', cof_ids[0])]
    graph.place_selected_individuals(graph._instances[('i', individual_id)],
                                     None, None, child_of_family, x_position)
    width = graph._instances[(
        'i', individual_id)].graphical_representations[0].get_width(None)
    x_position += width

    graph.define_svg_items()
    graph.paint_and_save(
        individual_id,
        os.path.join(os.path.dirname(__file__), 'output',
                     'test_svg_two_roots.svg'))
예제 #3
0
def test_instance_container_labels():
    instances = get_gedcom_instance_container(os.path.join(os.path.dirname(__file__),'gramps_sample.ged'))
    
    # load all
    instances.instantiate_all(instances)
    assert len(instances._data) == 59

    # get all individuals   
    individual_plain_names = [instance.plain_name for key, instance in instances.items() if key[0] == 'i']
    individual_birth_labels = [instance.birth_label for key, instance in instances.items() if key[0] == 'i']
    individual_death_labels = [instance.death_label for key, instance in instances.items() if key[0] == 'i']
    assert str(individual_plain_names[1:5]) == "['Keith Lloyd Smith', 'Hans Peter Smith', 'Hanna Smith', 'Herman Julius Nielsen']"
    assert str(individual_birth_labels[1:5]) == "['* 11.08.1966', '* 17.04.1904', '* 29.01.1821', '* 31.08.1889']"
    assert str(individual_death_labels[1:5]) == "['', '† 29.01.1977', '† geschätzt 1896', '† 1945']"
예제 #4
0
def test_fotos_in_chart():
    max_generations = 3
    x_position = 0
    last_individual_pos = None
    graph = AncestorGraph(
        instance_container=lambda: get_gedcom_instance_container(
            os.path.join(os.path.dirname(__file__), 'autogenerated.ged')),
        formatting={
            'relative_line_thickness': 0.7,
            'vertical_step_size': 50,
            'total_height': 3000,
            'individual_foto_relative_size': 2
        })

    individual_id = '@I6@'

    graph.select_individuals(graph._instances[('i', individual_id)],
                             generations=max_generations)

    images = {}
    import re, datetime
    expr = re.compile(r'individual_I6_image_age_(\d+)\.png')
    image_step_size = 365 * 4.0
    birth_ordinal_value = graph._instances[(
        'i', individual_id)].events['birth_or_christening']['ordinal_value']
    sorted_list = []
    for filename in os.listdir(
            os.path.join(os.path.dirname(__file__), 'images')):
        match = expr.match(filename)
        if match:
            year = int(match.group(1)) + 1032
            month = 1
            day = 1
            # elif match.group(3) is None::
            #     month = max(1, int(match.group(3)))
            ordinal_value = datetime.date(year, month, day).toordinal()
            sorted_list.append((ordinal_value, year, filename))
    sorted_list.sort()
    for ordinal_value, year, filename in sorted_list:
        if len(images) > 0:
            max_ordinal = max(list(images.keys()))
        else:
            max_ordinal = -1
        if round(
            (ordinal_value - birth_ordinal_value) / image_step_size) > round(
                (max_ordinal - birth_ordinal_value) / image_step_size):
            images[birth_ordinal_value +
                   round((ordinal_value - birth_ordinal_value) /
                         image_step_size) * image_step_size] = os.path.join(
                             os.path.dirname(__file__), 'images', filename)

    graph._instances[('i', individual_id)].images.update(images)
    #graph._instances[('i', '@I1@')].images.update(images)

    cof_ids = graph._instances[('i', individual_id)].child_of_family_id
    child_of_family = None
    if cof_ids:
        child_of_family = graph._instances[('f', cof_ids[0])]
    graph.place_selected_individuals(graph._instances[('i', individual_id)],
                                     None, None, child_of_family, x_position)
    width = graph._instances[(
        'i', individual_id)].graphical_representations[0].get_width(None)
    x_position += width
    graph.modify_layout(individual_id)

    graph.define_svg_items()
    graph.paint_and_save(
        individual_id,
        os.path.join(os.path.dirname(__file__), 'output',
                     'test_svg_fotos.svg'))