Example #1
0
def test_dimacs_maxclique(tmpdir):
    g = build_graph()
    tmpfile = tmpdir.join('dimacs.out')
    tmpfilename = str(tmpfile)
    write_dimacs(g, tmpfilename, format='maxclique')

    with open(tmpfilename, "r") as f:
        contents = f.read()
        print(contents)

    assert contents == dimacs_maxclique_expected
def test_anyhashableg_dimacs(tmpdir):
    g = build_property_graph()
    tmpfile = tmpdir.join("dimacs.out")
    tmpfilename = str(tmpfile)
    write_dimacs(g, tmpfilename, format="shortestpath")

    with open(tmpfilename, "r") as f:
        contents = f.read()
        print(contents)

    assert contents == dimacs_sp_expected2
def test_dimacs_coloring(tmpdir):
    g = build_graph()
    tmpfile = tmpdir.join("dimacs.out")
    tmpfilename = str(tmpfile)
    write_dimacs(g, tmpfilename, format="coloring")

    with open(tmpfilename, "r") as f:
        contents = f.read()
        print(contents)

    assert contents == dimacs_coloring_expected
def test_anyhashableg_dimacs_increase_to_positive_id(tmpdir):
    g = create_graph(directed=False,
                     allowing_self_loops=False,
                     allowing_multiple_edges=False,
                     weighted=True,
                     any_hashable=True,
                     edge_supplier=create_edge_supplier(type='int'))

    for i in range(0, 10):
        g.add_vertex(i)

    g.add_edge(0, 1)
    g.add_edge(0, 2)
    g.add_edge(0, 3)
    g.add_edge(0, 4)
    g.add_edge(0, 5)
    g.add_edge(0, 6)
    g.add_edge(0, 7)
    g.add_edge(0, 8)
    g.add_edge(0, 9)

    g.add_edge(1, 2)
    g.add_edge(2, 3)
    g.add_edge(3, 4)
    g.add_edge(4, 5)
    g.add_edge(5, 6)
    g.add_edge(6, 7)
    g.add_edge(7, 8)
    g.add_edge(8, 9)
    g.add_edge(9, 1)

    def increase_vid(id):
        return id + 1

    tmpfile = tmpdir.join("dimacs.out")
    tmpfilename = str(tmpfile)
    write_dimacs(g,
                 tmpfilename,
                 format="shortestpath",
                 export_vertex_id_cb=increase_vid)

    with open(tmpfilename, "r") as f:
        contents = f.read()
        print(contents)

    assert contents == dimacs_sp_expected
def test_dimacs_with_custom_ids(tmpdir):
    g = build_graph()
    tmpfile = tmpdir.join("dimacs.out")
    tmpfilename = str(tmpfile)

    def custom_id(id):
        return id + 100

    write_dimacs(g,
                 tmpfilename,
                 format="shortestpath",
                 export_vertex_id_cb=custom_id)

    with open(tmpfilename, "r") as f:
        contents = f.read()
        print(contents)

    assert contents == dimacs_sp_expected100
def test_dimacs_with_custom_ids_bad_function(tmpdir):
    g = build_graph()
    tmpfile = tmpdir.join("dimacs.out")
    tmpfilename = str(tmpfile)

    def custom_id(id):
        return str(id + 100)

    with pytest.raises(TypeError):
        write_dimacs(g,
                     tmpfilename,
                     format="shortestpath",
                     export_vertex_id_cb=custom_id)

    def custom_id2(id):
        return -id

    with pytest.raises(ValueError):
        write_dimacs(g,
                     tmpfilename,
                     format="shortestpath",
                     export_vertex_id_cb=custom_id2)