-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathgraphio.jl
97 lines (89 loc) · 2.35 KB
/
graphio.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# This file contains helper functions for testing the various
# GraphIO formats
using Graphs
graphs = Dict{String,Graph}(
"graph1" => complete_graph(5), "graph2" => path_graph(6), "graph3" => wheel_graph(4)
)
digraphs = Dict{String,DiGraph}(
"digraph1" => complete_digraph(5),
"digraph2" => path_digraph(6),
"digraph3" => wheel_digraph(4),
)
allgraphs = merge(graphs, digraphs)
function gettempname()
(f, fio) = mktemp()
close(fio)
return f
end
function read_test(
format::Graphs.AbstractGraphFormat,
g::Graphs.AbstractGraph,
gname::String="g",
fname::AbstractString="";
testfail=false,
)
@test loadgraph(fname, gname, format) == g
if testfail
@test_throws Union{ArgumentError,ErrorException} loadgraph(
fname, "badgraphXXX", format
)
end
@test loadgraphs(fname, format)[gname] == g
end
function read_test_mult(
format::Graphs.AbstractGraphFormat, d::Dict{String,G}, fname::AbstractString=""
) where {G<:AbstractGraph}
rd = loadgraphs(fname, format)
@test rd == d
end
function write_test(
format::Graphs.AbstractGraphFormat,
g::Graphs.AbstractGraph,
gname::String="g",
fname::AbstractString=gettempname();
remove=true,
silent=false,
)
@test savegraph(fname, g, gname, format) == 1
if remove
rm(fname)
elseif !silent
info("graphio/write_test: Left temporary file at: $fname")
end
end
function write_test(
format::Graphs.AbstractGraphFormat,
d::Dict{String,G},
fname::AbstractString=gettempname();
remove=true,
silent=false,
) where {G<:Graphs.AbstractGraph}
@test savegraph(fname, d, format) == length(d)
if remove
rm(fname)
elseif !silent
info("graphio/write_test: Left temporary file at: $fname")
end
end
function readback_test(
format::Graphs.AbstractGraphFormat,
g::Graphs.AbstractGraph,
gname="graph",
fname=gettempname();
remove=true,
testfail=false,
)
@test savegraph(fname, g, format) == 1
@test loadgraphs(fname, format)[gname] == g
@test loadgraph(fname, gname, format) == g
if testfail
@test_throws Union{ArgumentError,ErrorException} loadgraph(
fname, "badgraphXXX", format
)
end
if remove
rm(fname)
else
info("graphio/readback_test: Left temporary file at: $fname")
end
end