-
-
Notifications
You must be signed in to change notification settings - Fork 359
/
test_animations.jl
127 lines (109 loc) · 3.57 KB
/
test_animations.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
@testset "Animation constructors" begin
@test Animation() isa Animation
@test Animation("dir") isa Animation
@test Animation("dir", String[]) isa Animation
end
@testset "Missing animation directory" begin
anim = Animation("nonexisting_dir")
@test_throws SystemError frame(anim, plot([1, 2, 3]))
end
@testset "Empty anim" begin
anim = @animate for i in []
end
@test_throws ArgumentError gif(anim, show_msg = false)
end
@userplot CirclePlot
@recipe function f(cp::CirclePlot)
x, y, i = cp.args
n = length(x)
inds = circshift(1:n, 1 - i)
linewidth --> range(0, 10, length = n)
seriesalpha --> range(0, 1, length = n)
aspect_ratio --> 1
label --> false
x[inds], y[inds]
end
@testset "Circle plot" begin
n = 10
t = range(0, 2π, length = n)
x = sin.(t)
y = cos.(t)
anim = @animate for i in 1:n
circleplot(x, y, i)
end
@test filesize(gif(anim, show_msg = false).filename) > 10_000
@test filesize(mov(anim, show_msg = false).filename) > 10_000
@test filesize(mp4(anim, show_msg = false).filename) > 10_000
@test filesize(webm(anim, show_msg = false).filename) > 10_000
@test filesize(Plots.apng(anim, show_msg = false).filename) > 10_000
@gif for i in 1:n
circleplot(x, y, i, line_z = 1:n, cbar = false, framestyle = :zerolines)
end every 5
@gif for i in 1:n
circleplot(x, y, i, line_z = 1:n, cbar = false, framestyle = :zerolines)
end when i % 5 == 0
@gif for i in 1:n
circleplot(x, y, i, line_z = 1:n, cbar = false, framestyle = :zerolines)
end when i % 5 == 0 fps = 10
@test_throws LoadError macroexpand(
@__MODULE__,
quote
@gif for i in 1:n
circleplot(x, y, i, line_z = 1:n, cbar = false, framestyle = :zerolines)
end when i % 5 == 0 every 10 # cannot use every and when together
end,
)
@test_nowarn macroexpand(
@__MODULE__,
quote
@gif for i in 1:n
circleplot(x, y, i, line_z = 1:n, cbar = false, framestyle = :zerolines)
end asdf = bla #asdf is allowed
end,
)
anim = Plots.@apng for i in 1:n
circleplot(x, y, i, line_z = 1:n, cbar = false, framestyle = :zerolines)
end every 5
@test showable(MIME("image/png"), anim)
end
@testset "html" begin
pl = plot([sin, cos], zeros(0), leg = false, xlims = (0, 2π), ylims = (-1, 1))
anim = Animation()
for x in range(0, stop = 2π, length = 10)
push!(pl, x, Float64[sin(x), cos(x)])
frame(anim)
end
agif = gif(anim, show_msg = false)
html = tempname() * ".html"
open(html, "w") do io
show(io, MIME("text/html"), agif)
end
@test filesize(html) > 10_000
@test showable(MIME("image/gif"), agif)
agif = mp4(anim, show_msg = false)
html = tempname() * ".html"
open(html, "w") do io
show(io, MIME("text/html"), agif)
end
@test filesize(html) > 10_000
end
@testset "animate" begin
anim = animate([1:2, 2:3]; show_msg = false, fps = 1 // 10)
@test anim isa Plots.AnimatedGif
@test showable(MIME("image/gif"), anim)
fn = tempname() * ".apng"
open(fn, "w") do io
show(io, MIME("image/png"), anim)
end
@test filesize(fn) > 1_000
fn = tempname() * ".gif"
open(fn, "w") do io
show(io, MIME("image/gif"), anim)
end
@test filesize(fn) > 1_000
end
@testset "coverage" begin
@test animate([1:2, 2:3]; variable_palette = true, show_msg = false) isa
Plots.AnimatedGif
@test Plots.FrameIterator([1:2, 2:3]).every == 1
end