Exemplo n.º 1
0
def test_output_graph6(tmpdir):

    g = build_graph()
    tmpfile = tmpdir.join('graph.g6')
    tmpfilename = str(tmpfile)

    write_graph6(g, tmpfilename)

    # read back

    def va_cb(vertex, attribute_name, attribute_value):
        assert attribute_name == 'ID'
        assert str(vertex) == attribute_value

    g1 = create_graph(directed=False,
                      allowing_self_loops=False,
                      allowing_multiple_edges=False,
                      weighted=True)
    read_graph6sparse6(g1, tmpfilename, vertex_attribute_cb=va_cb)

    assert len(g1.vertices()) == 4
    assert len(g1.edges()) == 5
Exemplo n.º 2
0
def test_read_anyhashableg_sparse6_graph_from_file(tmpdir):
    tmpfile = tmpdir.join("gml.out")
    tmpfilename = str(tmpfile)

    with open(tmpfilename, "w") as f:
        f.write(":Cca")

    g = create_graph(
        directed=False,
        allowing_self_loops=False,
        allowing_multiple_edges=False,
        weighted=True,
        any_hashable=True,
        vertex_supplier=create_vertex_supplier(type='int'),
        edge_supplier=create_edge_supplier(type='int'),
    )

    def import_id_cb(id):
        return int(id)

    read_graph6sparse6(g, tmpfilename, import_id_cb=import_id_cb)

    assert g.vertices == {0, 1, 2, 3}
    assert g.edge_tuple(0) == (0, 1, 1.0)