Skip to content

Commit

Permalink
refactoring tests, more tests on parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
hhaensel committed May 28, 2024
1 parent fa19ba6 commit 7a7e4f7
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 21 deletions.
19 changes: 0 additions & 19 deletions test/Charts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,4 @@ end
@test pd[2].text[2] == "D"
end
end
end

@testset "JSONText from PlotlyBase extension" begin

using Stipple
@testset "Stipple.JSONText" begin
@test ! @isdefined PBPlotWithEvents
using PlotlyBase, PlotlyBase.JSON
@test @isdefined PBPlotWithEvents

sc = scatter(x = StipplePlotly.JSONText("jsontext"), more_of_this = "a")
pl = Plot(sc)
@test JSON.json(sc) == "{\"type\":\"scatter\",\"more\":{\"of\":{\"this\":\"a\"}},\"x\":jsontext}"
@test contains(JSON.json(pl), "{\"type\":\"scatter\",\"more\":{\"of\":{\"this\":\"a\"}},\"x\":jsontext}")

@test Stipple.json(sc) == "{\"type\":\"scatter\",\"more\":{\"of\":{\"this\":\"a\"}},\"x\":jsontext}"
@test contains(Stipple.json(pl), "{\"type\":\"scatter\",\"more\":{\"of\":{\"this\":\"a\"}},\"x\":jsontext}")
end

end
66 changes: 66 additions & 0 deletions test/PlotlyBaseExtension.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
@testset "PlotlyBase extension" begin

using Stipple
@testset "Stipple.JSONText" begin
@test ! @isdefined(PBPlotWithEvents) || @isdefined(PlotlyBase)
using PlotlyBase, PlotlyBase.JSON
@test @isdefined PBPlotWithEvents

sc = scatter(x = StipplePlotly.JSONText("jsontext"), more_of_this = "a")
pl = Plot(sc)
@test JSON.json(sc) == "{\"type\":\"scatter\",\"more\":{\"of\":{\"this\":\"a\"}},\"x\":jsontext}"
@test contains(JSON.json(pl), "{\"type\":\"scatter\",\"more\":{\"of\":{\"this\":\"a\"}},\"x\":jsontext}")

@test Stipple.json(sc) == "{\"type\":\"scatter\",\"more\":{\"of\":{\"this\":\"a\"}},\"x\":jsontext}"
@test contains(Stipple.json(pl), "{\"type\":\"scatter\",\"more\":{\"of\":{\"this\":\"a\"}},\"x\":jsontext}")
end

@testset "Parsing" begin
using Stipple
import Stipple.stipple_parse

@testset "Layout" begin
pl = PlotlyBase.Layout(xaxis_range = [1, 2])
pl_d = JSON3.read(Stipple.json(render(pl)), Dict)

pl_in = stipple_parse(PlotlyBase.Layout, pl_d)
@test pl_in[:xaxis_range] == [1, 2]

pl_in = stipple_parse(PlotlyBase.Layout{Dict{Symbol, Any}}, pl_d)
pl_in[:xaxis_range] == [1, 2]

if VersionNumber(Genie.Assets.package_version(Stipple)) >= v"0.30.5"
pl_in = stipple_parse(PlotlyBase.Layout{OrderedDict{Symbol, Any}}, pl_d)
@test pl_in[:xaxis_range] == [1, 2]
end
end

@testset "GenericTrace" begin
tr = scatter(x = [1, 2, 3], y = [3, 4, 5])
tr_d = JSON3.read(Stipple.json(render(tr)), Dict)

tr_in = stipple_parse(GenericTrace, tr_d)
@test tr_in.x == [1, 2, 3]
@test tr_in.y == [3, 4, 5]
end

@testset "Plot" begin
pl = PlotlyBase.Plot([scatter(x = [1, 2, 3], y = [3, 4, 5])], PlotlyBase.Layout(xaxis_range = [1, 2]))
pl_d = JSON3.read(Stipple.json(render(pl)), Dict)

pl_in = stipple_parse(PlotlyBase.Plot, pl_d)
@test length(pl_in.data) == 1
@test pl_in.layout[:xaxis_range] == [1, 2]

T = Plot() |> typeof
T = Plot
pl_in = stipple_parse(T, pl_d)
@test length(pl_in.data) == 1
@test pl_in.data[1][:x] == [1, 2, 3]
@test pl_in.layout[:xaxis_range] == [1, 2]
end
end

end

pl = PlotlyBase.Layout(xaxis_range = [1, 2])
9 changes: 7 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ using StipplePlotly
using Test
using DataFrames

@testset verbose = true "Charts" begin
files = filter(endswith(".jl"), readdir(@__DIR__))

include("Charts.jl")
for file in files
file == "runtests.jl" && continue

title = file[1:end-3]
@testset verbose = true "$title" begin
include(file)
end
end

0 comments on commit 7a7e4f7

Please sign in to comment.