1
1
using DrWatson, Test
2
+ using BSON, JLD2
2
3
cd (@__DIR__ )
3
4
T = 1000
4
5
N = 50 # spatial extent
@@ -14,60 +15,62 @@ function f(simulation)
14
15
return @strdict a b simulation
15
16
end
16
17
17
-
18
+ @testset " Tagsafe ( $ending ) " for ending ∈ [ " bson " , " jld2 " ]
18
19
# ###############################################################################
19
20
# tagsave #
20
21
# ###############################################################################
21
- t = f (simulation)
22
- tagsave (savename (simulation, " bson" ), t, gitpath= findproject ())
23
- file = load (savename (simulation, " bson" ))
24
- @test " gitcommit" ∈ keys (file)
25
- @test file[" gitcommit" ] |> typeof == String
26
- rm (savename (simulation, " bson" ))
27
-
28
- t = f (simulation)
29
- @tagsave (savename (simulation, " bson" ), t, safe= false , gitpath= findproject ())
30
- file = load (savename (simulation, " bson" ))
31
- @test " gitcommit" ∈ keys (file)
32
- @test file[" gitcommit" ] |> typeof == String
33
- @test " script" ∈ keys (file)
34
- @test file[" script" ] |> typeof == String
35
- @test file[" script" ] == joinpath (" test" , " savefiles_tests.jl#29" )
36
-
37
- t = f (simulation)
38
- @tagsave (savename (simulation, " bson" ), t, safe= true , gitpath= findproject ())
39
- sn = savename (simulation, " bson" )[1 : end - 5 ]* " _#1" * " .bson"
40
- @test isfile (sn)
41
- rm (sn)
42
-
43
- t = f (simulation)
44
- tagsave (savename (simulation, " bson" ), t, safe= true , gitpath= findproject ())
45
- sn = savename (simulation, " bson" )[1 : end - 5 ]* " _#1" * " .bson"
46
- @test isfile (sn)
47
- rm (sn)
48
-
49
- t = f (simulation)
50
- t[" gitcommit" ] = " "
51
- @test @tagsave (savename (simulation, " bson" ), t, safe= true , gitpath= findproject ())[" gitcommit" ] == " "
52
- @test isfile (sn)
53
- rm (sn)
54
- @test @tagsave (savename (simulation, " bson" ), t, safe= true , force= true , gitpath= findproject ())[" gitcommit" ] != " "
55
- @test isfile (sn)
56
- rm (sn)
57
-
58
- rm (savename (simulation, " bson" ))
59
- @test ! isfile (savename (simulation, " bson" ))
60
-
61
- ex = @macroexpand @tagsave (" testname.bson" , (@dict a b c ), storepatch= false ; safe= true )
62
- ex2 = @macroexpand @tagsave (" testname.bson" , @dict a b c; storepatch= false , safe= true )
63
- @test ex. args[1 : end - 1 ] == ex2. args[1 : end - 1 ]
64
-
65
- # Remove leftover
22
+ t = f (simulation)
23
+ tagsave (savename (simulation, ending), t, gitpath= findproject ())
24
+ file = load (savename (simulation, ending))
25
+ @test " gitcommit" ∈ keys (file)
26
+ @test file[" gitcommit" ] |> typeof == String
27
+ rm (savename (simulation, ending))
28
+
29
+ t = f (simulation)
30
+ @tagsave (savename (simulation, ending), t, safe= false , gitpath= findproject ())
31
+ file = load (savename (simulation, ending))
32
+ @test " gitcommit" ∈ keys (file)
33
+ @test file[" gitcommit" ] |> typeof == String
34
+ @test " script" ∈ keys (file)
35
+ @test file[" script" ] |> typeof == String
36
+ @test file[" script" ] == joinpath (" test" , " savefiles_tests.jl#30" )
37
+
38
+ t = f (simulation)
39
+ @tagsave (savename (simulation, ending), t, safe= true , gitpath= findproject ())
40
+ sn = savename (simulation, ending)[1 : end - 5 ]* " _#1" * " ." * ending
41
+ @test isfile (sn)
42
+ rm (sn)
43
+
44
+ t = f (simulation)
45
+ tagsave (savename (simulation, ending), t, safe= true , gitpath= findproject ())
46
+ sn = savename (simulation, ending)[1 : end - 5 ]* " _#1" * " ." * ending
47
+ @test isfile (sn)
48
+ rm (sn)
49
+
50
+ t = f (simulation)
51
+ t[" gitcommit" ] = " "
52
+ @test @tagsave (savename (simulation, ending), t, safe= true , gitpath= findproject ())[" gitcommit" ] == " "
53
+ @test isfile (sn)
54
+ rm (sn)
55
+ @test @tagsave (savename (simulation,ending), t, safe= true , force= true , gitpath= findproject ())[" gitcommit" ] != " "
56
+ @test isfile (sn)
57
+ rm (sn)
58
+
59
+ rm (savename (simulation, ending))
60
+ @test ! isfile (savename (simulation, ending))
61
+
62
+ ex = @macroexpand @tagsave (" testname." * ending, (@dict a b c ), storepatch= false ; safe= true )
63
+ ex2 = @macroexpand @tagsave (" testname." * ending, @dict a b c; storepatch= false , safe= true )
64
+ @test ex. args[1 : end - 1 ] == ex2. args[1 : end - 1 ]
65
+
66
+ # Remove leftover
67
+ end
66
68
67
69
# ###############################################################################
68
70
# produce or load #
69
71
# ###############################################################################
70
- for ending ∈ (" bson" , " jld2" )
72
+
73
+ @testset " Produce or Load ($ending )" for ending ∈ [" bson" , " jld2" ]
71
74
@test ! isfile (savename (simulation, ending))
72
75
sim, path = produce_or_load (simulation, f; suffix = ending)
73
76
@test isfile (savename (simulation, ending))
@@ -113,15 +116,18 @@ rm(savename(simulation, "jld2"))
113
116
# ###############################################################################
114
117
# Backup files before saving #
115
118
# ###############################################################################
116
- filepath = " test.#backup.jld2"
117
- data = [Dict ( " a" => i, " b" => rand (rand (1 : 10 ))) for i = 1 : 3 ]
118
- for i = 1 : 3
119
- safesave (filepath, data[i])
120
- @test data[i] == load (filepath)
119
+
120
+ @testset " Backup ($ending )" for ending ∈ [" bson" , " jld2" ]
121
+ filepath = " test.#backup." * ending
122
+ data = [Dict ( " a" => i, " b" => rand (rand (1 : 10 ))) for i = 1 : 3 ]
123
+ for i = 1 : 3
124
+ safesave (filepath, data[i])
125
+ @test data[i] == load (filepath)
126
+ end
127
+ @test data[2 ] == load (" test.#backup_#1." * ending)
128
+ @test data[1 ] == load (" test.#backup_#2." * ending)
129
+ @test data[3 ] == load (" test.#backup." * ending)
130
+ rm (" test.#backup." * ending)
131
+ rm (" test.#backup_#1." * ending)
132
+ rm (" test.#backup_#2." * ending)
121
133
end
122
- @test data[2 ] == load (" test.#backup_#1.jld2" )
123
- @test data[1 ] == load (" test.#backup_#2.jld2" )
124
- @test data[3 ] == load (" test.#backup.jld2" )
125
- rm (" test.#backup.jld2" )
126
- rm (" test.#backup_#1.jld2" )
127
- rm (" test.#backup_#2.jld2" )
0 commit comments